Skip to content
Myr

Remove jest esm examples (#2517)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by John Gee · committed by GitHub · parent d785d8b · Browse files · 13 files+0 added−208 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

13 files+0 added−208 removed

  • tests:+0 added−18 removed
  • other:+0 added−190 removed

13 files+0 added−208 removed

deleted:examples/using-esm-from-commonjs/jest-javascript/.gitignore-4 removed
1node_modules/23# Save space, do not commit package-lock.json with all the Jest dependencies!4package-lock.json
deleted:examples/using-esm-from-commonjs/jest-javascript/babel.config.js-3 removed
deleted:examples/using-esm-from-commonjs/jest-javascript/index.spec.cjs-9 removed
deleted:examples/using-esm-from-commonjs/jest-javascript/jest.config.js-6 removed
deleted:examples/using-esm-from-commonjs/jest-javascript/package.json-17 removed
deleted:examples/using-esm-from-commonjs/jest-javascript/README.md-40 removed
deleted:examples/using-esm-from-commonjs/jest-typescript/.gitignore-4 removed
1node_modules/23# Save space, do not commit package-lock.json with all the Jest dependencies!4package-lock.json
deleted:examples/using-esm-from-commonjs/jest-typescript/index.spec.cts-9 removed
deleted:examples/using-esm-from-commonjs/jest-typescript/jest.config.js-16 removed
1// List the dependencies that are pure esm and need transformation.2const esmModules = ['commander'].join('|'); // redundant join in case you have others34module.exports = {5 // 1. tell ts-jest to (also) handle .js and .mjs files6 transform: {7 '^.+\\.[cm]?[tj]sx?$': [8 'ts-jest',9 {10 useESM: false, // want CJS for Jest11 },12 ],13 },14 // 2. allow transformation of specific node_modules15 transformIgnorePatterns: [`node_modules/(?!(${esmModules})/)`],16};
deleted:examples/using-esm-from-commonjs/jest-typescript/package.json-18 removed
1{2 "name": "jest-typescript",3 "version": "1.0.0",4 "description": "",5 "scripts": {6 "test": "jest"7 },8 "license": "MIT",9 "type": "commonjs",10 "dependencies": {11 "commander": "^15.0.0-0"12 },13 "devDependencies": {14 "jest": "^30.2.0",15 "ts-jest": "^29.4.6",16 "typescript": "^5.9.3"17 }18}
deleted:examples/using-esm-from-commonjs/jest-typescript/README.md-34 removed
1# Example configuration for Jest 30 running CommonJS from TypeScript23This project shows using `ts-jest` to transform Commander ESM to CommonJS.45Example error message when requiring ESM-only Commander in a Jest test with default configuration:67```8$ npm run --silent test9 FAIL ./index.test.ts10 ● Test suite failed to run1112 Jest encountered an unexpected token1314 Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.1516 [more detail omitted, check output for up-to-date suggestions]17...18 import { Command } from 'commander';19 ^^^^^^2021 SyntaxError: Cannot use import statement outside a module22...23```2425Additional setup:2627- see two tweaks in `jest.config.js` to use `ts-jest` to convert Commander ESM to CommonJS2829Running test:3031```console32npm install33npm test34```
deleted:examples/using-esm-from-commonjs/jest-typescript/tsconfig.json-44 removed
1{2 // Visit https://aka.ms/tsconfig to read more about this file3 "compilerOptions": {4 // File Layout5 // "rootDir": "./src",6 // "outDir": "./dist",78 // Environment Settings9 // See also https://aka.ms/tsconfig/module10 "module": "nodenext",11 "target": "esnext",12 "types": [],13 // For nodejs:14 // "lib": ["esnext"],15 // "types": ["node"],16 // and npm install -D @types/node1718 // Other Outputs19 "sourceMap": true,20 "declaration": true,21 "declarationMap": true,2223 // Stricter Typechecking Options24 "noUncheckedIndexedAccess": true,25 "exactOptionalPropertyTypes": true,2627 // Style Options28 // "noImplicitReturns": true,29 // "noImplicitOverride": true,30 // "noUnusedLocals": true,31 // "noUnusedParameters": true,32 // "noFallthroughCasesInSwitch": true,33 // "noPropertyAccessFromIndexSignature": true,3435 // Recommended Options36 "strict": true,37 "jsx": "react-jsx",38 "verbatimModuleSyntax": false, // we want import to be output as require, not verbatim39 "isolatedModules": true,40 "noUncheckedSideEffectImports": true,41 "moduleDetection": "force",42 "skipLibCheck": true,43 },44}
modified:CHANGELOG.md-4 removed
42 unmodified lines
4344If you have problems using Commander 15 in your environment, one option is stay on Commander 14 for now. Commander 14 will45get security updates until May 2027 and things will hopefully improve for your setup in the meantime.4647To allow `require(esm)` from CommonJS you may be able to make small changes to your current setup. Some48examples for Jest are included in [examples/using-esm-from-commonjs](./examples/using-esm-from-commonjs).49(Commander was using Jest, so we have a special interest.)5047## [14.0.3] (2026-01-31)4849### Added50
1587 unmodified lines