Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ikatyang/jest-playback
Record and playback HTTP requests from your Jest tests
https://github.com/ikatyang/jest-playback
jest playback record request
Last synced: about 2 months ago
JSON representation
Record and playback HTTP requests from your Jest tests
- Host: GitHub
- URL: https://github.com/ikatyang/jest-playback
- Owner: ikatyang
- License: mit
- Created: 2017-07-13T11:55:24.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-01-20T02:39:43.000Z (about 1 year ago)
- Last Synced: 2024-04-14T11:56:47.365Z (10 months ago)
- Topics: jest, playback, record, request
- Language: TypeScript
- Homepage:
- Size: 731 KB
- Stars: 52
- Watchers: 3
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# jest-playback
[![npm](https://img.shields.io/npm/v/jest-playback.svg)](https://www.npmjs.com/package/jest-playback)
[![build](https://img.shields.io/github/actions/workflow/status/ikatyang/jest-playback/test.yml)](https://github.com/ikatyang/jest-playback/actions?query=branch%3Amaster)Record and playback HTTP requests from your Jest tests
[Changelog](https://github.com/ikatyang/jest-playback/blob/master/CHANGELOG.md)
## Install
```sh
npm install jest-playback
```## Usage
```js
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
```ts
export default setup
export declare function setup(options?: Options): Promiseexport interface Options {
/** @default Mode.Auto */
mode?: Mode
getRequestCacheKey?: (request: Request) => string | Promise
}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
```sh
# 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](https://github.com/ikatyang)