js-cjs
js-cjs runs JavaScript tests as CommonJS in the node environment. jest-esm-transformer-2 transforms JavaScript,
including ESM packages in node_modules.
module.exports = { preset: '@repobuddy/jest/presets/js-cjs',}Options
Section titled “Options”None. A preset takes no options.
Effective config
Section titled “Effective config”Printed from the built preset with Node.js 26, in a directory that has a src folder:
{ transform: { '\\.m?jsx?$': 'jest-esm-transformer-2', }, transformIgnorePatterns: [], collectCoverageFrom: [ '<rootDir>/src/**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}', '!<rootDir>/src/**/*.stories.*', ], roots: ['<rootDir>/src'], coveragePathIgnorePatterns: [ '\\.(spec|test|unit|accept|integrate|learning|system|perf|stress|load)(\\..*)?\\.(js|jsx|cjs|mjs|ts|tsx|cts|mts)$', ], testEnvironment: 'node', testRegex: [ '\\.(spec|test|unit|accept|integrate|learning|system|perf|stress)(\\.node)?\\.(js|jsx|cjs|mjs|ts|tsx|cts|mts)$', '\\.(spec|test|unit|accept|integrate|learning|system|perf|stress)\\.node14\\.(js|jsx|cjs|mjs|ts|tsx|cts|mts)$', // one entry per Node.js major, from 15 up to the running major ],}It is built from configs.jsCjs,
configs.configSource(), and
configs.node.
Packages it needs
Section titled “Packages it needs”extract.extractPackages() on the preset returns:
['jest-environment-node', 'jest-esm-transformer-2']Behavior
Section titled “Behavior”transformIgnorePatterns: []makes Jest transform files innode_modules. In thejs-cjsfixture,require('chalk').defaultloads chalk 6, an ESM-only package.- The
transformpattern matches.js,.jsx,.mjs, and.mjsx..cjsfiles are not transformed. - Test file names: see test file names.
js-cjs-watch variant
Section titled “js-cjs-watch variant”@repobuddy/jest/presets/js-cjs-watch is js-cjs plus the watch plugins of the watch
preset.
Examples
Section titled “Examples”The js-cjs fixture keeps its source in source/, which the preset detects:
module.exports = { preset: '@repobuddy/jest/presets/js-cjs-watch', detectOpenHandles: true,}