@moxy/jest-config-react-native

MOXY's Jest configuration enhancer for React Native apps


Keywords
jest-config, jestconfig, jest, test, preset, react-native
License
MIT
Install
npm install @moxy/jest-config-react-native@5.3.0

Documentation

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 @moxy/jest-config

Usage

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

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

module.exports = baseConfig();

What's included in baseConfig?

Our baseConfig has project agnostic configurations, meant to help any project regardless of their purpose, including;

  • Transform: Preprocessors for .js files as well as other common filetypes.
  • Module name mapping: For .css files, to correctly mock className lookups when using CSS Modules.
  • Coverage: By default, coverage is only verified in CI. This feature is 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 with in CI.

Addons

This packages comes with extra addons that further tweak the base Jest configuration to cover the needs of common situations. Here's a list of all addons we offer so far:

Addon Description
withWeb Adds setup and ignore patterns we use in next-with-moxy.
withRTL Adds setup for projects using React Testing Library.

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

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

module.exports = compose([baseConfig, withWeb]);

If you want to make your own addon, you can! It just needs to have the following structure:

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

// Receives previous configuration
const withAddon = (configuration) => {
    // Add your options to configuration
    // For example, do not test '.data.js' files
    configuration.testPathIgnorePatterns = ['/.*.data.js$/'];

    // Returns configuration with added options
    return configuration;
};

module.exports = compose([baseConfig, withAddon]);

Without addons

If you want to add your own options without using our addons or making your own, you may imperatively change the returned base config like so:

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

const myConfig = baseConfig();

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

module.exports = myConfig;

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.