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

Package detail

@sucrase/jest-plugin

alangpierce82.6kMIT3.0.0TypeScript support: included

Jest plugin for Sucrase

readme

Sucrase Jest plugin

npm version MIT License

This is a simple Jest plugin that makes it easy to use Sucrase when running Jest tests.

Usage

First install the package and sucrase as a dev dependency:

yarn add --dev @sucrase/jest-plugin sucrase

Then change the default transform in jest.config.js file:

  ...
  transform: { "\\.(js|jsx|ts|tsx)$": "@sucrase/jest-plugin" },
  ...

You can specify additional transformation options to Sucrase by passing an object. For example, to enable automatic react transforms:

  ...
  transform: { "\\.(js|jsx|ts|tsx)$": ["@sucrase/jest-plugin", { jsxRuntime: 'automatic' }] },
  ...

By default, the transforms option is automatically detected based on file type and Jest mode. If you pass a transforms array in the options, it will apply to all files, regardless of extension.

changelog

3.0.0 (2022-10-08)

  • BREAKING: Switch sucrase to a peer dependency instead of a regular dependency. Please install sucrase separately as part of updating to this version. (#756)
  • BREAKING: Require jest >= 27 and and sucrase >= 3.25. (#749, #756)
  • BREAKING: Specify disableESTransforms by default, since it's no longer necessary for supported Node versions. (#754)
  • Add support for specifying Sucrase options in Jest config. (#749) (Jan Aagaard Meier; also implemented by stagas in #663)
  • Add support for using Jest in ESM mode, automatically configuring Sucrase accordingly. (#752)
  • Fix unhelpful error messages when an error is thrown from Sucrase. (#750)

2.2.1 (2022-04-28)

  • Add support for Jest 28. (#695) (Viktor Luft)

2.2.0 (2021-10-24)

  • Include inline source maps when transforming code. This fixes debugging in WebStorm. (#661)

2.1.1 (2021-08-09)

  • Add support for Jest 27. (#640) (Victor Pontis)

2.1.0 (2021-04-11)

  • Enable Sucrase's new jest transform to hoist jest.mock calls.

2.0.0 (2018-06-10)

  • Switch Sucrase dependency to ^3, update code to use new return type.