Files
ever-gauzy/jest.patterns.js
Ruslan KonviserandClaude Opus 5.5 a85bcea69e fix: what the AI review of the upgrade found
- Seed cleanup (Greptile): rimraf 3 took the failure callback for its options
  argument and called the success one either way, so a failed cleanup of
  generated files never stopped a seed. With rimraf 6's promise, the seed
  service's `.finally()` left the rejection unhandled (Node ends the process on
  that) and cleanAssets / the feature and report cleaners rejected. All four
  log the failure and go on; seed-cleanup.spec.ts fails on the old code.
- Tray icons: jimp 1's brightness() multiplies each channel by its argument,
  so 0.22's brightness(-0.1) made every *_gray tray icon black. 0.9 is the
  same 90%.
- CI static checks: the jest-config type check installed TypeScript 5.9.3,
  which refuses ignoreDeprecations "6.0" (TS5103); it now uses 6.0.3. Under
  6.0.3 the check found the 75 Node jest configs restating
  `require(jest.patterns).nodeTransformIgnorePatterns` (typed unknown by the
  check's shim). jest.preset.js already picks that variant, so they inherit it
  again, as core's config says they should.
- engines: the 114 workspace manifests still said node >=22; now >=26, as the
  root does.
- The desktop Dockerfiles (no workflow uses them): the Windows ones copy
  vendor/ before the install, the Linux ones build on node:26-trixie-slim
  (libayatana-appindicator3-1 replaces libappindicator3-1, gone after bullseye).
- jest-angular-projects.js declares the arrays it pushes to with `let`
  (repository convention, Greptile).
- jest.patterns.js: `yarn ng test <node project>` runs without the ES-module
  flag (the ng script already sets NODE_OPTIONS, and Nx never overrides a set
  variable with a .env value); documented, with `yarn nx test` as the way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 17:01:39 +02:00

41 lines
3.0 KiB
JavaScript

/**
* The `transformIgnorePatterns` every Jest project of the workspace uses, in one place (see `jest.preset.js` for why
* each package is listed). Two variants, because the two kinds of project load ES modules differently:
*
* - `transformIgnorePatterns` (the preset's default) also transforms every `.mjs` file. The Angular projects need
* that: Angular and its ecosystem ship `fesm2022/*.mjs` bundles that jest-preset-angular compiles (and links).
*
* - `nodeTransformIgnorePatterns` leaves every ES module alone. The Node projects run with
* `NODE_OPTIONS=--experimental-vm-modules` (the workspace `.env.test`; CI sets it for them), so Jest loads an ES
* module natively, also one a CommonJS spec requires (`require(esm)`, Node >= 24.9). NestJS 12 ships as ES modules,
* which is why the flag is on. Under it Jest decides how to load a file by the file alone — a `.mjs`, or a `.js` in
* a `"type": "module"` package, is evaluated as an ES module — so a transform to CommonJS breaks such a package
* instead of fixing it: Nest found no named exports in the `.mjs` of `uid` ("The requested module 'uid' does not
* provide an export named 'uid'"), and uuid 14 and jose 6, both ESM-only, threw "exports is not defined" in the
* auth, pricing, catalog and inventory suites. Only a package that puts ES module syntax in files Node takes for
* CommonJS still needs the transform: `@datorama/akita` (plain `.js`, no `"type"`), and `@nestjs/axios` (see
* `jest.preset.js`). Every other package on the list above loads natively.
*
* The Angular projects run WITHOUT that flag (each one's `.env.test` clears `NODE_OPTIONS`; CI runs them separately):
* under it, Jest would evaluate every `.mjs` bundle as an ES module after jest-preset-angular compiled it to CommonJS
* ("module is not defined" in `setup-env/zone`, and every Angular suite failed to load).
*
* No project sets the key: `jest.preset.js` picks the variant, and a project's own `transformIgnorePatterns` would
* REPLACE the preset's.
*
* Nx loads a `.env.test` value only when the variable is not set yet, so a `NODE_OPTIONS` that is already set wins
* over both files: `yarn ng test <node project>` (the `ng` script sets a heap size) runs WITHOUT the flag and the
* suites fail to load NestJS. Run them with `yarn nx test <project>`, or add the flag to your own NODE_OPTIONS.
*/
const ESM_PACKAGES = String.raw`(?:.*/)?(sanitize-html|htmlparser2|domelementtype|domhandler|domutils|dom-serializer|entities|nanoid|parse-srcset|uuid|camelcase|@faker-js|@nestjs/axios|@datorama|@ngneat|lodash-es|d3-[a-z-]+|internmap|jose|marked|hash-it)/`;
/** The packages a Node project still transforms: ES module syntax in files Node loads as CommonJS (see above). */
const NODE_TRANSFORMED_PACKAGES = String.raw`(?:.*/)?(@datorama|@nestjs/axios)/`;
module.exports = {
ESM_PACKAGES,
NODE_TRANSFORMED_PACKAGES,
transformIgnorePatterns: [String.raw`node_modules/(?!.*\.mjs$|${ESM_PACKAGES})`],
nodeTransformIgnorePatterns: [String.raw`node_modules/(?!${NODE_TRANSFORMED_PACKAGES})`]
};