1 | # Sucrase Jest plugin
|
2 |
|
3 | [![npm version](https://badge.fury.io/js/@sucrase%2Fjest-plugin.svg)](https://www.npmjs.com/package/@sucrase/jest-plugin)
|
4 | [![MIT License](https://img.shields.io/npm/l/express.svg?maxAge=2592000)](LICENSE)
|
5 |
|
6 | This is a simple Jest plugin that makes it easy to use
|
7 | [Sucrase](https://github.com/alangpierce/sucrase) when running Jest tests.
|
8 |
|
9 | ## Usage
|
10 |
|
11 | First install the package and `sucrase` as a dev dependency:
|
12 | ```
|
13 | yarn add --dev @sucrase/jest-plugin sucrase
|
14 | ```
|
15 |
|
16 | Then change the default transform in jest.config.js file:
|
17 | ```ts
|
18 | ...
|
19 | transform: { "\\.(js|jsx|ts|tsx)$": "@sucrase/jest-plugin" },
|
20 | ...
|
21 | ```
|
22 |
|
23 | You can specify additional transformation options to Sucrase by passing an object. For example, to enable automatic react transforms:
|
24 |
|
25 | ```ts
|
26 | ...
|
27 | transform: { "\\.(js|jsx|ts|tsx)$": ["@sucrase/jest-plugin", { jsxRuntime: 'automatic' }] },
|
28 | ...
|
29 | ```
|
30 |
|
31 | By default, the `transforms` option is automatically detected based on file type and Jest mode.
|
32 | If you pass a `transforms` array in the options, it will apply to all files, regardless of extension.
|