Skip to content

Commit c0f09d3

Browse files
committed
test(auto-install): make npm/pnpm bare tests robust on Windows by using local input and scoped cleanup\n\n- Copy shared input into the fixture cwd so node-resolve finds installed deps\n- Run del cleanup in the fixture cwd and avoid deleting repo files\n- Keep env tweaks scoped per-test; no behavior change for npm/pnpm/yarn tests\n\nFixes CI Windows Node 20 failures introduced by 218488a.
1 parent 4e8942a commit c0f09d3

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

packages/auto-install/test/npm-bare.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import nodeResolve from '@rollup/plugin-node-resolve';
1212
const DIR = fileURLToPath(new URL('.', import.meta.url));
1313
const cwd = path.join(DIR, 'fixtures/npm-bare');
1414
const file = path.join(cwd, 'output/bundle.js');
15-
const input = path.join(cwd, '../input.js');
15+
// Use a local input inside the cwd so Node resolution finds packages installed
16+
// by the test (e.g., on Windows where upward-only resolution won't see
17+
// `npm-bare/node_modules` from `fixtures/input.js`).
18+
const input = path.join(cwd, 'input.local.js');
1619
const pkgFile = path.join(cwd, 'package.json');
1720

1821
// Helper to temporarily disable slow npm features during the test
@@ -48,6 +51,8 @@ it.runIf(RUN_ON_THIS_NODE)(
4851
async () => {
4952
const restoreEnv = stubNpmQuietEnv();
5053
const prevCwd = process.cwd();
54+
// Create a local copy of the shared input so resolution starts from `cwd`.
55+
fs.copyFileSync(path.join(cwd, '../input.js'), input);
5156
process.chdir(cwd);
5257
try {
5358
const { default: autoInstall } = await import('~package');
@@ -65,12 +70,17 @@ it.runIf(RUN_ON_THIS_NODE)(
6570
}
6671
} finally {
6772
process.chdir(prevCwd);
73+
try {
74+
fs.unlinkSync(input);
75+
} catch {
76+
/* ignore cleanup errors */
77+
}
6878
restoreEnv();
6979
}
7080
},
7181
60000
7282
);
7383

7484
afterAll(async () => {
75-
await del(['node_modules', 'package.json', 'package-lock.json']);
85+
await del(['node_modules', 'package.json', 'package-lock.json'], { cwd });
7686
});

packages/auto-install/test/pnpm-bare.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ import nodeResolve from '@rollup/plugin-node-resolve';
1212
const DIR = fileURLToPath(new URL('.', import.meta.url));
1313
const cwd = path.join(DIR, 'fixtures/pnpm-bare');
1414
const file = path.join(cwd, 'output/bundle.js');
15-
const input = path.join(cwd, '../input.js');
15+
// Use a local input inside the cwd so Node resolution finds packages installed
16+
// by the test (e.g., on Windows where upward-only resolution won't see
17+
// `pnpm-bare/node_modules` from `fixtures/input.js`).
18+
const input = path.join(cwd, 'input.local.js');
1619

1720
const PREV_CWD = process.cwd();
1821
const [NODE_MAJOR, NODE_MINOR] = process.versions.node.split('.').map(Number);
1922
const RUN_ON_THIS_NODE = NODE_MAJOR > 20 || (NODE_MAJOR === 20 && NODE_MINOR >= 19);
2023

2124
it.runIf(RUN_ON_THIS_NODE)('pnpm, bare', async () => {
25+
// Create a local copy of the shared input so resolution starts from `cwd`.
26+
fs.copyFileSync(path.join(cwd, '../input.js'), input);
2227
process.chdir(cwd);
2328
const { default: autoInstall } = await import('~package');
2429
const bundle = await rollup({
@@ -36,6 +41,12 @@ it.runIf(RUN_ON_THIS_NODE)('pnpm, bare', async () => {
3641
});
3742

3843
afterAll(async () => {
39-
await del(['node_modules', 'package.json', 'pnpm-lock.yaml']);
44+
// Ensure cleanup runs against the fixture directory, not the repo root
45+
await del(['node_modules', 'package.json', 'pnpm-lock.yaml'], { cwd });
46+
try {
47+
fs.unlinkSync(input);
48+
} catch {
49+
/* ignore cleanup errors */
50+
}
4051
process.chdir(PREV_CWD);
4152
});

0 commit comments

Comments
 (0)