Skip to content

Commit 3ee7cbd

Browse files
authored
test(vscode): pin repo packageManager in isolated E2E recovery sandboxes (#147)
1 parent 62403fb commit 3ee7cbd

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎packages/vscode/e2e/lint/runTest.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import os from 'node:os';
3232
import path from 'node:path';
3333

3434
import { downloadAndUnzipVSCode, runTests } from '@vscode/test-electron';
35+
import { writeRepoPackageManager } from '../pnpmInstall';
3536
import { vscodeTestCachePath } from '../vscodeTestCache';
3637

3738
interface TestSuite {
@@ -135,6 +136,8 @@ async function runIsolatedSuite(
135136
path.join(profileRoot, 'node_modules'),
136137
process.platform === 'win32' ? 'junction' : 'dir',
137138
);
139+
} else {
140+
writeRepoPackageManager(profileRoot, extensionDevelopmentPath);
138141
}
139142

140143
await runTests({

‎packages/vscode/e2e/pnpmInstall.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
11
import { execFile as execFileCallback } from 'node:child_process';
2+
import fs from 'node:fs';
3+
import path from 'node:path';
24
import { promisify } from 'node:util';
35

46
const execFile = promisify(execFileCallback);
57

8+
/**
9+
* Writes the repo's `packageManager` pin into a tmpdir sandbox parent so
10+
* Corepack reuses the cached pnpm instead of fetching `pnpm/latest` from npm.
11+
*/
12+
export function writeRepoPackageManager(
13+
sandboxRoot: string,
14+
extensionDevelopmentPath: string,
15+
): void {
16+
const { packageManager } = JSON.parse(
17+
fs.readFileSync(
18+
path.resolve(extensionDevelopmentPath, '../../package.json'),
19+
'utf8',
20+
),
21+
) as { packageManager?: string };
22+
if (packageManager) {
23+
fs.writeFileSync(
24+
path.join(sandboxRoot, 'package.json'),
25+
`${JSON.stringify({ packageManager })}\n`,
26+
);
27+
}
28+
}
29+
630
/**
731
* Runs `pnpm install --frozen-lockfile --ignore-scripts` in `cwd`. pnpm 11
832
* prints install errors (e.g. ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION) to

‎packages/vscode/e2e/rstest/runTest.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
import { tmpdir } from 'node:os';
2929
import path from 'node:path';
3030
import { runTests } from '@vscode/test-electron';
31+
import { writeRepoPackageManager } from '../pnpmInstall';
3132
import { vscodeTestCachePath } from '../vscodeTestCache';
3233

3334
// Repo-relative fixture dirs whose installs this slice needs. workspace-2 has
@@ -134,6 +135,7 @@ async function main() {
134135
recursive: true,
135136
filter: (source) => path.basename(source) !== 'node_modules',
136137
});
138+
writeRepoPackageManager(recoveryRoot, extensionDevelopmentPath);
137139
await runTests({
138140
...launchOptions,
139141
extensionTestsPath: path.resolve(

0 commit comments

Comments
 (0)