forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
74 lines (62 loc) · 2.25 KB
/
Copy pathindex.ts
File metadata and controls
74 lines (62 loc) · 2.25 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
// This file is providing the test runner to use when running extension tests.
import * as path from 'path';
import * as vscode from 'vscode';
import glob = require('glob');
import Mocha = require('mocha');
import { mockWebviewEnvironment } from './mocks/mockWebviewEnvironment';
// Linux: prevent a weird NPE when mocha on Linux requires the window size from the TTY
// Since we are not running in a tty environment, we just implement the method statically.
// This is copied verbatim from the upstream, default Mocha test runner:
// https://github.com/microsoft/vscode-extension-vscode/blob/master/lib/testrunner.ts
const tty = require('tty') as any;
if (!tty.getWindowSize) {
tty.getWindowSize = function () { return [80, 75]; };
}
function addTests(mocha: Mocha, root: string): Promise<void> {
return new Promise((resolve, reject) => {
glob('**/**.test.js', { cwd: root }, (error, files) => {
if (error) {
return reject(error);
}
for (const testFile of files) {
mocha.addFile(path.join(root, testFile));
}
resolve();
});
});
}
async function runAllExtensionTests(testsRoot: string): Promise<number> {
// Ensure the dev-mode extension is activated
const { name, publisher } = require('../../package.json') as { name: string, publisher: string };
const extensionId = `${publisher}.${name}`;
await vscode.extensions.getExtension(extensionId)!.activate();
mockWebviewEnvironment.install(global);
const mocha = new Mocha({
ui: 'bdd',
useColors: true,
});
mocha.addFile(path.resolve(testsRoot, 'globalHooks.js'));
await addTests(mocha, testsRoot);
await addTests(mocha, path.resolve(testsRoot, '../../webviews/test'));
if (process.env.TEST_JUNIT_XML_PATH) {
mocha.reporter('mocha-multi-reporters', {
reporterEnabled: 'mocha-junit-reporter, spec',
mochaJunitReporterReporterOptions: {
mochaFile: process.env.TEST_JUNIT_XML_PATH,
suiteTitleSeparatedBy: ' / ',
outputs: true,
}
});
}
return new Promise((resolve) => mocha.run(resolve));
}
export function run(testsRoot: string, clb: (error: Error | null, failures?: number) => void): void {
require('source-map-support').install();
runAllExtensionTests(testsRoot).then(
failures => clb(null, failures),
error => {
console.log(error.stack);
clb(error);
},
);
}