From e6a114ab06c306ae9fb0094c8821eb309baf3f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20Marussy?= Date: Fri, 31 Dec 2021 14:11:59 +0100 Subject: test: Switch to esbuild for faster tests --- config/jest.config.base.js | 17 +++++++++-------- config/jestEsbuildTransform.js | 26 ++++++++++++++++++++++++++ package.json | 1 - yarn.lock | 1 - 4 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 config/jestEsbuildTransform.js 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'; const thisDir = fileURLToDirname(import.meta.url); -/** @type {import('ts-jest').InitialOptionsTsJest} */ +/** @type {import('@jest/types').Config.InitialOptions} */ export default { - preset: 'ts-jest/presets/default-esm', - globals: { - 'ts-jest': { - useESM: true, - }, + transform: { + '\\.tsx?$': join(thisDir, 'jestEsbuildTransform.js'), }, + extensionsToTreatAsEsm: [ + '.ts', + '.tsx', + ], moduleNameMapper: { '@sophie/(.+)': join(thisDir, '../packages/$1/src/index.ts'), - '^(\\.{1,2}/.*)\\.js$': '$1', - // Workaround for typescript to recognize the vendored dependencies of chalk. + '^(\\.{1,2}/.*)\\.jsx?$': '$1', + // Workaround for jest to recognize the vendored dependencies of chalk. '#ansi-styles': join(thisDir, '../node_modules/chalk/source/vendor/ansi-styles/index.js'), '#supports-color': join(thisDir, '../node_modules/chalk/source/vendor/supports-color/index.js'), }, 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 @@ +import { transform } from 'esbuild'; + +import { node } from './buildConstants.js'; + +export default { + /** + * @param {string} source + * @param {string} filePath + * @param {import('@jest/types').Config.GlobalConfig} jestConfig + * @return {Promise} + */ + async processAsync(source, filePath) { + const { code } = await transform(source, { + loader: filePath.endsWith('tsx') ? 'tsx' : 'ts', + sourcefile: filePath, + format: 'esm', + target: node, + sourcemap: 'inline', + }); + return { + code, + originalCode: source, + sourceMapPath: null, + }; + }, +}; diff --git a/package.json b/package.json index ab2fc9f..f1ee627 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,6 @@ "jest": "^27.4.5", "rimraf": "^3.0.2", "rollup": "^2.62.0", - "ts-jest": "^27.1.2", "typescript": "^4.5.4", "vite": "^2.7.10" }, diff --git a/yarn.lock b/yarn.lock index 9d19aac..41293cb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7015,7 +7015,6 @@ __metadata: preload: ^0.1.0 rimraf: ^3.0.2 rollup: ^2.62.0 - ts-jest: ^27.1.2 typescript: ^4.5.4 vite: ^2.7.10 languageName: unknown -- cgit v1.2.3