0.2.36 • Published 3 months ago

@swc/jest v0.2.36

Weekly downloads
836
License
MIT
Repository
github
Last release
3 months ago

@swc/jest

SWC binding for Jest.

Installation

# if you use npm
npm i -D jest @swc/core @swc/jest
# if you use yarn
yarn add -D jest @swc/core @swc/jest

Usage

jest.config.js:

module.exports = {
  transform: {
    '^.+\\.(t|j)sx?$': '@swc/jest',
  },
}

It will load the SWC configuration from .swcrc by default. You also can customize it:

const fs = require('fs')

const config = JSON.parse(fs.readFileSync(`${__dirname}/.swcrc`, 'utf-8'))

module.exports = {
  transform: {
    '^.+\\.(t|j)sx?$': ['@swc/jest', { ...config, /* custom configuration in Jest */ }],
  },
}

Q & A

Q: Jest uses CommonJS by default. But I want to use ESM.

A: Setup Jest following this Guide.

For JavaScript, edit package.json as follows:

{
  // ...
  "type": "module"
}

For TypeScript, edit jest.config.js as follows:

module.exports = {
  // ...
  extensionsToTreatAsEsm: ['.ts', '.tsx'],
}

Run test with --experimental-vm-modules:

cross-env NODE_OPTIONS=--experimental-vm-modules jest

# or
node --experimental-vm-modules ./node_modules/jest/bin/jest.js

Q: What ECMAScript target is set by jsc.target?

A: By default, the version supported by your Node runtime.

Node versionDefault jsc.target
12'es2018'
13'es2019'
14'es2020'
15'es2021'
16'es2021'
17'es2022'

You can customize this by setting an explicit version in jest.config.js:

module.exports = {
    transform: {
        "^.+\\.(t|j)sx?$": [
            "@swc/jest",
            {
                jsc: {
                    target: "es2021",
                },
            },
        ],
    },
}

License

MIT

@atmosfera/jest-config@storybook/test-runner@backstage/cli@infinitebrahmanuniverse/nolb-_swc@everything-registry/sub-chunk-886web3-security-snapwebpack-build-tooltest-runner-with-snap-speed-exptest-runner-with-snap-speed-exp2typescript-dev-loop@faasjs/jest@functionless/jest@equinor/opt-devvisyn_scriptsvanify@haojian-app/jest-preset@infinum/jesttailwind-radix-colorstdp_core@essex/jest-configreact-scripts-dependencies-upgradedrockmansquak@lowdefy/jest-yaml-transform@marigold/jest-config@m78/build-tools@m78/lib-build@packasso/jest@elliemae/pui-cli@fcsukltd/config@darcytech/jest-preset-darcytech@d-leb/swc-jestmongodb-safe-querybinance-local-exchangechakra-12345@techor/jestplugin-jest@dev-spendesk/cli@dfatwork-pkgs/backstage-cli@developpeurdurable/nx-workspace-plugincodeaprocomponetoscrontab-sentencereact-app-rewired-swccraco-swcrunes-js@rafyamada/jest-default-config@s-ui/jest@neodx/config@niieani/scaffold@nordicsemiconductor/pc-nrfconnect-shared@powerfulyang/lint@planjs/react-cli-service@venok/cli@versini/dev-dependencies-server@volkovlabs/grafana-utils@stijnvanhulle/jest-builder@metacraft/cli@matejlauko/jest-presets@jameslnewell/jest-preset@jameslnewell/jest-preset-node@hutm/footing@mediaplatform/sportal365-tennis-sdk@tksst/typescript-starter@snout/jest-config@rickzhou/react-test@sylo-digital/scripts@tarantool.io/tcm-jest-config@tty-pt/scripts@toptal/davinci-qaeh-react-scripts-legacy@amazeelabs/jest-preset@asyncapi/modelina@aklesky/jest-config@webdesserts/app-scripts@ainc/jest@autosoft/jest-presetmetacraftmhy@cartable/coremodular-scripts
0.2.36

3 months ago

0.2.34

3 months ago

0.2.33

3 months ago

0.2.32

3 months ago

0.2.31

3 months ago

0.2.30

3 months ago

0.2.27

9 months ago

0.2.29

9 months ago

0.2.28

9 months ago

0.2.26

1 year ago

0.2.25

1 year ago

0.2.24

1 year ago

0.2.23

2 years ago

0.2.22

2 years ago

0.2.21

2 years ago

0.2.20

2 years ago

0.2.19

2 years ago

0.2.18

2 years ago

0.2.17

2 years ago

0.2.16

2 years ago

0.2.15

2 years ago

0.2.14

2 years ago

0.2.12

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.2.7

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

4 years ago

0.1.1

4 years ago