Socket
Socket
Sign inDemoInstall

jest-playback

Package Overview
Dependencies
11
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jest-playback

Record and playback HTTP requests from your Jest tests


Version published
Weekly downloads
3.2K
decreased by-9.84%
Maintainers
1
Install size
1.04 MB
Created
Weekly downloads
 

Changelog

Source

4.0.0 (2023-07-22)

Features

  • rewrite with @mswjs/interceptors (#432) (cb66cf5)
    • use snapshot to store records
    • store records by test by request
    • support custom request cache key
    • compatible with Vitest

BREAKING CHANGES

  • this package is now pure ESM
  • this package now requires Node 18+
  • the record format has been changed
  • Mode has been replaced by the Jest --ci/--update-snapshot flag

<a name="3.0.0"></a>

Readme

Source

jest-playback

npm build

Record and playback HTTP requests from your Jest tests

Changelog

Install

npm install jest-playback

Usage

In setup file or test file:

import setupPlayback from 'jest-playback'
await setupPlayback()

The HTTP responses are stored as snapshots:

  • default
    • new requests will be stored
    • stored records will be played
  • with Jest --ci flag specified
    • new requests will be blocked
    • stored records will be played
  • with Jest --update-snapshot flag specified
    • new requests will be stored
    • stored records will be updated
    • obsolete records will be removed

API

declare function setupPlayback(options?: Options): Promise<void>

interface Options {
  getRequestCacheKey?: (request: Request) => string | Promise<string>
}

Development

# lint
pnpm run lint

# build
pnpm run build

# test with jest
pnpm run test:jest

# test with vitest
pnpm run test:vitest

License

MIT © Ika

Keywords

FAQs

Last updated on 22 Jul 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc