-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathindex.ts
More file actions
59 lines (49 loc) · 2.03 KB
/
index.ts
File metadata and controls
59 lines (49 loc) · 2.03 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// This file is providing the test runner to use when running extension tests.
import * as path from 'path';
import * as vscode from 'vscode';
import Mocha from 'mocha';
import { mockWebviewEnvironment } from './mocks/mockWebviewEnvironment';
import { EXTENSION_ID } from '../constants';
async function runAllExtensionTests(testsRoot: string, clb: (error: Error | null, failures?: number) => void): Promise<any> {
// Ensure the dev-mode extension is activated
await vscode.extensions.getExtension(EXTENSION_ID)!.activate();
mockWebviewEnvironment.install(global);
const mocha = new Mocha({
ui: 'bdd',
color: true
});
// Load globalHooks if it exists
try {
mocha.addFile(path.resolve(testsRoot, 'globalHooks.js'));
} catch (e) {
// globalHooks might not exist in webpack bundle, ignore
}
// Import all test files using webpack's require.context
try {
// Load tests from src/test directory only
// Webview tests are compiled separately with the webview configuration
const importAll = (r: __WebpackModuleApi.RequireContext) => r.keys().forEach(r);
importAll(require.context('./', true, /\.test$/));
} catch (e) {
console.log('Error loading tests:', e);
}
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 mocha.run(failures => clb(null, failures));
}
export function run(testsRoot: string, clb: (error: Error | null, failures?: number) => void): void {
require('source-map-support').install();
runAllExtensionTests(testsRoot, clb);
}