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; diff --git a/package-lock.json b/package-lock.json index a7fe21202..244bdb9cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -83,7 +83,7 @@ "prettier": "3.4.2", "ts-jest": "29.2.5", "ts-node": "10.9.2", - "typescript": "5.5.4", + "typescript": "5.7.2", "which": "5.0.0" }, "engines": { @@ -11313,9 +11313,9 @@ } }, "node_modules/typescript": { - "version": "5.5.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", - "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz", + "integrity": "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==", "dev": true, "license": "Apache-2.0", "bin": { diff --git a/package.json b/package.json index 659a59ed2..01afe1036 100644 --- a/package.json +++ b/package.json @@ -138,7 +138,7 @@ "prettier": "3.4.2", "ts-jest": "29.2.5", "ts-node": "10.9.2", - "typescript": "5.5.4", + "typescript": "5.7.2", "which": "5.0.0" }, "//engines": [ diff --git a/tsconfig.json b/tsconfig.json index 39a3f7111..dd7fb5f36 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,7 +27,7 @@ /* Modules */ "module": "node16", /* Specify what module code is generated. */ // "rootDir": "./", /* Specify the root folder within your source files. */ - "moduleResolution": "node16", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "moduleResolution": "node16", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ @@ -103,5 +103,9 @@ "ts-node": { "esm": true, "experimentalSpecifierResolution": "node", + // Fix typescript@>=5.6.0 breaking ts-node@10.9.2 + // WARN: this will skip type checking! + // https://github.com/nodejs/node/issues/48207#issuecomment-1880644283 + "transpileOnly": true } }