js-esm
js-esm runs JavaScript tests as native ES modules in the node environment. It sets no transform.
export default { preset: '@repobuddy/jest/presets/js-esm',}NODE_OPTIONS=--experimental-vm-modules jestOptions
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:
{ extensionsToTreatAsEsm: ['.jsx'], 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.jsEsm,
configs.configSource(), and
configs.node.
Packages it needs
Section titled “Packages it needs”extract.extractPackages() on the preset returns:
['jest-environment-node']That package is a dependency of Jest, so jest is the only install.
Behavior
Section titled “Behavior”- The preset sets no
transform, so Jest’s default applies. With Jest 30,jest --showConfigin thejs-esmfixture showsbabel-jestfor\.[jt]sx?$. .jsfiles load as ESM becausepackage.jsonhas"type": "module".extensionsToTreatAsEsmadds.jsx.- Without
--experimental-vm-modules, ESM test files fail withSyntaxError: Cannot use import statement outside a module. - Test file names: see test file names.
js-esm-watch variant
Section titled “js-esm-watch variant”@repobuddy/jest/presets/js-esm-watch is js-esm plus the watch plugins of the watch
preset.
Examples
Section titled “Examples”The js-esm fixture keeps its source in js/, which the preset detects:
export default { preset: '@repobuddy/jest/presets/js-esm', detectOpenHandles: true,}