Skip to content

ts

ts resolves to ts-esm or ts-cjs, based on the type field of the nearest package.json.

jest.config.mjs
export default {
preset: '@repobuddy/jest/presets/ts',
}

None. A preset takes no options.

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'].

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
  • The choice happens once, when Jest loads the preset. It uses the working directory, not the rootDir of a project. In a multi-project config run from the repository root, every project gets the root package.json’s choice. See the monorepo guide.
  • An ESM result needs NODE_OPTIONS=--experimental-vm-modules. See ts-esm.

@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.

The ts-cjs fixture has no type field, so ts resolves to ts-cjs:

jest.config.js
module.exports = {
preset: '@repobuddy/jest/presets/ts',
detectOpenHandles: true,
}

The ts-esm fixture has "type": "module", so ts-watch resolves to ts-esm-watch:

jest.config.mjs
export default {
preset: '@repobuddy/jest/presets/ts-watch',
detectOpenHandles: true,
}