Skip to content

jsdom-ts

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

jest.config.mjs
export default {
preset: '@repobuddy/jest/presets/jsdom-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 jsdom-ts-esm config
anything else, or no package.json the jsdom-ts-cjs config
Resolved to Packages from extract.extractPackages()
jsdom-ts-esm @swc/jest, jest-environment-jsdom
jsdom-ts-cjs jest-environment-jsdom, jest-esm-transformer-2, ts-jest
  • The choice happens once, when Jest loads the preset, and uses the working directory. See ts.
  • An ESM result needs NODE_OPTIONS=--experimental-vm-modules.

@repobuddy/jest/presets/jsdom-ts-watch resolves the same way, to jsdom-ts-esm-watch or jsdom-ts-cjs-watch.

The dual-ts-swc fixture ("type": "module") uses it in a second config file, with a mapper for uuid:

jest.config.bundle.cjs
/** @type {import('jest').Config} */
const config = {
preset: '@repobuddy/jest/presets/jsdom-ts',
detectOpenHandles: true,
moduleNameMapper: {
'^uuid$': require.resolve('uuid'),
},
}
module.exports = config