-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
/
createLazyTestEnv.js
64 lines (61 loc) · 1.43 KB
/
createLazyTestEnv.js
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
module.exports = (env, globalTimeout = 2000, nameSuffix = "") => {
const suite = env.describe(
nameSuffix ? `exported tests ${nameSuffix}` : "exported tests",
() => {
// this must have a child to be handled correctly
env.it("should run the exported tests", () => {});
}
);
let numberOfTests = 0;
const beforeAndAfterFns = () => {
let currentSuite = suite;
let afters = [];
let befores = [];
while (currentSuite) {
befores = befores.concat(currentSuite.beforeFns);
afters = afters.concat(currentSuite.afterFns);
currentSuite = currentSuite.parentSuite;
}
return {
befores: befores.reverse(),
afters: afters
};
};
return {
setDefaultTimeout(time) {
globalTimeout = time;
},
getNumberOfTests() {
return numberOfTests;
},
it(title, fn, timeout = globalTimeout) {
numberOfTests++;
let spec;
if(fn) {
spec = env.fit(title, fn, timeout);
} else {
spec = env.fit(title, () => {});
spec.pend("Skipped");
}
suite.addChild(spec);
spec.disabled = false;
spec.getSpecName = () => {
return `${suite.getFullName()} ${spec.description}`;
};
spec.beforeAndAfterFns = beforeAndAfterFns;
spec.result.fullName = spec.getFullName();
},
beforeEach(fn, timeout = globalTimeout) {
suite.beforeEach({
fn,
timeout: () => timeout
});
},
afterEach(fn, timeout = globalTimeout) {
suite.afterEach({
fn,
timeout: () => timeout
});
}
};
};