npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@chealt/jest-mock-environment

v0.16.2

Published

[![npm](https://img.shields.io/npm/v/@chealt/jest-mock-environment.svg)](http://npm.im/@chealt/jest-mock-environment) [![License](https://img.shields.io/npm/l/@chealt/jest-mock-environment.svg)](/LICENSE) # @chealt/jest-mock-environment

Downloads

64

Readme

npm License

@chealt/jest-mock-environment

A custom environment for Jest to record and replay requests and their responses during a test execution using Puppeteer.

Install

NPM

npm install @chealt/jest-mock-environment puppeteer

Yarn

yarn add @chealt/jest-mock-environment puppeteer

Usage

Update your Jest config with

{
  "testRunner": "jest-circus/runner",
  "globalSetup": "@chealt/jest-mock-environment/setup",
  "globalTeardown": "@chealt/jest-mock-environment/teardown",
  "testEnvironment": "@chealt/jest-mock-environment"
}

See a more detailed example in the Jest Mock example package.

Additional configuration

Using the Jest config testEnvironmentOptions you have the following options:

mockResponseDir (required)

Relative path to the rootDir in your config to store and load the recorded responses. The mocks will be saved using the specs' relative path with the postfix .mocks.json.

Example:

{
  "testEnvironmentOptions": {
    "mockResponseDir": "mocks"
  }
}

It is also possible to create global mocks that will be used for all tests. The environment will check if a global.mocks.json exists in the mockResponseDir and prefer that over the test mocks. The content of the file is similar to the test mock files but it does NOT include the name of the spec.

collectCoverage

Type: Boolean Default: false

Indicates whether the coverage information should be collected while executing the test.

coverage example

collectCoverageFrom

Type: array<String> Default: undefined

A list of Strings to be created regular expressions of to match the URLs to be collected coverage information from. These will be passed to new RegExp with the u flag and any URL matching any one of them will be included.

To take effect the collectCoverage option must be true.

coverageDirectory

Type: String Default: undefined

Relative path to the rootDir in your config to store the code coverage.

Example:

{
  "testEnvironmentOptions": {
    "coverageDirectory": "coverage"
  }
}

printCoverageSummary

Type: Boolean Default: false

Indicate if you would like to see the coverage summary in the console after the tests finished executing.

recordCoverageText

Type: Boolean Default: false

When Puppeteer collects coverage information it records each asset's text as well as the ranges. This can make the coverage file quite large, therefore, by default, the library excludes this information from the output.

isHostAgnostic

Type: Boolean Default: false

If true when using the mocks the host in the URL (including the protocol) won't be used to match the recorded response.

isPortAgnostic

Type: Boolean Default: false

If true when using the mocks the port in the URL won't be used to match the recorded response.

requestPathIgnorePatterns

Type: array<String> Default: undefined

A list of Strings to be created regular expressions of to not be included in the recorded requests. These will be passed to new RegExp with the u flag and any URL matching any one of them will be included.

shouldUseMocks

Type: Boolean Default: false

If true the recorded responses will be used, otherwise the environment records the requests and responses.

recordScreenshots

Type: Boolean Default: false

Indicates whether screenshots should be taken while executing the test.

screenshotDirectory

Type: String Default: undefined

Relative path to the rootDir in your config to store the screenshots taken during the test run.

Example:

{
  "testEnvironmentOptions": {
    "screenshotDirectory": "screenshots"
  }
}

collectPerfMetrics

Type: Boolean Default: false

Indicates whether the performance metrics should be collected while executing the test.

perfMetricsDirectory

Type: String Default: undefined

Relative path to the rootDir in your config to store the performance metrics.

Example:

{
  "testEnvironmentOptions": {
    "perfMetricsDirectory": "performance"
  }
}

Screenshot on failure

The environment will take a screenshot of the full page if a test fails and store it using the following format: <<TEST_NAME>>--failure.png.