-
Notifications
You must be signed in to change notification settings - Fork 121
/
index.ts
39 lines (34 loc) · 1.25 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
import jetpack = require("fs-jetpack");
import * as path from "path";
import Mocha from "mocha";
// @ts-ignore
import MochaAllureReporter from "../..";
import { InMemoryAllureWriter, TestResult } from "allure-js-commons";
const testDir = "./test/fixtures/specs";
export function runTests(...specs: string[]): Promise<InMemoryAllureWriter> {
const writer = new InMemoryAllureWriter();
const mocha = new Mocha();
mocha.reporter(MochaAllureReporter, { writer });
assignSpecs(mocha, specs);
return new Promise(resolve => {
mocha.run(() => resolve(writer));
});
}
export function findLabelValue(test: TestResult, labelName: string) {
const label = test.labels.find(label => label.name === labelName);
return label && label.value;
}
export function findParameter(test: TestResult, parameterName: string): any {
return test.parameters.find(parameter => parameter.name === parameterName);
}
function assignSpecs(mocha: Mocha, specs: string[]) {
jetpack
.dir(testDir)
.find({ matching: specs.map(spec => `${spec}.ts`) })
.forEach(file => {
const testPath = path.resolve(testDir, file);
// remove the test from node_modules cache, so it can be executed again
delete require.cache[testPath];
mocha.addFile(testPath);
});
}