Skip to content

Commit

Permalink
fix: make jest ESM-ready
Browse files Browse the repository at this point in the history
  • Loading branch information
mizdra committed Dec 28, 2021
1 parent 1afa2db commit c550aec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
// eslint-disable-next-line import/no-default-export
export default {
displayName: 'test',
preset: 'ts-jest',
preset: 'ts-jest/presets/default-esm',
testMatch: ['<rootDir>/test/**/*.test.ts?(x)'],
// Since fixtures-tmp are rewritten during testing, if they are in the watch target, the test will be retrying infinitely.
watchPathIgnorePatterns: ['<rootDir>/fixtures-tmp/'],
// ESLint v8 では `pkg.exports` を利用したモジュールに依存しているが、jest は `pkg.exports` を解釈できないため、
// そのままだと jest がコケてしまう。そこで `moduleNameMapper` を使って無理やりモジュール名を解決している。
moduleNameMapper: {
'@eslint/eslintrc/universal': '@eslint/eslintrc/dist/eslintrc-universal.cjs',
// Map `./**/xxx.js` to `./**/xxx` (for ESM)
'^(\\.{1,2}/.*)\\.js$': '$1',
},
// do not transform `import` statements (for ESM)
transform: {},
collectCoverageFrom: ['<rootDir>/src/**/*.{ts,tsx}', '!**/*.d.ts'],
globals: {
'ts-jest': {
tsconfig: 'tsconfig.test.json',
useESM: true,
},
},
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lint:tsc:test": "tsc -p tsconfig.test.json --noEmit",
"lint:eslint": "eslint --ignore-pattern '/fixtures' .",
"lint:prettier": "prettier --check .",
"test": "jest --colors"
"test": "NODE_OPTIONS=--experimental-vm-modules jest --colors"
},
"prettier": "@mizdra/prettier-config-mizdra",
"renovate": "github>mizdra/renovate-config-mizdra",
Expand Down

0 comments on commit c550aec

Please sign in to comment.