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

test_runner: empty pending tests queue post running #44059

Merged
Merged
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
1 change: 1 addition & 0 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ class Test extends AsyncResource {

// The test has run, so recursively cancel any outstanding subtests and
// mark this test as failed if any subtests failed.
this.pendingSubtests = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably use defineProperty?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The object is never exposed to user land.
See how it it originally defined in the constructor

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AsyncResource instances inherit from Object.prototype, so by adding a setter to Object.prototype for “pendingSubtests” would allow someone to intercept this part of the class.

Copy link
Contributor

@aduh95 aduh95 Jul 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's overriding a property that was already defined in the constructor, so a follow up PR could make the constructor itself use defineProperty (or the setOwnProperty helper from #44007), this line is fine though IIUC.

Copy link
Member Author

@MoLow MoLow Jul 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

il do this in a follow-up pr after #44007 will land

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative would be to use a class field in AsyncResource (and/or here)

for (let i = 0; i < this.subtests.length; i++) {
const subtest = this.subtests[i];

Expand Down
2 changes: 1 addition & 1 deletion test/message/test_runner_unresolved_promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ const test = require('node:test');

test('pass');
test('never resolving promise', () => new Promise(() => {}));
test('fail');
test('fail', () => console.log('this should not appear'));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this message would have been printed prior to this PR

2 changes: 1 addition & 1 deletion test/message/test_runner_unresolved_promise.out
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ not ok 2 - never resolving promise
# Subtest: fail
not ok 3 - fail
---
duration_ms: *
duration_ms: 0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to make sure this test never starts

failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
Expand Down