forked from nightwatchjs/nightwatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
38 lines (32 loc) · 1.16 KB
/
utils.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
var Nightwatch = require('./nightwatch.js');
module.exports = {
/**
* Monkey-patch run queue run() callbacks to capture errors handled
* in the queue after they are sent off to the nightwatch instance.
*
* @param {function} testCallback The callback used by the test to
* capture the error object
*/
catchQueueError: function (testCallback) {
var queue = Nightwatch.client().queue;
// queue is a singleton, not re-instancing with new nightwatch
// instances. In order to re-patch it if patched previously, we
// restore the original run method from the patch if it exists
// (which may happen if a patched run never gets called with err)
if (queue.run.origRun) {
queue.run = queue.run.origRun;
}
function queueRunnerPatched (origCallback) {
origCallback = origCallback || function noop () {};
origRun.call(queue, function(err) {
origCallback(err);
if (err) {
queue.run = origRun; // once, since errors are fatal to queue execution
testCallback(err);
}
});
}
var origRun = queueRunnerPatched.origRun = queue.run;
queue.run = queueRunnerPatched;
}
};