Commit a97bd37
authored
chore(testing): stub plugin imports in devkit specs to avoid cross-project reads (#35374)
## Current Behavior
Three devkit specs exercise helpers that do `await
import('@nx/<plugin>/plugin')` at runtime (`findPluginForConfigFile`
when a registration has `include`/`exclude`, and
`addE2eCiTargetDefaults` unconditionally for every e2e plugin
registration). Combined with the custom jest resolver in
`scripts/patched-jest-resolver.js` — which maps `@nx/<pkg>` subpaths to
workspace source — the dynamic imports pull the real plugin source plus
everything transitively re-exported by `@nx/js` and `@nx/vite` into the
jest process.
Concretely, `devkit:test` ends up reading ~49 files across
`packages/js/src/**` and `packages/vite/**` that are not declared (and
cannot be declared without creating a project-graph cycle since `@nx/js`
and `@nx/vite` both depend on `@nx/devkit`). The sandbox flags all 49 as
undeclared-read violations.
## Expected Behavior
None of these specs aim to validate the real plugin's behavior. They
exercise devkit's own logic — how a registration is matched to a config
file, how target defaults are written into `nx.json`, and how e2e web
server info is resolved from a registered plugin — treating
`@nx/<plugin>/plugin` as an opaque reference. The plugin's
`createNodesV2[0]` glob is used by the devkit helpers only as a pattern
pre-filter against conventional config filenames (`vite.config.ts`,
`cypress.config.ts`); what the real plugin does beyond that is outside
the scope of these tests.
Stubbing the three plugin modules with `jest.mock(..., { virtual: true
})` that exposes just the real plugin's glob pattern:
- Preserves the minimal contract the devkit helpers rely on (the module
resolves, and its glob matches the conventional config filenames used in
the tests).
- Drops the incidental loading of the real plugin and its entire
transitive graph — removing all 49 reported sandbox violations.
- Eliminates an accidental coupling to the pinned `@nx/cypress` version
currently pulled from `node_modules`, which also transitively requires
`@nx/js` workspace source via the custom resolver.
Changes are test-only; no production code is touched.1 parent 77f8e1e commit a97bd37
3 files changed
Lines changed: 38 additions & 0 deletions
File tree
- packages/devkit/src
- generators
- utils
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
1 | 16 | | |
2 | 17 | | |
3 | 18 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
1 | 12 | | |
2 | 13 | | |
3 | 14 | | |
| |||
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
1 | 13 | | |
2 | 14 | | |
3 | 15 | | |
| |||
0 commit comments