forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstandardTest.ts
More file actions
107 lines (99 loc) · 4.3 KB
/
standardTest.ts
File metadata and controls
107 lines (99 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { spawnSync } from 'child_process';
import * as fs from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
import { downloadAndUnzipVSCode, resolveCliPathFromVSCodeExecutablePath, runTests } from '@vscode/test-electron';
import { JUPYTER_EXTENSION_ID, PYLANCE_EXTENSION_ID } from '../client/common/constants';
import { EXTENSION_ROOT_DIR_FOR_TESTS } from './constants';
import { getChannel } from './utils/vscode';
import { TestOptions } from '@vscode/test-electron/out/runTest';
// If running smoke tests, we don't have access to this.
if (process.env.TEST_FILES_SUFFIX !== 'smoke.test') {
const logger = require('./testLogger');
logger.initializeLogger();
}
function requiresJupyterExtensionToBeInstalled() {
return process.env.INSTALL_JUPYTER_EXTENSION === 'true';
}
function requiresPylanceExtensionToBeInstalled() {
return process.env.INSTALL_PYLANCE_EXTENSION === 'true';
}
process.env.IS_CI_SERVER_TEST_DEBUGGER = '';
process.env.VSC_PYTHON_CI_TEST = '1';
const workspacePath = process.env.CODE_TESTS_WORKSPACE
? process.env.CODE_TESTS_WORKSPACE
: path.join(__dirname, '..', '..', 'src', 'test');
const extensionDevelopmentPath = process.env.CODE_EXTENSIONS_PATH
? process.env.CODE_EXTENSIONS_PATH
: EXTENSION_ROOT_DIR_FOR_TESTS;
/**
* Smoke tests & tests running in VSCode require Jupyter extension to be installed.
*/
async function installJupyterExtension(vscodeExecutablePath: string) {
if (!requiresJupyterExtensionToBeInstalled()) {
console.info('Jupyter Extension not required');
return;
}
console.info('Installing Jupyter Extension');
const cliPath = resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath, os.platform());
// For now install Jupyter from the marketplace
spawnSync(cliPath, ['--install-extension', JUPYTER_EXTENSION_ID], {
encoding: 'utf-8',
stdio: 'inherit',
});
}
async function installPylanceExtension(vscodeExecutablePath: string) {
if (!requiresPylanceExtensionToBeInstalled()) {
console.info('Pylance Extension not required');
return;
}
console.info('Installing Pylance Extension');
const cliPath = resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath, os.platform());
// For now install pylance from the marketplace
spawnSync(cliPath, ['--install-extension', PYLANCE_EXTENSION_ID], {
encoding: 'utf-8',
stdio: 'inherit',
});
// Make sure to enable it by writing to our workspace path settings
await fs.ensureDir(path.join(workspacePath, '.vscode'));
const settingsPath = path.join(workspacePath, '.vscode', 'settings.json');
if (await fs.pathExists(settingsPath)) {
let settings = JSON.parse(await fs.readFile(settingsPath, 'utf-8'));
settings = { ...settings, 'python.languageServer': 'Pylance' };
await fs.writeFile(settingsPath, JSON.stringify(settings));
} else {
const settings = `{ "python.languageServer": "Pylance" }`;
await fs.writeFile(settingsPath, settings);
}
}
async function start() {
console.log('*'.repeat(100));
console.log('Start Standard tests');
const channel = getChannel();
console.log(`Using ${channel} build of VS Code.`);
const vscodeExecutablePath = await downloadAndUnzipVSCode(channel);
const baseLaunchArgs =
requiresJupyterExtensionToBeInstalled() || requiresPylanceExtensionToBeInstalled()
? []
: ['--disable-extensions'];
await installJupyterExtension(vscodeExecutablePath);
await installPylanceExtension(vscodeExecutablePath);
console.log('VS Code executable', vscodeExecutablePath);
const launchArgs = baseLaunchArgs
.concat([workspacePath])
.concat(channel === 'insiders' ? ['--enable-proposed-api'] : [])
.concat(['--timeout', '5000']);
console.log(`Starting vscode ${channel} with args ${launchArgs.join(' ')}`);
const options: TestOptions = {
extensionDevelopmentPath: extensionDevelopmentPath,
extensionTestsPath: path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'out', 'test'),
launchArgs,
version: channel,
extensionTestsEnv: { ...process.env, UITEST_DISABLE_INSIDERS: '1' },
};
await runTests(options);
}
start().catch((ex) => {
console.error('End Standard tests (with errors)', ex);
process.exit(1);
});