diff options
author | Kristóf Marussy <kristof@marussy.com> | 2021-12-31 14:11:59 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2021-12-31 14:11:59 +0100 |
commit | e6a114ab06c306ae9fb0094c8821eb309baf3f65 (patch) | |
tree | cbb76e667920c94939a5702da69f85acfd3e8c9a /config | |
parent | build: Use exports field for modules (diff) | |
download | sophie-e6a114ab06c306ae9fb0094c8821eb309baf3f65.tar.gz sophie-e6a114ab06c306ae9fb0094c8821eb309baf3f65.tar.zst sophie-e6a114ab06c306ae9fb0094c8821eb309baf3f65.zip |
test: Switch to esbuild for faster tests
Diffstat (limited to 'config')
-rw-r--r-- | config/jest.config.base.js | 17 | ||||
-rw-r--r-- | config/jestEsbuildTransform.js | 26 |
2 files changed, 35 insertions, 8 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 | }; | ||