jest howto
[toc]
top js test frameworks
top 1: jest
top 2: mocha
others are: jsamine
, tape
, etc.
In project of rehype-shortcodes
, I found them using tape
and seems cabinet(小巧的) and output-friendly.
Nevertheless, I used to use jest
and ts-jest
which is mature and strong. So I didn't pretend to dive into tape
deeper.
jest
ESM support
- Add
"type": "module"
in package.json - Add
transform: {}
injest.config.js
- use one of the following approach to run jest in
esm
mode:node --experimental-vm-modules ./node_modules/.bin/jest JS_FILE
NODE_OPTIONS=--experimental-vm-modules npx jest JS_FILE
- Add
"scripts": {"test": "NODE_OPTIONS=--experimental-vm-modules npx jest"}
inpackage.json
, then runtest JS_FILE
in command line - Add
--experimental-vm-modules
in webstorm jest configuration, and then click run button:
ref:
official answer of jest
stackoverflow solution
jest
+ typescript
+ ESM
// jest.config.js
module.exports = {
preset: 'ts-jest/presets/default-esm', // or other ESM presets
globals: {
'ts-jest': {
useESM: true,
},
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
};
ref:
recommend: