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

Abstain tree from resolving in between test case. #4325

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
4 changes: 4 additions & 0 deletions lib/core/asynctree.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ class AsyncTree extends EventEmitter{
}

async done(err = null) {
if (this.currentResult instanceof Promise && !this.currentResult.settled) {
return err;
}

this.emit('asynctree:finished', this);
this.empty();
this.createRootNode();
Expand Down
3 changes: 2 additions & 1 deletion lib/core/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ class CommandQueue extends EventEmitter {
return Promise.resolve();
}

run() {
run(result) {
this.tree.currentResult = result;
if (this.tree.started) {
return this;
}
Expand Down
14 changes: 12 additions & 2 deletions lib/testsuite/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,12 @@ class Context extends EventEmitter {
args[0] = client.api;
}

return this.testsuite[fnName].apply(context, args);
const result = this.testsuite[fnName].apply(context, args);
if (this.currentRunnable) {
this.currentRunnable.currentTestCaseResult = result;
}

return result;
}

/**
Expand All @@ -541,7 +546,12 @@ class Context extends EventEmitter {
const fnAsync = Utils.makeFnAsync(expectedArgs, this.testsuite[fnName], context);
const args = this.getHookFnArgs(done, api, expectedArgs);

return fnAsync.apply(context, args);
const result = fnAsync.apply(context, args);
if (this.currentRunnable) {
this.currentRunnable.currentTestCaseResult = result;
}

return result;
}

////////////////////////////////////////////////////////////////
Expand Down
17 changes: 14 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 @@ -159,7 +159,18 @@ class Runnable {
}
}

this.queue.run().then(err => {
if (this.currentTestCaseResult instanceof Promise) {
this.currentTestCaseResult
.catch(() => {
// to avoid unhandledRejections
})
.finally(() => {
this.currentTestCaseResult.settled = true;
this.queue.scheduleTraverse();
});
}

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