From e9ef27c18c5441b34920d883da90feb27d294932 Mon Sep 17 00:00:00 2001 From: Christian Emmer <10749361+emmercm@users.noreply.github.com> Date: Mon, 30 Dec 2024 12:32:54 -0800 Subject: [PATCH] Use async --- jest.config.ts | 92 ++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/jest.config.ts b/jest.config.ts index c4912fdaa..f7fc6bb01 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,49 +1,51 @@ import fs from 'node:fs'; import path from 'node:path'; -import { JestConfigWithTsJest } from 'ts-jest'; - -// Fix some bad package.json files that don't play well with ts-jest -[ - // https://github.com/g-plane/cue/issues/1 - '@gplane/cue', -].forEach((moduleName) => { - const modulePath = path.join('node_modules', moduleName); - const packagePath = path.join(modulePath, 'package.json'); - const packageJson = JSON.parse(fs.readFileSync(packagePath).toString()); - - packageJson.main = packageJson.main ?? packageJson.exports['.'].import; - delete packageJson.exports; - - fs.writeFileSync(packagePath, JSON.stringify(packageJson, undefined, 2)); -}); - -const jestConfig: JestConfigWithTsJest = { - preset: 'ts-jest', - testEnvironment: 'node', - - setupFilesAfterEnv: ['jest-extended/all'], - - // 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 - extensionsToTreatAsEsm: ['.ts'], - transform: { - '^.+\\.tsx?$': ['ts-jest', { useESM: true }], - }, - moduleNameMapper: { - '^(\\.{1,2}/.*)\\.js$': '$1', - // END https://kulshekhar.github.io/ts-jest/docs/guides/esm-support - }, - - // Don't run any compiled versions of the tests, if they exist - modulePathIgnorePatterns: ['/dist/'], - // Don't report coverage on the test directory - coveragePathIgnorePatterns: ['/test/'], - - // Report coverage on all source files, because it won't by default... - collectCoverageFrom: ['/src/**/*.{js,cjs,mjs,ts}'], +import type { Config } from 'jest'; + +export default async (): Promise => { + // Fix some bad package.json files that don't play well with ts-jest + await Promise.all( + [ + // https://github.com/g-plane/cue/issues/1 + '@gplane/cue', + ].map(async (moduleName) => { + const modulePath = path.join('node_modules', moduleName); + const packagePath = path.join(modulePath, 'package.json'); + const packageJson = JSON.parse((await fs.promises.readFile(packagePath)).toString()); + + packageJson.main = packageJson.main ?? packageJson.exports['.'].import; + delete packageJson.exports; + + await fs.promises.writeFile(packagePath, JSON.stringify(packageJson, undefined, 2)); + }), + ); + + return { + preset: 'ts-jest', + testEnvironment: 'node', + + setupFilesAfterEnv: ['jest-extended/all'], + + // 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 + extensionsToTreatAsEsm: ['.ts'], + transform: { + '^.+\\.tsx?$': ['ts-jest', { useESM: true }], + }, + moduleNameMapper: { + '^(\\.{1,2}/.*)\\.js$': '$1', + // END https://kulshekhar.github.io/ts-jest/docs/guides/esm-support + }, + + // Don't run any compiled versions of the tests, if they exist + modulePathIgnorePatterns: ['/dist/'], + // Don't report coverage on the test directory + coveragePathIgnorePatterns: ['/test/'], + + // Report coverage on all source files, because it won't by default... + collectCoverageFrom: ['/src/**/*.{js,cjs,mjs,ts}'], + }; }; - -export default jestConfig;