Skip to content

Commit

Permalink
Fix: get rid of Jest ESM hacks (#729)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored Oct 1, 2023
1 parent c76dcc0 commit add9ec9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
20 changes: 4 additions & 16 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
import path from 'node:path';
import { JestConfigWithTsJest } from 'ts-jest';

const jestConfig = {
const jestConfig: JestConfigWithTsJest = {
testEnvironment: 'node',

// Most tests are I/O-bound, increase the test timeout globally
testTimeout: 20_000,

// BEGIN https://kulshekhar.github.io/ts-jest/docs/guides/esm-support
preset: 'ts-jest/presets/default-esm-legacy',
extensionsToTreatAsEsm: ['.ts'],
transform: {
'\\.ts$': ['ts-jest', { useESM: true }],
'^.+\\.tsx?$': ['ts-jest', { useESM: true }],
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
// END https://kulshekhar.github.io/ts-jest/docs/guides/esm-support

// BEGIN https://github.com/facebook/jest/issues/12270#issuecomment-1111533936
chalk: require.resolve('chalk'),
'#ansi-styles': path.join(
require.resolve('chalk').split('chalk')[0],
'chalk/source/vendor/ansi-styles/index.js',
),
'#supports-color': path.join(
require.resolve('chalk').split('chalk')[0],
'chalk/source/vendor/supports-color/index.js',
),
// END https://github.com/facebook/jest/issues/12270#issuecomment-1111533936
},

// Don't run any compiled versions of the tests, if they exist
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
},
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": true,
"experimentalSpecifierResolution": "node",
"files": true, // without this `ts-node` and `node --loader ts-node/esm` won't find our custom types
}
}

0 comments on commit add9ec9

Please sign in to comment.