diff options
-rw-r--r-- | config/jest.config.base.js | 17 | ||||
-rw-r--r-- | config/jestEsbuildTransform.js | 26 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | yarn.lock | 1 |
4 files changed, 35 insertions, 10 deletions
diff --git a/config/jest.config.base.js b/config/jest.config.base.js index 87d5b31..bc34295 100644 --- a/config/jest.config.base.js +++ b/config/jest.config.base.js | |||
@@ -4,18 +4,19 @@ import { fileURLToDirname } from './utils.js'; | |||
4 | 4 | ||
5 | const thisDir = fileURLToDirname(import.meta.url); | 5 | const thisDir = fileURLToDirname(import.meta.url); |
6 | 6 | ||
7 | /** @type {import('ts-jest').InitialOptionsTsJest} */ | 7 | /** @type {import('@jest/types').Config.InitialOptions} */ |
8 | export default { | 8 | export default { |
9 | preset: 'ts-jest/presets/default-esm', | 9 | transform: { |
10 | globals: { | 10 | '\\.tsx?$': join(thisDir, 'jestEsbuildTransform.js'), |
11 | 'ts-jest': { | ||
12 | useESM: true, | ||
13 | }, | ||
14 | }, | 11 | }, |
12 | extensionsToTreatAsEsm: [ | ||
13 | '.ts', | ||
14 | '.tsx', | ||
15 | ], | ||
15 | moduleNameMapper: { | 16 | moduleNameMapper: { |
16 | '@sophie/(.+)': join(thisDir, '../packages/$1/src/index.ts'), | 17 | '@sophie/(.+)': join(thisDir, '../packages/$1/src/index.ts'), |
17 | '^(\\.{1,2}/.*)\\.js$': '$1', | 18 | '^(\\.{1,2}/.*)\\.jsx?$': '$1', |
18 | // Workaround for typescript to recognize the vendored dependencies of chalk. | 19 | // Workaround for jest to recognize the vendored dependencies of chalk. |
19 | '#ansi-styles': join(thisDir, '../node_modules/chalk/source/vendor/ansi-styles/index.js'), | 20 | '#ansi-styles': join(thisDir, '../node_modules/chalk/source/vendor/ansi-styles/index.js'), |
20 | '#supports-color': join(thisDir, '../node_modules/chalk/source/vendor/supports-color/index.js'), | 21 | '#supports-color': join(thisDir, '../node_modules/chalk/source/vendor/supports-color/index.js'), |
21 | }, | 22 | }, |
diff --git a/config/jestEsbuildTransform.js b/config/jestEsbuildTransform.js new file mode 100644 index 0000000..7c6a57c --- /dev/null +++ b/config/jestEsbuildTransform.js | |||
@@ -0,0 +1,26 @@ | |||
1 | import { transform } from 'esbuild'; | ||
2 | |||
3 | import { node } from './buildConstants.js'; | ||
4 | |||
5 | export default { | ||
6 | /** | ||
7 | * @param {string} source | ||
8 | * @param {string} filePath | ||
9 | * @param {import('@jest/types').Config.GlobalConfig} jestConfig | ||
10 | * @return {Promise<import('@jest/types').TransformTypes.TransformResult>} | ||
11 | */ | ||
12 | async processAsync(source, filePath) { | ||
13 | const { code } = await transform(source, { | ||
14 | loader: filePath.endsWith('tsx') ? 'tsx' : 'ts', | ||
15 | sourcefile: filePath, | ||
16 | format: 'esm', | ||
17 | target: node, | ||
18 | sourcemap: 'inline', | ||
19 | }); | ||
20 | return { | ||
21 | code, | ||
22 | originalCode: source, | ||
23 | sourceMapPath: null, | ||
24 | }; | ||
25 | }, | ||
26 | }; | ||
diff --git a/package.json b/package.json index ab2fc9f..f1ee627 100644 --- a/package.json +++ b/package.json | |||
@@ -49,7 +49,6 @@ | |||
49 | "jest": "^27.4.5", | 49 | "jest": "^27.4.5", |
50 | "rimraf": "^3.0.2", | 50 | "rimraf": "^3.0.2", |
51 | "rollup": "^2.62.0", | 51 | "rollup": "^2.62.0", |
52 | "ts-jest": "^27.1.2", | ||
53 | "typescript": "^4.5.4", | 52 | "typescript": "^4.5.4", |
54 | "vite": "^2.7.10" | 53 | "vite": "^2.7.10" |
55 | }, | 54 | }, |
@@ -7015,7 +7015,6 @@ __metadata: | |||
7015 | preload: ^0.1.0 | 7015 | preload: ^0.1.0 |
7016 | rimraf: ^3.0.2 | 7016 | rimraf: ^3.0.2 |
7017 | rollup: ^2.62.0 | 7017 | rollup: ^2.62.0 |
7018 | ts-jest: ^27.1.2 | ||
7019 | typescript: ^4.5.4 | 7018 | typescript: ^4.5.4 |
7020 | vite: ^2.7.10 | 7019 | vite: ^2.7.10 |
7021 | languageName: unknown | 7020 | languageName: unknown |