-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathindex.ts
92 lines (80 loc) · 2.17 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
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
import * as path from "path";
import Mocha from "mocha";
import { glob } from "glob";
import { MochaOptions } from "vscode-extension-tester";
import NYC from "nyc";
function setupCoverage() {
const nyc = new NYC({
cwd: path.join(__dirname, "..", "..", ".."),
reporter: ["text", "html", "lcov"],
all: true,
silent: false,
instrument: true,
hookRequire: true,
hookRunInContext: true,
hookRunInThisContext: true,
include: ["out/client/src/**/*.js", "out/server/src/**/*.js"],
reportDir: "out/coverage/e2e",
tempDir: "out/.nyc_output",
});
nyc.reset();
nyc.wrap();
return nyc;
}
export async function run(): Promise<void> {
// Setup NYC for code coverage
const nyc = process.env.COVERAGE ? setupCoverage() : null;
// if (nyc) { // For debugging
// console.log("Glob verification", await nyc.exclude.glob(nyc.cwd));
// }
const mochaOptions: MochaOptions = {
color: true,
ui: "bdd",
timeout: 50000,
reporter: "mochawesome",
reporterOptions: {
reportFilename: "e2e_test_report",
reportDir: "out/e2eTestReport",
reportTitle: "vscode-ansible e2e test",
reportPageTitle: "vscode-ansible e2e test report",
cdn: true,
charts: true,
},
};
if (process.env.MOCHA_GREP) {
mochaOptions.grep = process.env.MOCHA_GREP;
}
if (process.env.MOCHA_INVERT) {
mochaOptions.invert = !!process.env.MOCHA_INVERT;
}
// Create the mocha test
const mocha = new Mocha(mochaOptions);
const testsRoot = path.resolve(__dirname, "..");
const files = await glob("**/**.test.js", { cwd: testsRoot });
// Add e2e test cases (excluding unit test cases)
files.forEach((file) => {
if (!file.includes("/units/")) {
mocha.addFile(path.resolve(testsRoot, file));
}
});
try {
await new Promise<void>((c, e) => {
// Run the mocha test
mocha.run((failures: number) => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
});
} catch (err) {
console.error(err);
throw err;
} finally {
if (nyc) {
nyc.writeCoverageFile();
await nyc.report();
}
}
}