This package has been deprecated

Author message:

This package has been deprecated due to a large refactoring. Please use one or more of the new @moxy/jest-config-* packages instead

@moxy/jest-config

4.2.1 • Public • Published

jest-config

NPM version Downloads Build Status Coverage Status Dependency status Dev Dependency status

MOXY's Jest configuration to be used across several JavaScript projects.

Installation

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

How it works

This package contains a base configuration and a set of enhancers. You may combine them to configure Jest for different types of projects.

Base config

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 config will be read and used to transpile code.
  • 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.

Enhancers

There are several enhancer packages, which are intended to be used in conjunction with the base configuration:

Usage

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

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

module.exports = baseConfig();

The baseConfig function accepts a 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:

@moxy/jest-config/environments/node-single-context

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.

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:

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

module.exports = compose(
    baseConfig(),
    withWeb(),
    withRTL(),
);

You may also use compose to add your own inline enhancer:

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:

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

License

Released under the MIT License.

Package Sidebar

Install

npm i @moxy/jest-config

Weekly Downloads

13

Version

4.2.1

License

MIT

Unpacked Size

33.9 kB

Total Files

26

Last publish

Collaborators

  • tiagodinis
  • moxyhq
  • filipediasf
  • satazor
  • marcooliveira
  • acostalima
  • andregoncalvesdev