Skip to content

Commit df64acc

Browse files
committed
run tests in a separate user data dir by default
Fixes microsoft/vscode#137678
1 parent 4bdccd4 commit df64acc

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### 2.0.0 | 2021-12-14
4+
5+
- Run tests using a separate instance of VS Code by default. This can be disabled by setting `reuseMachineInstall: true`.
6+
37
### 1.6.2 | 2021-07-15
48

59
- Add `--disable-workspace-trust` flag when running tests by default

lib/download.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,16 @@ function spawnDecompressorChild(command: string, args: ReadonlyArray<string>, in
170170
})
171171
}
172172

173+
export const defaultCachePath = path.resolve(extensionRoot, '.vscode-test');
174+
173175
/**
174176
* Download and unzip a copy of VS Code.
175177
* @returns Promise of `vscodeExecutablePath`.
176178
*/
177179
export async function download(options?: Partial<DownloadOptions>): Promise<string> {
178180
let version = options?.version;
179-
let platform = options?.platform ?? systemDefaultPlatform;
180-
let cachePath = options?.cachePath ?? path.resolve(extensionRoot, '.vscode-test');
181+
const platform = options?.platform ?? systemDefaultPlatform;
182+
const cachePath = options?.cachePath ?? defaultCachePath;
181183

182184
if (version) {
183185
if (version === 'stable') {
@@ -258,4 +260,4 @@ export async function download(options?: Partial<DownloadOptions>): Promise<stri
258260
*/
259261
export async function downloadAndUnzipVSCode(version?: DownloadVersion, platform: DownloadPlatform = systemDefaultPlatform): Promise<string> {
260262
return await download({ version, platform });
261-
}
263+
}

lib/runTest.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as cp from 'child_process';
7-
import { downloadAndUnzipVSCode, DownloadVersion, DownloadPlatform } from './download';
7+
import * as path from 'path';
8+
import { downloadAndUnzipVSCode, DownloadVersion, DownloadPlatform, defaultCachePath } from './download';
89

910
export interface TestOptions {
1011
/**
@@ -37,6 +38,15 @@ export interface TestOptions {
3738
*/
3839
platform?: DownloadPlatform;
3940

41+
/**
42+
* Whether VS Code should be launched using default settings and extensions
43+
* installed on this machine. If `false`, then separate directories will be
44+
* used inside the `.vscode-test` folder within the project.
45+
*
46+
* Defaults to `false`.
47+
*/
48+
reuseMachineInstall?: boolean;
49+
4050
/**
4151
* Absolute path to the extension root. Passed to `--extensionDevelopmentPath`.
4252
* Must include a `package.json` Extension Manifest.
@@ -91,6 +101,8 @@ export async function runTests(options: TestOptions): Promise<number> {
91101
let args = [
92102
// https://github.com/microsoft/vscode/issues/84238
93103
'--no-sandbox',
104+
'--skip-welcome',
105+
'--skip-release-notes',
94106
'--disable-workspace-trust',
95107
'--extensionDevelopmentPath=' + options.extensionDevelopmentPath,
96108
'--extensionTestsPath=' + options.extensionTestsPath
@@ -100,9 +112,23 @@ export async function runTests(options: TestOptions): Promise<number> {
100112
args = options.launchArgs.concat(args);
101113
}
102114

115+
if (!options.reuseMachineInstall) {
116+
if (!hasArg('extensions-dir', args)) {
117+
args.push(`--extensions-dir=${path.join(defaultCachePath, 'extensions')}`)
118+
}
119+
120+
if (!hasArg('user-data-dir', args)) {
121+
args.push(`--user-data-dir=${path.join(defaultCachePath, 'user-data')}`)
122+
}
123+
}
124+
103125
return innerRunTests(options.vscodeExecutablePath, args, options.extensionTestsEnv);
104126
}
105127

128+
function hasArg(argName: string, argList: readonly string[]) {
129+
return argList.some(a => a === `--${argName}` || a.startsWith(`--${argName}=`));
130+
}
131+
106132
async function innerRunTests(
107133
executable: string,
108134
args: string[],

0 commit comments

Comments
 (0)