Skip to content

Commit 59e7f44

Browse files
jaysooFrozenPandaz
authored andcommitted
fix(js): set --ws=false when running npm config for jest e2e (#29887)
When we run inferred Jest tasks with workspaces enabled, it'll result in an error like this: ``` npm ERR! A complete log of this run can be found in: /Users/jack/.npm/_logs/2025-02-05T13_41_51_079Z-debug-0.log Error: Command failed: npm config set //localhost:4873/:_authToken "secretVerdaccioToken" npm ERR! code ENOWORKSPACES npm ERR! This command does not support workspaces. ``` This is because the cwd is the project root (e.g. `packages/mypkg-e2e`), and `npm config set` cannot be run on packages inside the workspaces. By passing `--ws=false`, it'll only be run in the workspace root and won't error. ## Current Behavior Jest e2e tests inferred from `@nx/jest/plugin` fail when starting a local registry. ## Expected Behavior Jest e2e tests should work even if they are inferred (or have cwd other than workspace root). ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # (cherry picked from commit 0944e34)
1 parent d972ba2 commit 59e7f44

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

e2e/plugin/src/nx-plugin-ts-solution.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ describe('Nx Plugin (TS solution)', () => {
7777
expect(runCLI(`e2e @proj/${plugin}-e2e`)).toContain(
7878
`Successfully ran target e2e for project @proj/${plugin}-e2e`
7979
);
80+
81+
// Check that inferred targets also work
82+
updateJson('nx.json', (json) => {
83+
json.plugins.push({
84+
plugin: '@nx/jest/plugin',
85+
include: ['packages/*-e2e/**/*'],
86+
options: {
87+
targetName: 'e2e',
88+
ciTargetName: 'e2e-ci',
89+
},
90+
});
91+
return json;
92+
});
93+
updateJson(`packages/${plugin}-e2e/package.json`, (json) => {
94+
delete json.targets;
95+
return json;
96+
});
97+
expect(() => runCLI(`e2e @proj/${plugin}-e2e`)).not.toThrow();
8098
}, 90000);
8199

82100
it('should be able to infer projects and targets', async () => {

packages/js/src/plugins/jest/start-local-registry.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function startLocalRegistry({
5454

5555
process.env.npm_config_registry = registry;
5656
execSync(
57-
`npm config set //${listenAddress}:${port}/:_authToken "secretVerdaccioToken"`,
57+
`npm config set //${listenAddress}:${port}/:_authToken "secretVerdaccioToken" --ws=false`,
5858
{
5959
windowsHide: false,
6060
}
@@ -70,9 +70,12 @@ export function startLocalRegistry({
7070

7171
resolve(() => {
7272
childProcess.kill();
73-
execSync(`npm config delete //${listenAddress}:${port}/:_authToken`, {
74-
windowsHide: false,
75-
});
73+
execSync(
74+
`npm config delete //${listenAddress}:${port}/:_authToken --ws=false`,
75+
{
76+
windowsHide: false,
77+
}
78+
);
7679
});
7780
childProcess?.stdout?.off('data', listener);
7881
}

0 commit comments

Comments
 (0)