-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.js
54 lines (49 loc) · 1.56 KB
/
hooks.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
const testControllerHolder = require("./testControllerHolder");
const Runner = require("./runner");
const debug = require("debug")("pickle-cafe:hooks");
module.exports = {
/* Wait for TestCafé to boot up and return the TestCafé controller */
before(data) {
debug("before hook - start runner");
global.testControllerHolder = testControllerHolder;
this.runner = new Runner();
this.runner.createTestCafeScript(data.pickle.name);
this.runner.run();
debug("return promise that waits for t to be stored in world")
return this.waitForTestController.then(function (t) {
debug("runner started");
return t;
});
},
/* Resolve the TestCafé controller promise, this ends the test for TestCafé */
after() {
return new Promise(resolve => {
debug("after hook - stop runner");
// Does resolving t here cause an issue if we want to debug?
testControllerHolder.free();
let intervalId = null;
let timeoutId = null;
let runner = this.runner;
function waitForTestCafe() {
intervalId = setInterval(checkLastResponse, 500);
timeoutId = setTimeout(close, 5000)
}
function checkLastResponse() {
if (
typeof t === "undefined" ||
t.testRun.lastDriverStatusResponse === "test-done-confirmation"
) {
close()
}
}
function close() {
debug("close runner");
clearTimeout(timeoutId)
clearInterval(intervalId);
runner.close();
resolve();
}
waitForTestCafe();
});
}
};