Skip to content

Commit

Permalink
Fix queue resolution without error in between test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 committed Dec 5, 2024
1 parent 329d797 commit 61189c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/core/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ class CommandQueue extends EventEmitter {

err = err || this.tree.returnError;

if (!err && this.tree.currentResult instanceof Promise && !this.tree.currentResult.settled) {
return this;
}

this.emit('queue:finished', err);
// when using third-party test runners (e.g. cucumber), sometimes the previous error is not cleared
this.tree.returnError = null;
Expand All @@ -145,7 +149,9 @@ class CommandQueue extends EventEmitter {
return Promise.resolve();
}

run() {
run(result) {
this.tree.currentResult = result;

if (this.tree.started) {
return this;
}
Expand Down
9 changes: 6 additions & 3 deletions lib/testsuite/runnable.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ class Runnable {
}

setDoneCallback(cb) {
let originalResolve = this.deffered.resolveFn;
let originalReject = this.deffered.rejectFn;
const originalResolve = this.deffered.resolveFn;
const originalReject = this.deffered.rejectFn;
this.deffered.resolveFn = function() {};
this.deffered.rejectFn = function() {};

Expand Down Expand Up @@ -134,13 +134,15 @@ class Runnable {
const deferredFn = () => {
result
.then(res_ => {
result.settled = true;
if (this.queueInProgress()) {
return;
}

this.deffered.resolveFn(res_);
})
.catch(err => {
result.settled = true;
this.deffered.rejectFn(err);
});
};
Expand All @@ -152,14 +154,15 @@ class Runnable {
// without .catch() here, we can get an unhandledRejection
result
.catch(err => {
result.settled = true;
this.deffered.rejectFn(err);
});
} else {
deferredFn();
}
}

this.queue.run().then(err => {
this.queue.run(result).then(err => {
if (err) {
return this.deffered.rejectFn(err);
}
Expand Down

0 comments on commit 61189c6

Please sign in to comment.