Skip to content

Commit f3ca4f6

Browse files
committed
Added handling for multiple '--user-data-dir' to enable Spectron smoke testing in microsoft#25291.
1 parent e4c6a96 commit f3ca4f6

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/main.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,15 @@ function mkdir(dir) {
170170
});
171171
}
172172

173+
// Because Spectron doesn't allow us to pass a custom user-data-dir,
174+
// Code receives two of them. Let's just take the first one.
175+
var userDataDir = args['user-data-dir'];
176+
if (userDataDir) {
177+
userDataDir = typeof userDataDir === 'string' ? userDataDir : userDataDir[0];
178+
}
179+
173180
// Set userData path before app 'ready' event and call to process.chdir
174-
var userData = path.resolve(args['user-data-dir'] || paths.getDefaultUserDataPath(process.platform));
181+
var userData = path.resolve(userDataDir || paths.getDefaultUserDataPath(process.platform));
175182
app.setPath('userData', userData);
176183

177184
// Update cwd based on environment and platform

src/vs/platform/environment/node/argv.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,14 @@ export function parseCLIProcessArgv(processArgv: string[]): ParsedArgs {
105105
* Use this to parse code arguments such as `--verbose --wait`
106106
*/
107107
export function parseArgs(args: string[]): ParsedArgs {
108-
return minimist(args, options) as ParsedArgs;
108+
const result = minimist(args, options) as ParsedArgs;
109+
110+
// Because Spectron doesn't allow us to pass a custom user-data-dir,
111+
// Code receives two of them. Let's just take the first one.
112+
const userDataDir: string | string[] = result['user-data-dir'];
113+
result['user-data-dir'] = typeof userDataDir === 'string' ? userDataDir : userDataDir[0];
114+
115+
return result;
109116
}
110117

111118
export const optionsHelp: { [name: string]: string; } = {

src/vs/platform/environment/test/node/environmentService.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,11 @@ suite('EnvironmentService', () => {
4141
assert.equal(parse(['--user-data-dir', './dir'], { cwd: () => '/foo', env: { 'VSCODE_CWD': '/bar' } }), path.resolve('/bar/dir'),
4242
'should use VSCODE_CWD as the cwd when --user-data-dir is specified');
4343
});
44+
45+
test('userDataPath should always take the first one', () => {
46+
const parse = (a, b: { cwd: () => string, env: { [key: string]: string } }) => parseUserDataDir(parseArgs(a), <any>b);
47+
48+
assert.equal(parse(['--user-data-dir', './dir1', '--user-data-dir', './dir2'], { cwd: () => '/foo', env: {} }), path.resolve('/foo/dir1'),
49+
'should pick first --user-data-dir (dir1)');
50+
});
4451
});

0 commit comments

Comments
 (0)