-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
test_runner: remove Promise return values from test(), suite(), and t.test() #56664
base: main
Are you sure you want to change the base?
Conversation
Review requested:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #56664 +/- ##
=======================================
Coverage 89.20% 89.20%
=======================================
Files 662 662
Lines 191899 191925 +26
Branches 36940 36942 +2
=======================================
+ Hits 171184 171215 +31
- Misses 13546 13550 +4
+ Partials 7169 7160 -9
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from the nits: I think this is a great devEx enhancement! LGTM
doc/api/test.md
Outdated
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no change here regarding how a test is recognized as finished. The test is either a synchronous function, a function that returns a Promise, or a function that takes a callback. The test is finished after awaiting the return value or the callback is invoked. That part is already documented.
For example, how would it understand this one completes?
Unrelated to this change - I believe this first snippet has a bug, assuming someCallback()
is asynchronous? If it is asynchronous, there should be a Promise or a done
callback involved. The second code snippet looks correct, but a Promise could have been used as well.
Does this PR make the done callback required for all subtests?
No.
This commit updates the test runner to automatically wait for subtests to finish. This makes the experience more consistent with suites and removes the need to await anything.
This commit updates the test() and suite() APIs to no longer return a Promise. Fixes: nodejs#51292
This commit updates the TestContext.prototype.test() API to no longer return a Promise. Fixes: nodejs#51292
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a test for ensuring dynamically added test cases finish before the suite closes? This await behaviour was previously required in order to orchestrate that in userland, so I'm just concerned this could break that.
Yes, dynamically added tests still work. The breaking change (aside from the return value change) is that you can no longer await subtests for control flow purposes. For users of |
I'm confused. The docs still say that a test can return a promise: Lines 32 to 43 in 2b34ffe
Are you saying that we can no longer await those returned promises in order to keep the parent test alive? |
const r = test('foo', () => {
return new Promise((resolve) => {
resolve();
});
}); This test returns a Promise (the Promise that is resolved()). When that Promise settles, the test is considered finished. That has not changed.
Previously, if you were writing a test inside of another test, you needed to The only scenario where this is breaking: test('foo', async (t) => {
await t.test('subtest 1');
// It is no longer guaranteed that the subtest on the previous line has
// finished by the time this line executes. But the test runner still ensures
// the order that subtest 1 and subtest 2 are executed in.
await t.test('subtest 2');
}); |
Thank you for the clarification. I was unaware of |
So, is |
As far as I know, that was already the case. The difference was that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving the breaking change.
test_runner: automatically wait for subtests to finish
This commit updates the test runner to automatically wait for
subtests to finish. This makes the experience more consistent
with suites and removes the need to await anything.
test_runner: remove promises returned by test()
This commit updates the test() and suite() APIs to no longer
return a Promise.
Fixes: #51292
test_runner: remove promises returned by t.test()
This commit updates the TestContext.prototype.test() API to no
longer return a Promise.
Fixes: #51292