Shared jest configuration for TypeScript packages: defineJestConfig, which fills in the ts-jest transform, the ESM settings, the test excludes and the coverage block a project otherwise writes by hand.
The coverage block is the one the vitest library configuration uses, so a package reports the same files whichever runner it picks.
| Function |
Description |
| defineJestConfig |
Defines a TypeScript project’s jest configuration. The defaults: the tests are src/**\/*.test.ts, run in the node environment, transformed by ts-jest, as ESM when the package is (see DefineJestConfigOptions.esm); a .js relative import resolves onto its .ts source; coverage is v8 over src/, without the barrels, the declarations, the tests and the test helpers, reported as text, lcov and html into coverage/. Every jest option in options replaces its default, except moduleNameMapper, whose entries are added to the .js mapper. |
| isEsmPackage |
Says whether the project at the root is an ES module package. |
| Variable |
Description |
| DEFAULT_JEST_TEST_PATH_IGNORE_PATTERNS |
Folders jest never collects tests from. |
| JEST_RELATIVE_JS_IMPORT_MAPPER |
Maps a relative import written with a .js extension onto the path without an extension, which jest resolves. A project compiled with module: nodenext writes ./foo.js for ./foo.ts, and so does TypeScript itself when rewriteRelativeImportExtensions turns a ./foo.ts import into ./foo.js. Jest looks for a file literally named foo.js and fails with Cannot find module './foo.js', so the extension is removed and jest’s own moduleFileExtensions search finds foo.ts. |
| JEST_TYPESCRIPT_TRANSFORM_PATTERN |
The files ts-jest compiles: .ts, .tsx, .mts and .cts. |