Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix queue resolution without error in between test case. #4323

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/core/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ class CommandQueue extends EventEmitter {

err = err || this.tree.returnError;

// only used in hooks
this.emit('queue:finished', err);

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

// when using third-party test runners (e.g. cucumber), sometimes the previous error is not cleared
this.tree.returnError = null;

Expand All @@ -145,7 +151,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
Loading