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

Package detail

@moxy/jest-config-base

moxystudio430MIT6.1.0

MOXY's Jest base configuration

jest-config, jestconfig, jest, test, preset

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:

<summary>@moxy/jest-config/environments/node-single-context</summary>

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

changelog

Change Log

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

6.1.0 (2021-06-24)

Features

  • jest-config-base: add json5 support (#41) (f6898b0)

6.0.0 (2021-05-26)

⚠ BREAKING CHANGES

  • migrate @testing-library/react-native support to v7+ where Callstack's react-native-testing-library has been merged into.

Bug Fixes

  • jest-native peer dep on react-native and migrate to ntl v7 (55ace1b)

5.3.0 (2021-04-22)

Features

  • base config: add gltf file transform (#34) (6e3ec3c)

5.2.0 (2021-02-07)

Features

  • add typeahead watch plugin (c8cd450)

5.1.0 (2020-06-17)

  • feat: add native testing library setup (07e7912)

5.0.0 (2020-06-15)

  • chore: fix READMEs headings (e8aeb6b)
  • chore: fix READMEs syntax (d83581f)
  • chore: modularize repository into several packages (235c105)
  • chore: setup Node.js CI with Actions (#23) (c166020), closes #23

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

4.2.1 (2020-06-05)

Bug Fixes

  • ignore known enzyme/jsdom warnings emitted in React Native (9f97533)
  • use require.resolve to include React Native setup file (1f09586)

4.2.0 (2020-05-06)

Features

4.1.0 (2020-04-28)

Features

  • add node single context environment (#20) (5d32005)

Bug Fixes

  • add enzyme matchers to react native enhancer (#19) (f2375f7)
  • move animated mock to react native enhancer (#18) (8798738)

4.0.1 (2020-03-23)

Bug Fixes

  • remove unused dependency (59b7d11)

4.0.0 (2020-03-23)

⚠ BREAKING CHANGES

  • the base configuration no longer contains transforms nor mappings other than JavaScript files
  • baseConfig and enhancers are now factories
  • enhancers now validate if the test environment is correctly set
  • withEnzyme now has mandatory target argument
  • compose now accepts baseConfig as the first argument and enhancers are spread-ed after it

Features

Bug Fixes

  • fix testMatch pattern to not accept jsx (#13) (55dc8b0)

3.0.0 (2020-03-20)

⚠ BREAKING CHANGES

  • no longer detect .spec.js files (#12)

Features

2.1.0 (2020-03-14)

Features

2.0.2 (2020-03-10)

2.0.1 (2020-03-10)

Bug Fixes

  • remove peer dependency warning about react (2aef3a0)

2.0.0 (2020-02-21)

⚠ BREAKING CHANGES

  • withWeb addon no longer comes with RTL by default

Features

1.4.1 (2020-01-23)

Bug Fixes

1.4.0 (2020-01-23)

Features

  • ignore docusaurus in the web addon (008d17f)

1.3.0 (2020-01-22)

Features

1.2.0 (2019-12-17)

Features

  • add api to collect coverage from in the web addon (923150f)

1.1.1 (2019-11-21)

Bug Fixes

  • transformers not generating interop code (#5) (7047b45)

1.1.0 (2019-11-07)

Features

Bug Fixes

  • add missing babel-jest dependency (db1c38e)

1.0.2 (2019-11-05)

Bug Fixes

  • add repo to package.json (7e0d554)

1.0.1 (2019-11-05)

1.0.0 (2019-11-05)

Features