Skip to content

Commit

Permalink
Abort test on failure of awaited waitUntil command. (nightwatchjs…
Browse files Browse the repository at this point in the history
…#4161)

This commit solves the issue where `waitUntil` failure was not aborting the test when used with `await` and without chaining.

-------

Co-authored-by: Priyansh Garg <[email protected]>
  • Loading branch information
chikara1608 and garg3133 authored Apr 3, 2024
1 parent b08981d commit e79fcfa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/api/_loaders/_command-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ class BaseCommandLoader extends BaseLoader {
const alwaysAsync = this.module.alwaysAsync || false;
const isTraceable = this.module.isTraceable;
const avoidPrematureParentNodeResolution = !!this.module.avoidPrematureParentNodeResolution;
const rejectNodeOnAbortFailure = !!this.module.rejectNodeOnAbortFailure;

return {redact, alwaysAsync, isTraceable, avoidPrematureParentNodeResolution};
return {redact, alwaysAsync, isTraceable, avoidPrematureParentNodeResolution, rejectNodeOnAbortFailure};
}

validateMethod(parent) {
Expand Down
4 changes: 4 additions & 0 deletions lib/api/protocol/waitUntil.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ module.exports = class WaitUntil extends ProtocolAction {
return true;
}

static get rejectNodeOnAbortFailure() {
return true;
}

//timeMs, retryInterval, message, callback = function(r) {return r}
async command(conditionFn, ...args) {
let callback = function(r) {return r};
Expand Down
8 changes: 5 additions & 3 deletions lib/core/asynctree.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ class AsyncTree extends EventEmitter{
return Boolean(result);
}

shouldRejectNodePromise(err, node = this.currentNode) {
if ((err.isExpect || node.namespace === 'assert') && this.currentNode.isES6Async) {
shouldRejectNodePromise(err, abortOnFailure, node = this.currentNode) {
const rejectNodeOnAbortFailure = node.options?.rejectNodeOnAbortFailure;

if ((err.isExpect || node.namespace === 'assert' || (abortOnFailure && rejectNodeOnAbortFailure)) && this.currentNode.isES6Async) {
return true;
}

Expand Down Expand Up @@ -146,7 +148,7 @@ class AsyncTree extends EventEmitter{
err.stack = err.stack.split('\n').slice(1).join('\n');
}

if (this.shouldRejectNodePromise(err, node)) {
if (this.shouldRejectNodePromise(err, abortOnFailure, node)) {
node.reject(err);
} else {
node.resolve(err);
Expand Down

0 comments on commit e79fcfa

Please sign in to comment.