Skip to content

jsdom-ts-cjs

jsdom-ts-cjs runs TypeScript tests as CommonJS in the jsdom environment. ts-jest transforms TypeScript, and jest-esm-transformer-2 transforms JavaScript, including ESM packages in node_modules.

jest.config.js
module.exports = {
preset: '@repobuddy/jest/presets/jsdom-ts-cjs',
}

None. A preset takes no options.

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

{
transform: {
'^.+\\.(ts|tsx|cts|mts)$': ['ts-jest', { isolatedModules: true }],
'\\.m?jsx?$': 'jest-esm-transformer-2',
},
transformIgnorePatterns: [],
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.tsCjs, configs.configSource(), and configs.jsdom.

extract.extractPackages() on the preset returns:

['jest-environment-jsdom', 'jest-esm-transformer-2', 'ts-jest']

@repobuddy/jest does not declare jest-environment-jsdom. Install it yourself. ts-jest also needs typescript.

  • Same transforms as ts-cjs, including transformIgnorePatterns: [].
  • Uses testMatch instead of testRegex. See test file names.
  • Sets no coveragePathIgnorePatterns. Jest skips test files from coverage on its own.

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

jest.config.js
module.exports = {
preset: '@repobuddy/jest/presets/jsdom-ts-cjs-watch',
}