Repository navigation
Expand file tree
/
Copy pathrunTests.ts
More file actions
89 lines (80 loc) · 2.51 KB
/
Copy pathrunTests.ts
File metadata and controls
89 lines (80 loc) · 2.51 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as path from 'path';
import * as fs from 'fs';
import * as os from 'os';
import find from 'find-process';
import { runTests } from '@vscode/test-electron';
function rimraf(location: string) {
const stat = fs.lstatSync(location);
if (stat) {
if (stat.isDirectory() && !stat.isSymbolicLink()) {
for (const dir of fs.readdirSync(location)) {
rimraf(path.join(location, dir));
}
fs.rmdirSync(location);
}
else {
fs.unlinkSync(location);
}
}
}
async function go() {
try {
const extensionDevelopmentPath = path.resolve(__dirname, '..');
const extensionTestsPath = __dirname;
const testDir = path.join(os.tmpdir(), Date.now().toString());
fs.mkdirSync(testDir, { recursive: true });
const userDataDir = path.join(testDir, 'userData');
fs.mkdirSync(userDataDir);
const extensionDir = path.join(testDir, 'extensions');
fs.mkdirSync(extensionDir);
const workspaceFolder = path.join(testDir, 'workspace');
fs.mkdirSync(workspaceFolder);
// Under Linux we quite often run the tests using Xvfb.
// In case we have no display set and Xvfb is running use
// the Xvfb display port as a DISPLAY setting
let extensionTestsEnv: NodeJS.ProcessEnv | undefined = undefined;
if (process.platform === 'linux' && !process.env['DISPLAY']) {
let display: string | undefined;
const processes = await find('name', '/usr/bin/Xvfb');
for (const item of processes) {
if (item.name !== 'Xvfb') {
continue;
}
if (item.cmd !== undefined && item.cmd.length > 0) {
display = item.cmd.split(' ')[1];
}
}
if (display !== undefined) {
extensionTestsEnv = { 'DISPLAY': display };
}
}
/**
* Basic usage
*/
await runTests({
version: 'insiders',
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [
'--user-data-dir', userDataDir,
'--extensions-dir', extensionDir,
'--enable-proposed-api', 'ms-vscode.test-extension',
workspaceFolder
],
extensionTestsEnv
});
rimraf(testDir);
} catch (err) {
console.error('Failed to run tests', err);
process.exitCode = 1;
}
}
process.on('uncaughtException', (error: any) => {
console.error(error);
});
go().catch(console.error);