Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/automation/src/electron.ts
3520 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 { join } from 'path';
7
import * as fs from 'fs';
8
import { copyExtension } from './extensions';
9
import { URI } from 'vscode-uri';
10
import { measureAndLog } from './logger';
11
import type { LaunchOptions } from './code';
12
13
const root = join(__dirname, '..', '..', '..');
14
15
export interface IElectronConfiguration {
16
readonly electronPath: string;
17
readonly args: string[];
18
readonly env?: NodeJS.ProcessEnv;
19
}
20
21
export async function resolveElectronConfiguration(options: LaunchOptions): Promise<IElectronConfiguration> {
22
const { codePath, workspacePath, extensionsPath, userDataDir, remote, logger, logsPath, crashesPath, extraArgs } = options;
23
const env = { ...process.env };
24
25
const args = [
26
workspacePath,
27
'--skip-release-notes',
28
'--skip-welcome',
29
'--disable-telemetry',
30
'--disable-experiments',
31
'--no-cached-data',
32
'--disable-updates',
33
`--crash-reporter-directory=${crashesPath}`,
34
'--disable-workspace-trust',
35
`--logsPath=${logsPath}`
36
];
37
if (options.useInMemorySecretStorage) {
38
args.push('--use-inmemory-secretstorage');
39
}
40
if (userDataDir) {
41
args.push(`--user-data-dir=${userDataDir}`);
42
}
43
if (extensionsPath) {
44
args.push(`--extensions-dir=${extensionsPath}`);
45
}
46
if (options.verbose) {
47
args.push('--verbose');
48
}
49
50
if (remote) {
51
// Replace workspace path with URI
52
args[0] = `--${workspacePath.endsWith('.code-workspace') ? 'file' : 'folder'}-uri=vscode-remote://test+test/${URI.file(workspacePath).path}`;
53
54
if (codePath) {
55
if (!extensionsPath) {
56
throw new Error('Extensions path is required when running against a build at the moment.');
57
}
58
// running against a build: copy the test resolver extension
59
await measureAndLog(() => copyExtension(root, extensionsPath, 'vscode-test-resolver'), 'copyExtension(vscode-test-resolver)', logger);
60
}
61
args.push('--enable-proposed-api=vscode.vscode-test-resolver');
62
if (userDataDir) {
63
const remoteDataDir = `${userDataDir}-server`;
64
fs.mkdirSync(remoteDataDir, { recursive: true });
65
env['TESTRESOLVER_DATA_FOLDER'] = remoteDataDir;
66
}
67
env['TESTRESOLVER_LOGS_FOLDER'] = join(logsPath, 'server');
68
if (options.verbose) {
69
env['TESTRESOLVER_LOG_LEVEL'] = 'trace';
70
}
71
}
72
73
if (!codePath) {
74
args.unshift(root);
75
}
76
77
if (extraArgs) {
78
args.push(...extraArgs);
79
}
80
81
const electronPath = codePath ? getBuildElectronPath(codePath) : getDevElectronPath();
82
83
return {
84
env,
85
args,
86
electronPath
87
};
88
}
89
90
export function getDevElectronPath(): string {
91
const buildPath = join(root, '.build');
92
const product = require(join(root, 'product.json'));
93
94
switch (process.platform) {
95
case 'darwin':
96
return join(buildPath, 'electron', `${product.nameLong}.app`, 'Contents', 'MacOS', 'Electron');
97
case 'linux':
98
return join(buildPath, 'electron', `${product.applicationName}`);
99
case 'win32':
100
return join(buildPath, 'electron', `${product.nameShort}.exe`);
101
default:
102
throw new Error('Unsupported platform.');
103
}
104
}
105
106
export function getBuildElectronPath(root: string): string {
107
switch (process.platform) {
108
case 'darwin':
109
return join(root, 'Contents', 'MacOS', 'Electron');
110
case 'linux': {
111
const product = require(join(root, 'resources', 'app', 'product.json'));
112
return join(root, product.applicationName);
113
}
114
case 'win32': {
115
const product = require(join(root, 'resources', 'app', 'product.json'));
116
return join(root, `${product.nameShort}.exe`);
117
}
118
default:
119
throw new Error('Unsupported platform.');
120
}
121
}
122
123
export function getBuildVersion(root: string): string {
124
switch (process.platform) {
125
case 'darwin':
126
return require(join(root, 'Contents', 'Resources', 'app', 'package.json')).version;
127
default:
128
return require(join(root, 'resources', 'app', 'package.json')).version;
129
}
130
}
131
132