Path: blob/main/src/vs/platform/environment/test/node/userDataPath.test.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import assert from 'assert';6import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';7import { OPTIONS, parseArgs } from '../../node/argv.js';8import { getUserDataPath } from '../../node/userDataPath.js';9import product from '../../../product/common/product.js';1011suite('User data path', () => {1213test('getUserDataPath - default', () => {14const path = getUserDataPath(parseArgs(process.argv, OPTIONS), product.nameShort);15assert.ok(path.length > 0);16});1718test('getUserDataPath - portable mode', () => {19const origPortable = process.env['VSCODE_PORTABLE'];20try {21const portableDir = 'portable-dir';22process.env['VSCODE_PORTABLE'] = portableDir;2324const path = getUserDataPath(parseArgs(process.argv, OPTIONS), product.nameShort);25assert.ok(path.includes(portableDir));26} finally {27if (typeof origPortable === 'string') {28process.env['VSCODE_PORTABLE'] = origPortable;29} else {30delete process.env['VSCODE_PORTABLE'];31}32}33});3435test('getUserDataPath - --user-data-dir', () => {36const cliUserDataDir = 'cli-data-dir';37const args = parseArgs(process.argv, OPTIONS);38args['user-data-dir'] = cliUserDataDir;3940const path = getUserDataPath(args, product.nameShort);41assert.ok(path.includes(cliUserDataDir));42});4344test('getUserDataPath - VSCODE_APPDATA', () => {45const origAppData = process.env['VSCODE_APPDATA'];46try {47const appDataDir = 'appdata-dir';48process.env['VSCODE_APPDATA'] = appDataDir;4950const path = getUserDataPath(parseArgs(process.argv, OPTIONS), product.nameShort);51assert.ok(path.includes(appDataDir));52} finally {53if (typeof origAppData === 'string') {54process.env['VSCODE_APPDATA'] = origAppData;55} else {56delete process.env['VSCODE_APPDATA'];57}58}59});6061ensureNoDisposablesAreLeakedInTestSuite();62});636465