-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathindex.ts
56 lines (48 loc) · 2.02 KB
/
index.ts
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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as globby from 'globby';
import * as Mocha from 'mocha';
import * as path from 'path';
import { envUtils } from '../extension.bundle';
export async function run(): Promise<void> {
const options: Mocha.MochaOptions = {
ui: 'tdd',
color: true,
reporter: 'mocha-multi-reporters',
reporterOptions: {
reporterEnabled: 'spec, mocha-junit-reporter',
mochaJunitReporterReporterOptions: {
mochaFile: path.resolve(__dirname, '..', '..', 'test-results.xml')
}
}
};
addEnvVarsToMochaOptions(options);
console.log(`Mocha options: ${JSON.stringify(options, undefined, 2)}`);
const mocha = new Mocha(options);
let files: string[];
if (envUtils.isEnvironmentVariableSet(process.env.AZFUNC_UPDATE_BACKUP_TEMPLATES)) {
files = ['updateBackupTemplates.js'];
} else {
files = await globby('**/**.test.js', { cwd: __dirname })
}
files.forEach(f => mocha.addFile(path.resolve(__dirname, f)));
const failures = await new Promise<number>(resolve => mocha.run(resolve));
if (failures > 0) {
throw new Error(`${failures} tests failed.`);
}
}
function addEnvVarsToMochaOptions(options: Mocha.MochaOptions): void {
for (const envVar of Object.keys(process.env)) {
const match: RegExpMatchArray | null = envVar.match(/^mocha_(.+)/i);
if (match) {
const [, option] = match;
let value: string | number = process.env[envVar] || '';
if (typeof value === 'string' && !isNaN(parseInt(value))) {
value = parseInt(value);
}
(<any>options)[option] = value;
}
}
}