Socket
Socket
Sign inDemoInstall

jest-playback

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-playback - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

lib/manager.d.ts

55

CHANGELOG.md

@@ -1,49 +0,58 @@

# Change Log
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
# [4.0.0](https://github.com/ikatyang/jest-playback/compare/v3.0.0...v4.0.0) (2023-07-22)
### Features
- rewrite with `@mswjs/interceptors` ([#432](https://github.com/ikatyang/jest-playback/issues/432)) ([cb66cf5](https://github.com/ikatyang/jest-playback/commit/cb66cf543d276196d5fd3394ec4bd92fe4e67247))
- 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>
# [3.0.0](https://github.com/ikatyang/jest-playback/compare/v2.0.2...v3.0.0) (2020-07-29)
### Features
* upgrade Nock to v13 ([#411](https://github.com/ikatyang/jest-playback/issues/411)) ([9ec364e](https://github.com/ikatyang/jest-playback/commit/9ec364e))
- upgrade Nock to v13 ([#411](https://github.com/ikatyang/jest-playback/issues/411)) ([9ec364e](https://github.com/ikatyang/jest-playback/commit/9ec364e))
### BREAKING CHANGES
* require Node 10+
- require Node 10+
<a name="2.0.2"></a>
<a name="2.0.2"></a>
## [2.0.2](https://github.com/ikatyang/jest-playback/compare/v2.0.1...v2.0.2) (2018-11-30)
### Bug Fixes
* compute hash correctly for records with JSON body ([#351](https://github.com/ikatyang/jest-playback/issues/351)) ([e9c156a](https://github.com/ikatyang/jest-playback/commit/e9c156a))
- compute hash correctly for records with JSON body ([#351](https://github.com/ikatyang/jest-playback/issues/351)) ([e9c156a](https://github.com/ikatyang/jest-playback/commit/e9c156a))
<a name="2.0.1"></a>
<a name="2.0.1"></a>
## [2.0.1](https://github.com/ikatyang/jest-playback/compare/v2.0.0...v2.0.1) (2018-09-21)
### Bug Fixes
* **play:** disable allowUnmocked ([#328](https://github.com/ikatyang/jest-playback/issues/328)) ([4ebeb6d](https://github.com/ikatyang/jest-playback/commit/4ebeb6d))
- **play:** disable allowUnmocked ([#328](https://github.com/ikatyang/jest-playback/issues/328)) ([4ebeb6d](https://github.com/ikatyang/jest-playback/commit/4ebeb6d))
<a name="2.0.0"></a>
<a name="2.0.0"></a>
# [2.0.0](https://github.com/ikatyang/jest-playback/compare/v1.0.1...v2.0.0) (2018-07-28)
### Features
* parallel testing ([#313](https://github.com/ikatyang/jest-playback/issues/313)) ([94c1de1](https://github.com/ikatyang/jest-playback/commit/94c1de1))
- parallel testing ([#313](https://github.com/ikatyang/jest-playback/issues/313)) ([94c1de1](https://github.com/ikatyang/jest-playback/commit/94c1de1))
### BREAKING CHANGES

@@ -57,18 +66,16 @@

<a name="1.0.1"></a>
<a name="1.0.1"></a>
## [1.0.1](https://github.com/ikatyang/jest-playback/compare/v1.0.0...v1.0.1) (2017-09-05)
### Bug Fixes
* **peerDeps:** accept jest ^21.0.0 ([#70](https://github.com/ikatyang/jest-playback/issues/70)) ([8b85f7b](https://github.com/ikatyang/jest-playback/commit/8b85f7b))
- **peerDeps:** accept jest ^21.0.0 ([#70](https://github.com/ikatyang/jest-playback/issues/70)) ([8b85f7b](https://github.com/ikatyang/jest-playback/commit/8b85f7b))
<a name="v1.0.0"></a>
<a name="v1.0.0"></a>
## v1.0.0 (2017-07-13)
#### 🚀 New Feature
- Release first version

@@ -1,1 +0,2 @@

export * from './setup';
import { Options } from './options.js';
export default function setup(options?: Options): Promise<void>;

@@ -1,6 +0,35 @@

"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
import { BatchInterceptor } from '@mswjs/interceptors';
import { ClientRequestInterceptor } from '@mswjs/interceptors/ClientRequest';
import { FetchInterceptor } from '@mswjs/interceptors/fetch';
import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest';
import { PlaybackManager } from './manager.js';
import { JestRunner, VitestRunner } from './runners/index.js';
export default async function setup(options) {
const runner = getRunner();
await runner.init();
const manager = new PlaybackManager(runner, options);
const interceptor = new BatchInterceptor({
name: 'interceptor',
interceptors: [
new ClientRequestInterceptor(),
new FetchInterceptor(),
new XMLHttpRequestInterceptor(),
],
});
interceptor.apply();
interceptor.on('request', async ({ request }) => {
const response = await manager.onRequest(request);
if (response) {
request.respondWith(response);
}
});
}
exports.__esModule = true;
__export(require("./setup"));
function getRunner() {
if ('JEST_WORKER_ID' in process.env) {
return new JestRunner();
}
if ('VITEST_POOL_ID' in process.env) {
return new VitestRunner();
}
throw new Error('unexpected environment');
}
{
"name": "jest-playback",
"version": "3.0.0",
"description": "Record and playback http requests from your Jest tests",
"type": "module",
"version": "4.0.0",
"description": "Record and playback HTTP requests from your Jest tests",
"keywords": [
"jest",
"nock",
"playback",

@@ -12,4 +12,3 @@ "record",

],
"main": "lib/index.js",
"types": "lib/index.d.ts",
"exports": "./lib/index.js",
"repository": "https://github.com/ikatyang/jest-playback",

@@ -23,47 +22,33 @@ "homepage": "https://github.com/ikatyang/jest-playback#readme",

"license": "MIT",
"scripts": {
"prepublish": "npm run build",
"lint": "tslint -p .",
"test": "jest",
"prebuild": "rm -rf ./lib",
"build": "tsc -p tsconfig.build.json",
"release": "standard-version"
},
"dependencies": {
"json-stable-stringify": "^1.0.1",
"lodash.kebabcase": "^4.1.1",
"nock": "^13.0.3",
"rev-hash": "^2.0.0"
"@mswjs/interceptors": "^0.23.0",
"jest-snapshot-serializer-raw": "^2.0.0",
"mime-types": "^2.1.35"
},
"devDependencies": {
"@types/del": "3.0.1",
"@types/glob": "7.1.1",
"@types/jest": "21.1.10",
"@types/json-stable-stringify": "1.0.32",
"@types/lodash.kebabcase": "4.1.6",
"@types/node": "^10.17.28",
"@types/request": "2.48.1",
"@types/rev-hash": "2.0.0",
"del": "3.0.0",
"glob": "7.1.4",
"jest": "21.2.1",
"prettier": "1.18.2",
"prettier-config-ikatyang": "1.1.1",
"request": "2.88.0",
"standard-version": "4.4.0",
"ts-jest": "21.2.4",
"tslint": "5.15.0",
"tslint-config-prettier": "1.18.0",
"tslint-plugin-prettier": "2.0.1",
"typescript": "3.5.2"
"@types/jest": "29.5.3",
"@types/mime-types": "2.1.1",
"jest": "29.6.1",
"prettier": "3.0.0",
"standard-version": "9.5.0",
"ts-jest": "29.1.1",
"typescript": "5.1.6",
"vite": "4.4.4",
"vitest": "0.33.0"
},
"peerDependencies": {
"jest": ">= 20"
},
"engines": {
"node": ">= 10"
"node": ">=18"
},
"files": [
"/lib/**/*"
]
}
"/lib/**/*",
"/CHANGELOG.md"
],
"packageManager": "pnpm@8.6.6",
"scripts": {
"lint": "prettier --check .",
"test:vitest": "vitest",
"test:jest": "NODE_OPTIONS=--experimental-vm-modules jest",
"build": "tsc -p tsconfig.build.json",
"release": "standard-version"
}
}
# jest-playback
[![npm](https://img.shields.io/npm/v/jest-playback.svg)](https://www.npmjs.com/package/jest-playback)
[![build](https://img.shields.io/travis/ikatyang/jest-playback/master.svg)](https://travis-ci.org/ikatyang/jest-playback/builds)
[![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](https://facebook.github.io/jest/) tests
Record and playback HTTP requests from your Jest tests

@@ -13,7 +13,3 @@ [Changelog](https://github.com/ikatyang/jest-playback/blob/master/CHANGELOG.md)

```sh
# using npm
npm install --save-dev jest-playback jest
# using yarn
yarn add --dev jest-playback jest
npm install jest-playback
```

@@ -23,46 +19,32 @@

In setup file or test file:
```js
// records are stored in `${__dirname}/__playbacks__`.
require("jest-playback").setup(__dirname);
import setupPlayback from 'jest-playback'
await setupPlayback()
```
const request = require("request");
The HTTP responses are stored as snapshots:
test("example", done => {
request('http://www.example.com/', (_err, _res, body) => {
expect(body).toMatchSnapshot();
done();
});
});
```
- 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
You can control which [mode](#modes) to use by specifying the second argument of `setup`:
## API
```js
require("jest-playback").setup(__dirname, "record");
```
```ts
declare function setupPlayback(options?: Options): Promise<void>
or via the `JEST_PLAYBACK_MODE` environment variable:
```sh
JEST_PLAYBACK_MODE=record npx jest
interface Options {
getRequestCacheKey?: (request: Request) => string | Promise<string>
}
```
## Modes
- `run` (default)
- play records
- enable net connet
- `play`
- play records
- disable net connet
- `record`
- enable net connect
- record all requests
- `real`
- enable net connect
## Development

@@ -72,17 +54,16 @@

# lint
yarn run lint
pnpm run lint
# build
yarn run build
pnpm run build
# test
yarn run test
# test with jest
pnpm run test:jest
# test with vitest
pnpm run test:vitest
```
## Related
- [nock](https://github.com/node-nock/nock): HTTP mocking and expectations library
- [ava-playback](https://github.com/dempfi/ava-playback): Record and playback http requests from your ava tests
## License
MIT © [Ika](https://github.com/ikatyang)
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc