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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@moxy/jest-config-base

v6.1.0

Published

MOXY's Jest base configuration

Downloads

163

Readme

jest-config-base

NPM version Downloads Dependency status Dev Dependency status

MOXY's Jest base configuration.

Installation

$ npm install --save-dev jest @moxy/eslint-config-base

How it works

baseConfig is the base point of this configuration. It includes all defaults offered by jest-config and has project-agnostic configurations, meant to help any project regardless of their purpose, including:

  • Test match: Tweaks testMatch so that only files named test.js or files ending with .test.js are considered test files, even if they are inside __tests__ or any other folder.
  • Test path ignore patterns: Tweaks testPathIgnorePatterns to ignore common folders, such as docusaurus.
  • Transform:
    • Enables Babel so that jest.mock() and similar functions are automatically hoisted to the top. If your project uses Babel, its configuration will be read and used to transpile code.
    • Setups transforms for common files, such as images and files.
  • Coverage: Enables coverage for CI, a feature supported by ci-info, which you can check for information about supported CI services.
  • Coverage thresholds: For a good balance between strict but workable thresholds.
  • Snapshot serializing: To remove absolute paths from your snapshots, reducing conflicts in CI.

Usage

Create jest.config.js at the root of your project:

'use strict';

const { baseConfig } = require('@moxy/jest-config-base');

module.exports = baseConfig();

The baseConfig function accepts an optional parameter that allows to specify the Jest environment, which can be jsdom (default) or node. As an example, for Node.js projects you would use like so:

const { baseConfig } = require('@moxy/jest-config');

module.exports = baseConfig('node');

Alternatively, you may pass a path to a custom environment. In fact, we offer the following custom environments:

Special Node environment class for Jest which runs all scripts in the same context. This effectively disables the sandbox isolation to circumvent issues with Jest's sandboxing, which causes subtle bugs in specific situations, such as in code that relies in instanceof checks.

'use strict';

const { baseConfig } = require('@moxy/jest-config');

module.exports = baseConfig('@moxy/jest-config/environments/node-single-context');

⚠️ Only activate this environment if you are having problems with the aforementioned issue, and before trying other workarounds.

Composing enhancers

To use enhancers, use the compose function that comes with this package. Keep in mind, the first item should always be the base configuration! Here's an example of using compose:

'use strict';

const { compose, baseConfig } = require('@moxy/jest-config-base');
const withMyEnhancer = require('<your-own-enhancer>');

module.exports = compose(
    baseConfig(),
    withMyEnhancer(),
);

Enhancers are functions which accept a single argument, i.e., Jest's config object, and return the enhanced config. You may also use compose to add your own inline enhancer:

'use strict';

const { compose, baseConfig } = require('@moxy/jest-config');

module.exports = compose(
    baseConfig(),
    (config) => ({
        ...config,
        // Do not test `.data.js` files
        testPathIgnorePatterns: [
            ...config.pathIgnorePatterns,
            '/.*.data.js$/'
        ];
    }),
);

Without compose

If you want to modify the base config without using compose, you may change the config imperatively like so:

'use strict';

const { baseConfig } = require('@moxy/jest-config');

const config = baseConfig();

// Do not test `.data.js` files
config.testPathIgnorePatterns = [
    ...config.testPathIgnorePatterns,
    '/.*.data.js$/'
];

module.exports = config;

Tests

Any parameter passed to the test command is passed down to Jest.

$ npm t
$ npm t -- --watch  # To run watch mode