Skip to content

fix(core): make unit tests pass locally regardless of invoking package manager#35994

Open
FrozenPandaz wants to merge 3 commits into
masterfrom
fix/deterministic-unit-test-env
Open

fix(core): make unit tests pass locally regardless of invoking package manager#35994
FrozenPandaz wants to merge 3 commits into
masterfrom
fix/deterministic-unit-test-env

Conversation

@FrozenPandaz

Copy link
Copy Markdown
Contributor

Current Behavior

Two classes of unit tests fail when run locally but pass on CI:

  1. Running tests via pnpm nx test <project> injects npm_config_user_agent=pnpm/... into the jest processes. detectPackageManager falls back to that variable when the test tree has no lockfile (the common case for in-memory trees), so package-manager-dependent generator tests behave differently than their snapshots expect. CI agents start via npx nx-cloud, so the same tests see an npm user agent and pass.

  2. readNxJsonExtends resolves nx.json extends with require.resolve(extendsPath, { paths: [tree.root] }). For in-memory test trees the root is /virtual, which has no node_modules, and jest 30 throws after exhausting the given paths instead of falling back. Any test that reads an nx.json with extends (e.g. @nx/eslint:lint-project preset tests) fails with a cold jest cache.

Expected Behavior

  • scripts/unit-test-setup.js removes npm_config_user_agent so package manager detection in tests is deterministic and matches CI. Tests that exercise a specific package manager already force it explicitly (lockfile/pnpm-workspace.yaml in the tree, or setting the variable themselves).
  • readNxJsonExtends falls back to resolving from the running nx package when workspace-rooted resolution fails.

pnpm nx test eslint passes fully locally with these changes (20/20 suites).

Related Issue(s)

@netlify

netlify Bot commented Jun 12, 2026

Copy link
Copy Markdown

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit f62aa24
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/6a2c93fb4a84490008f19b05
😎 Deploy Preview https://deploy-preview-35994--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Jun 12, 2026

Copy link
Copy Markdown

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit f62aa24
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/6a2c93fb3841b2000860b983
😎 Deploy Preview https://deploy-preview-35994--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud

nx-cloud Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit f62aa24

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 31m 17s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 57s View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 18s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 5s View ↗

☁️ Nx Cloud last updated this comment at 2026-06-12 23:55:00 UTC

@FrozenPandaz FrozenPandaz marked this pull request as ready for review June 12, 2026 22:35
@FrozenPandaz FrozenPandaz requested a review from a team as a code owner June 12, 2026 22:35
@FrozenPandaz FrozenPandaz requested a review from lourw June 12, 2026 22:35
…rministic package manager detection [Self-Healing CI Rerun]

@nx-cloud nx-cloud Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nx Cloud has identified a flaky task in your failed CI:

🔂 Since the failure was identified as flaky, we triggered a CI rerun by adding an empty commit to this branch.

Nx Cloud View detailed reasoning in Nx Cloud ↗


🎓 Learn more about Self-Healing CI on nx.dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant