Skip to content

jsdom-ts-esm

jsdom-ts-esm runs TypeScript tests as native ES modules in the jsdom environment, transformed by @swc/jest.

jest.config.mjs
export default {
preset: '@repobuddy/jest/presets/jsdom-ts-esm',
}
Terminal window
NODE_OPTIONS=--experimental-vm-modules jest

None. A preset takes no options.

Printed from the built preset, in a directory that has a src folder:

{
extensionsToTreatAsEsm: ['.ts', '.mts', '.tsx'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'^.+\\.(js|jsx|cjs|mjs|ts|tsx|cts|mts)$': '@swc/jest',
},
collectCoverageFrom: [
'<rootDir>/src/**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}',
'!<rootDir>/src/**/*.stories.*',
],
roots: ['<rootDir>/src'],
testEnvironment: 'jsdom',
testMatch: [
'**/?*\\.(spec|test|unit|accept|integrate|learning|system|perf|stress)?(.jsdom).(js|jsx|cjs|mjs|ts|tsx|cts|mts)',
],
}

It is built from configs.tsEsm, configs.configSource(), and configs.jsdom.

extract.extractPackages() on the preset returns:

['@swc/jest', 'jest-environment-jsdom']

@repobuddy/jest does not declare jest-environment-jsdom. Install it yourself, along with @swc/jest and @swc/core.

  • Same transform and .js import mapping as ts-esm.
  • Uses testMatch instead of testRegex. It runs <name>.<id>.<ext> and <name>.<id>.jsdom.<ext>. Node-only names such as a.spec.node.ts do not run. See test file names.
  • Sets no coveragePathIgnorePatterns. Jest skips test files from coverage on its own.

@repobuddy/jest/presets/jsdom-ts-esm-watch is jsdom-ts-esm plus the watch plugins of the watch preset.

The jsdom-ts fixture in this repository:

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