Commit 2726e51
committed
fix(test): Stabilize Jest ESM configuration for CI
Resolves persistent `ReferenceError: exports is not defined` errors
encountered during unit tests (`unit-test (20.x)` job) in the GitHub
Actions CI environment. These errors occurred specifically when
importing `cli-testing-library` in the global Jest setup file
(`test/jest-setup.ts`), despite tests passing locally with the same
Node.js version (v20.19.0).
After iterative testing, the following Jest configuration combination
was identified as necessary to ensure consistent ESM handling and test
success in both local and CI environments:
- Set preset to `ts-jest/presets/default-esm` for stricter ESM rules.
- Configured `transformIgnorePatterns` to ensure Jest transforms specific ESM dependencies (`cli-testing-library`, `@clack`, `cleye`) within `node_modules`.
- Expanded the `transform` pattern (`^.+\\.(ts|tsx|js|jsx|mjs)$`) to explicitly cover various script types handled by `ts-jest`.
- Included explicit `tsconfig` overrides (`module: 'ESNext'`, `target: 'ES2022'`) within the `ts-jest` transform options to resolve potential environment discrepancies.
- Retained `moduleNameMapper` for `.js` imports for reliable module resolution.
- Ensured `cli-testing-library` imports remain in the global setup (`test/jest-setup.ts`).
- Removed test cache clearing from the `test:unit` script in `package.json`.
This configuration now passes reliably across environments.1 parent da2742e commit 2726e51
3 files changed
+22
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | | - | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
23 | 29 | | |
24 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
25 | 38 | | |
26 | 39 | | |
27 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | 1 | | |
| 2 | + | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
0 commit comments