Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@pollyjs/utils

netflix176.8kApache-2.06.0.6TypeScript support: included

Shared utilities and constants between @pollyjs packages

polly, pollyjs, utils

readme

Polly.JS

Record, Replay, and Stub HTTP Interactions

Build Status npm version license

The @pollyjs/utils package provides utilities and constants for other @pollyjs packages.

Installation

Note that you must have node (and npm) installed.

npm install @pollyjs/utils -D

If you want to install it with yarn:

yarn add @pollyjs/utils -D

License

Copyright (c) 2018 Netflix, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

6.0.6 (2023-07-20)

Note: Version bump only for package pollyjs

6.0.5 (2022-04-04)

Bug Fixes

  • persister: requests -> request in HarEntry declaration (#441) (6466810)

6.0.4 (2021-12-10)

Bug Fixes

6.0.3 (2021-12-08)

Bug Fixes

6.0.2 (2021-12-07)

Bug Fixes

  • core: Fix types for registering adapters and persisters (#435) (cc2fa19)

6.0.1 (2021-12-06)

Bug Fixes

  • ember: Bump peer dependencies to 6.x (#432) (1529226)
  • types: add types.d.ts to package.files (#431) (113ee89)

6.0.0 (2021-11-30)

Bug Fixes

  • persister: Only treat status codes >= 400 as failed (#430) (7658952)
  • fix!: Upgrade url-parse (#426) (c21ed04), closes #426
  • feat!: Cleanup adapter and persister APIs (#429) (06499fc), closes #429
  • feat!: Improve logging and add logLevel (#427) (bef3ee3), closes #427
  • chore!: Upgrade package dependencies (#421) (dd23334), closes #421
  • feat!: Use base64 instead of hex encoding for binary data (#420) (6bb9b36), closes #420
  • feat(ember)!: Upgrade to ember octane (#415) (8559ef8), closes #415

Features

BREAKING CHANGES

  • Upgrade url-parse to 1.5.0+ to fix CVE-2021-27515. This change could alter the final url generated for a request.
  • Adapter
    • passthroughRequest renamed to onFetchResponse
    • respondToRequest renamed to onRespond
  • Persister
    • findRecording renamed to onFindRecording
    • saveRecording renamed to onSaveRecording
    • deleteRecording renamed to onDeleteRecording
  • The logging configuration option has now been replaced with logLevel. This allows for more fine-grain control over what should be logged as well as silencing logs altogether.
  • Recording file name will no longer have trailing dashes
  • Use the standard encoding field on the generated har file instead of _isBinary and use base64 encoding instead of hex to reduce the payload size.
    • Although backwards compatibility is not guaranteed, you can replace all occurrences of "_isBinary": true with "encoding": "hex" in the recorded HAR files.
  • @pollyjs dependencies for @pollyjs/ember have been moved to peer dependencies

5.2.0 (2021-11-24)

Features

  • ember: Upgrade ember-cli-babel to ^7.26.6 (#411) (4352881)

5.1.1 (2021-06-02)

Bug Fixes

  • Handle failed arraybuffer instanceof checks (#393) (247be0a)

5.1.0 (2020-12-12)

Bug Fixes

Features

  • core: Add overrideRecordingName and configure to public API (#372) (cdbf513)

5.0.2 (2020-12-06)

Bug Fixes

  • adapter-node-http: Remove module monkey patching on disconnect (#369) (0cec43a)

5.0.1 (2020-09-25)

Bug Fixes

  • adapter-xhr: Only modify the responseType if it was changed (#363) (cff4e2d)

5.0.0 (2020-06-23)

Bug Fixes

  • adapter-fetch: Add statusText to the response (#341) (0d45953)
  • core: Compute order based on id and recording name (#342) (42004d2)

Features

  • Remove deprecated Persister.name and Adapter.name (#343) (1223ba0)

BREAKING CHANGES

  • Persister.name and Adapter.name have been replaced with Persister.id and Adapter.id
  • core: A request's order is will now be computed based on its id and the recording name it will be persisted to.

4.3.0 (2020-05-18)

Features

  • adapter-fetch: Add support for handling binary data (#332) (111bebf)
  • adapter-xhr: Add support for handling binary data (#333) (48ea1d7)
  • core: Add flushRequestsOnStop configuration option (#335) (ab4a2e1)

4.2.1 (2020-04-30)

Bug Fixes

  • adapter-node-http: Improve binary response body handling (#329) (9466989)

4.2.0 (2020-04-29)

Features

  • node-server: Pass options to the CORS middleware via corsOptions (3d991f5)

4.1.0 (2020-04-23)

Bug Fixes

Features

  • persister: Add disableSortingHarEntries option (#321) (0003c0e)

4.0.4 (2020-03-21)

Bug Fixes

  • Deprecates adapter & persister name in favor of id (#310) (41dd093)
  • adapter-node-http: Bump nock version (#319) (7d361a6)

4.0.3 (2020-01-30)

Bug Fixes

  • adapter-node-http: Use requestBodyBuffers to parse body (#304) (113fec5)

4.0.2 (2020-01-29)

Bug Fixes

  • core: Strict null query param handling (#302) (5cf70aa)

4.0.1 (2020-01-25)

Bug Fixes

  • ember: Config read from project root (7d6da38)

4.0.0 (2020-01-13)

Bug Fixes

  • adapter: Clone the recording entry before mutating it (#294) (d7e1303)
  • core: Disconnect from all adapters when pause is called (#291) (5c655bf)

chore

Features

  • core: Provide the request as an argument to matchRequestsBy methods (#293) (4e3163f)
  • core: Remove deprecated recordIfExpired option (#295) (5fe991d)

BREAKING CHANGES

  • core: recordIfExpired is no longer supported, please use expiryStrategy instead.
  • Drop support for Node 8 as it is now EOL
  • core: Calling polly.pause() will now disconnect from all connected adapters instead of setting the mode to passthrough. Calling polly.play() will reconnect to the disconnected adapters before pause was called.

3.0.2 (2020-01-08)

Bug Fixes

  • adapter-node-http: Bump nock version to correctly handle re… (#289) (8d0ae97), closes #278

3.0.1 (2019-12-25)

Bug Fixes

  • adapter-fetch: Fix "failed to construct Request" issue (#287) (d17ab9b), closes #286

3.0.0 (2019-12-18)

Bug Fixes

  • ember: loads polly config for ember by its own module (#277) (0569040)

BREAKING CHANGES

  • ember: moves location of polly configuration

2.7.0 (2019-11-21)

Bug Fixes

  • adapter-node-http: Correctly handle uploading binary data (#257) (31f0e0a)

Features

  • adapter-node-http: Upgrade nock to v11.x (#273) (5d42cbd)

2.6.3 (2019-09-30)

Bug Fixes

  • use watch strategy (#236) (5b4edf3)
  • adapter-fetch: Correctly handle Request instance passed into fetch (#259) (593ecb9)

2.6.2 (2019-08-05)

Bug Fixes

  • Bowser.getParser empty string UserAgent error (#246) (2c9c4b9)

Features

  • Adds an in-memory persister to test polly internals (#237) (5a6fda6)

2.6.1 (2019-08-01)

Bug Fixes

  • persister: Default to empty string if userAgent is empty (#242) (c46d65c)

2.6.0 (2019-07-17)

Bug Fixes

  • adapter-fetch: Handle Request objects as URLs (#220) (bb28d54)

Features

2.5.0 (2019-06-06)

Features

  • adapter-xhr: Support context option (65b3c38)

2.4.0 (2019-04-27)

Features

  • core: Improved control flow with times and stopPropagation (#202) (2c8231e)

2.3.2 (2019-04-09)

Bug Fixes

  • adapter-puppeteer: Remove other resource type matching (#197) (ea6bfcc)

2.3.1 (2019-03-06)

Bug Fixes

  • adapter-fetch: Correctly handle key/value pairs headers (dc0323d)

2.3.0 (2019-02-27)

Features

  • core: Filter requests matched by a route handler (#189) (5d57c32)

2.2.0 (2019-02-20)

Features

  • Add error event and improve error handling (#185) (3694ebc)

2.1.0 (2019-02-04)

Bug Fixes

  • adapter: Log information if request couldn't be found in recording (#172) (8dcdf7b)
  • adapter-xhr: Xhr.send should not be an async method (#173) (eb3a6eb)
  • Correctly handle array header values (#179) (fb7dbb4)

Features

  • core: Add removeHeader, removeHeaders, and allow empty headers (#176) (1dfae5a)

2.0.0 (2019-01-29)

  • feat(adapter-node-http): Use nock under the hood instead of custom implementation (#166) (62374f4), closes #166

Bug Fixes

  • adapter: Test for navigator before accessing (#165) (7200255)
  • ember: Remove Node 6 from supported versions (#169) (07b2b4e)
  • persister: Only persist post data if a request has a body (#171) (f62d318)

chore

Features

  • Make PollyRequest.respond accept a response object (#168) (5b07b26)
  • Simplify adapter implementation (#154) (12c8601)

BREAKING CHANGES

  • The node-http adapter no longer accepts the transports option
  • Any adapters calling pollyRequest.respond should pass it a response object instead of the previous 3 arguments (statusCode, headers, body).
  • Polly will no longer actively support Node 6
  • Changes to the base adapter implementation and external facing API

1.4.2 (2019-01-16)

Bug Fixes

  • adapter-node-http: Fix unhandled rejection if connection fails (#160) (12fcfa7)
  • adapter-node-http: Pause socket on original request (#162) (8f0c56c)

Features

1.4.1 (2018-12-13)

Bug Fixes

  • utils: Support arrays & nested objects in query params (#148) (7e846b0)

1.4.0 (2018-12-07)

Bug Fixes

  • adapter-fetch: Deprecate usage in Node in favor of node-http (#146) (001ccdd)

Features

1.3.2 (2018-11-29)

Note: Version bump only for package pollyjs

1.3.1 (2018-11-28)

Bug Fixes

  • Support URL objects (#139) (cf0d755)
  • core: Handle trailing slashes when generating route names (#142) (19147f7)
  • core: Ignore context options from being deep merged (#144) (2123d83)
  • core: Support multiple handlers for same paths (#141) (79e04b8)

Features

  • core: Support custom functions in matchRequestsBy config options (#138) (626a84c)
  • Add an onIdentifyRequest hook to allow adapter level serialization (#140) (548002c)
  <a name="1.2.0"></a>

1.2.0 (2018-09-16)

Bug Fixes

  • adapter-puppeteer: Do not intercept CORS preflight requests (#90) (53ad433)
  • Changes self to global, rollup-plugin-node-globals makes isomorphic (#54) (3811e9d)
  • core: Freeze request after emitting afterResponse. (66a2b64)
  • Allow 204 responses without a body (#101) (20b4125)
  • Browser (UMD) build now bundles corejs (#106) (ec62fc0)
  • Bumping core within Ember (af4faa1)
  • Config expiresIn can contain periods. i.e, 1.5 weeks (e9c7aaa)
  • Correctly normalize relative URLs (b9b23cd)
  • Creator cleanup and persister assertion (#67) (19fee5a)
  • Do not display node server listening banner in quiet mode (1be57a7)
  • Ensure polly's middleware goes before ember-cli's (#36) (43db361)
  • Improve support for relative URLs (#78) (2c0083e), closes #76
  • Loosen up global XHR native check (#69) (79cdd96)
  • Proxy route.params onto the request instead of mutating req (5bcd4f9)
  • Puppeteer 1.7.0 support (#100) (e208b38)
  • Puppeteer CORS request matching (#110) (7831115)
  • Rest server on Windows (be5c473)
  • core: Set url on the fetch Response object (#44) (f5980cf), closes #43
  • ember: Fix auto-register and add tests to cover (24c15bd)
  • persister: Handle concurrent find requests (#88) (0e02414)

Features

  • Abort and passthrough from an intercept (#57) (4ebacb8)
  • Class events and EventEmitter (#52) (0a3d591)
  • Cleanup event handler logic + rename some event names (78dbb5d)
  • Convert recordings to be HAR compliant (#45) (e622640)
  • Custom persister support (8bb313c)
  • Fetch adapter support for context provided via adapterOptions (#66) (82ebd09)
  • Improved adapter and persister registration (#62) (164dbac)
  • Keyed persister & adapter options (#60) (29ed8e1)
  • Make recording size limit configurable (#40) (d4be431)
  • Move more response methods to shared base class (#74) (4f845e5)
  • Node File System Persister (#61) (0a0eeca)
  • Presets persisterOptions.host to the node server default (0b47838)
  • Puppeteer Adapter (#64) (f902c6d)
  • Use status code 204 in place of 404. (#5) (930c492)
  • core: Add json property to Request (bb8e1cb), closes #7
  • core: Default Response status code to 200 (f42a281), closes #6
  • Wait for all handled requests to resolve via .flush() (#75) (a3113b7)
  • core: Normalize headers by lower-casing all keys (#42) (02a4767)
  • core: Server level configuration (#80) (0f32d9b)
  • node-server: Add cors support to express server to pass-through all requests (223ce4e)
  • persister: Add keepUnusedRequests config option (#108) (3f5f5b2)
  • persister: Cache recordings (#31) (a04d7a7)

Reverts

  • "Update commitlint.config.js" (65e6996)
  • Add json property to Request (4ea50e8)
  • Revert "Update commitlint.config.js" (6624cb5)
  • Revert Use docsify GA plugin (35ace6f)
  • Use docsify GA plugin (cf5f1c5)

BREAKING CHANGES

  • Adapters
import { XHRAdapter, FetchAdapter } from '@pollyjs/core';

// Register the xhr adapter so its accessible by all future polly instances
Polly.register(XHRAdapter);

polly.configure({
adapters: ['xhr', FetchAdapter]
});

Persister

import { LocalStoragePersister, RESTPersister } from '@pollyjs/core';

// Register the local-storage persister so its accessible by all future polly instances
Polly.register(LocalStoragePersister);

polly.configure({
persister: 'local-storage'
});

polly.configure({
persister: RESTPersister
});
  • Recordings now produce HAR compliant json. Please delete existing recordings.
  • core: With this change, request ids will resolve to a different hash meaning that users will have to rerecord.
  • Relative URLs will have different hashes and will require to re-record.
  # Changelog