ts
ts resolves to ts-esm or ts-cjs, based on the
type field of the nearest package.json.
export default { preset: '@repobuddy/jest/presets/ts',}Options
Section titled “Options”None. A preset takes no options.
Effective config
Section titled “Effective config”When the preset loads, it reads the nearest package.json, starting from the directory Jest runs in:
package.json type |
Resolves to |
|---|---|
"module" |
the ts-esm config |
anything else, or no package.json |
the ts-cjs config |
The value is the same object as the chosen preset. In a scratch directory with "type": "module" and a ts folder,
the printed preset had transform set to @swc/jest and roots set to ['<rootDir>/ts'].
Packages it needs
Section titled “Packages it needs”extract.extractPackages() returns the list of the preset it resolved to:
| Resolved to | Packages |
|---|---|
ts-esm |
@swc/jest, jest-environment-node |
ts-cjs |
jest-esm-transformer-2, jest-environment-node, ts-jest |
Behavior
Section titled “Behavior”- The choice happens once, when Jest loads the preset. It uses the working directory, not the
rootDirof a project. In a multi-project config run from the repository root, every project gets the rootpackage.json’s choice. See the monorepo guide. - An ESM result needs
NODE_OPTIONS=--experimental-vm-modules. Seets-esm.
ts-watch variant
Section titled “ts-watch variant”@repobuddy/jest/presets/ts-watch resolves the same way, to ts-esm-watch or ts-cjs-watch. Those add the plugins of
the watch preset.
Examples
Section titled “Examples”The ts-cjs fixture has no type field, so ts resolves to ts-cjs:
module.exports = { preset: '@repobuddy/jest/presets/ts', detectOpenHandles: true,}The ts-esm fixture has "type": "module", so ts-watch resolves to ts-esm-watch:
export default { preset: '@repobuddy/jest/presets/ts-watch', detectOpenHandles: true,}Related
Section titled “Related”jsdom-ts: the same detection for jsdom.- TypeScript with ESM, TypeScript with CommonJS