Skip to content

fix: repair broken Jest test suite (16/18 suites failing)#410

Open
shaunpatterson wants to merge 2 commits into
dgraph-io:mainfrom
shaunpatterson:sp/fix-jest-esm-transform
Open

fix: repair broken Jest test suite (16/18 suites failing)#410
shaunpatterson wants to merge 2 commits into
dgraph-io:mainfrom
shaunpatterson:sp/fix-jest-esm-transform

Conversation

@shaunpatterson

Copy link
Copy Markdown
Contributor

Problem

npm test currently fails 16 of 18 suites in a clean checkout of main. None of the failures are real test regressions — they are all test-infrastructure breakages:

  1. ESM-only deps are never transpiled. The babel config lives in package.json (file-relative, like .babelrc), so it is not applied to files inside node_modules even if transformIgnorePatterns lets them through. react-leaflet 4 is ESM-only → SyntaxError: Unexpected token 'export' in every suite that transitively imports the app.
  2. Jest 26 can't resolve node:-prefixed core modules required by newer transitive deps (cheerio → parse5/undici).
  3. enzyme 3 requires cheerio/lib/utils, which no longer exists in cheerio 1.x final (the lockfile resolves enzyme's ^1.0.0-rc.3 range to 1.1.2).
  4. jsdom 16 lacks TextEncoder/TextDecoder, web streams, Blob and MessageChannel globals that undici needs at import time.
  5. e2e suites run in the default npm test but require puppeteer (optional dep) plus a live Dgraph cluster at localhost:8080, so 14 suites always fail locally and in CI-less environments.

Fix

  • config/jest/babelTransform.js: dedicated babel-jest transformer with explicit presets, so allowed-through node_modules files actually get compiled; transformIgnorePatterns now whitelists react-leaflet/@react-leaflet.
  • config/jest/nodeShims/*: one-line shims + a moduleNameMapper rule mapping node:<mod> → the bare core module.
  • moduleNameMapper entry pointing cheerio/lib/utils at its new location (dist/commonjs/utils.js); enzyme is test-only so a Jest mapping is sufficient.
  • config/jest/testPolyfills.js added to setupFiles (kept separate from config/polyfills.js, which is also a webpack entry and must not require node core modules).
  • e2e suites split out: npm test runs unit tests, npm run test:e2e runs src/e2etests (unchanged behavior otherwise).

Result

before after
npm test 16/18 suites fail 4/4 suites pass (13 tests)

No production code or dependency changes; npm run build verified unaffected.

🤖 Generated with Claude Code

Every component test suite has been failing to run. Four independent
breakages, all in test infrastructure - no production code changes:

- ESM-only packages were never transpiled: the babel config lives in
  package.json (file-relative, like .babelrc), so it is not applied to
  files inside node_modules even when transformIgnorePatterns allows
  them through. Added config/jest/babelTransform.js (explicit presets)
  and allowed react-leaflet/@react-leaflet through the transform.
- Jest 26 cannot resolve node:-prefixed core modules required by newer
  transitive deps (cheerio -> parse5/undici). Added shim files under
  config/jest/nodeShims plus a moduleNameMapper rule.
- enzyme 3 requires cheerio/lib/utils, which no longer exists in
  cheerio 1.x final (the lockfile resolves enzyme's ^1.0.0-rc.3 range
  to 1.1.2). Mapped to its new location (dist/commonjs/utils.js).
- jsdom 16 lacks TextEncoder/TextDecoder, web streams, Blob and
  MessageChannel globals that undici needs. Added a Jest-only
  setupFiles polyfill (kept out of config/polyfills.js, which is also
  a webpack entry).

Also split e2e tests out of the default run: they need puppeteer and a
live Dgraph cluster, so 14 suites always failed in a plain checkout.
'npm test' now runs unit tests only; 'npm run test:e2e' runs the rest.

Result: npm test goes from 16/18 suites failing to 4/4 passing
(13 tests). Production build verified unaffected.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant