Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/environment/test/node/userDataPath.test.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';
8
import { OPTIONS, parseArgs } from '../../node/argv.js';
9
import { getUserDataPath } from '../../node/userDataPath.js';
10
import product from '../../../product/common/product.js';
11
12
suite('User data path', () => {
13
14
test('getUserDataPath - default', () => {
15
const path = getUserDataPath(parseArgs(process.argv, OPTIONS), product.nameShort);
16
assert.ok(path.length > 0);
17
});
18
19
test('getUserDataPath - portable mode', () => {
20
const origPortable = process.env['VSCODE_PORTABLE'];
21
try {
22
const portableDir = 'portable-dir';
23
process.env['VSCODE_PORTABLE'] = portableDir;
24
25
const path = getUserDataPath(parseArgs(process.argv, OPTIONS), product.nameShort);
26
assert.ok(path.includes(portableDir));
27
} finally {
28
if (typeof origPortable === 'string') {
29
process.env['VSCODE_PORTABLE'] = origPortable;
30
} else {
31
delete process.env['VSCODE_PORTABLE'];
32
}
33
}
34
});
35
36
test('getUserDataPath - --user-data-dir', () => {
37
const cliUserDataDir = 'cli-data-dir';
38
const args = parseArgs(process.argv, OPTIONS);
39
args['user-data-dir'] = cliUserDataDir;
40
41
const path = getUserDataPath(args, product.nameShort);
42
assert.ok(path.includes(cliUserDataDir));
43
});
44
45
test('getUserDataPath - VSCODE_APPDATA', () => {
46
const origAppData = process.env['VSCODE_APPDATA'];
47
try {
48
const appDataDir = 'appdata-dir';
49
process.env['VSCODE_APPDATA'] = appDataDir;
50
51
const path = getUserDataPath(parseArgs(process.argv, OPTIONS), product.nameShort);
52
assert.ok(path.includes(appDataDir));
53
} finally {
54
if (typeof origAppData === 'string') {
55
process.env['VSCODE_APPDATA'] = origAppData;
56
} else {
57
delete process.env['VSCODE_APPDATA'];
58
}
59
}
60
});
61
62
ensureNoDisposablesAreLeakedInTestSuite();
63
});
64
65