4.1.0 • Published 9 months ago

jest-playback v4.1.0

Weekly downloads
307
License
MIT
Repository
github
Last release
9 months ago

jest-playback

npm build

Record and playback HTTP requests from your Jest tests

Changelog

Install

npm install jest-playback

Usage

import * as jestPlayback from 'jest-playback'

await jestPlayback.setup()

test('example', async () => {
  const response = await fetch('http://www.example.com/')
  expect(response.status).toBe(200)
})

The records are stored as snapshots.

API

export default setup
export declare function setup(options?: Options): Promise<void>

export interface Options {
  /** @default Mode.Auto */
  mode?: Mode
  getRequestCacheKey?: (request: Request) => string | Promise<string>
}

export enum Mode {
  /**
   * - `Mode.Update` if Jest `--update-snapshot` flag specified
   * - `Mode.Play` if Jest `--ci` flag specified
   * - `Mode.Record` otherwise
   */
  Auto = 'auto',
  /**
   * - all requests are recorded
   */
  Update = 'update',
  /**
   * - play records
   * - new requests are blocked
   */
  Play = 'play',
  /**
   * - play records
   * - new requests are recorded
   */
  Record = 'record',
}

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

4.1.0

9 months ago

4.0.0

9 months ago

3.0.0

4 years ago

2.0.2

5 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago