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: refactor test runner run plan tests #57304

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

pmarchini
Copy link
Member

This is a followup refactor related to #56765 (comment) , #56765 (comment)

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test Issues and PRs related to the tests. labels Mar 3, 2025
@pmarchini pmarchini changed the title Test/refactor test runner plan tests test: refactor test runner run plan tests Mar 3, 2025

test('planning should FAIL when wait time expires before plan is met', (t) => {
t.plan(2, { wait: 500 });
setTimeout(() => {
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be unrefed so the event loop isn't forced to stay alive?

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case, unfortunately, forceExit is needed in order to prevent the test from waiting for the setTimeout

const stream = run({
  files: [join(testFixtures, 'plan', 'timeout-expired.mjs')],
  forceExit: true
});

Copy link
Member

Choose a reason for hiding this comment

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

@pmarchini why though? can't we just unref it?

test('planning should FAIL when wait time expires before plan is met', (t) => {
  t.plan(2, { wait: 500 });
  setTimeout(() => {
    t.assert.ok(true);
  }, 50_000_000).unref();
});

Copy link
Member Author

Choose a reason for hiding this comment

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

just to clarify, do you typically expect users to do this, or is it mainly to improve the test? 😁

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 reason why I used forceExit is that it seemed more "generic" to me, but I didn't think about unreferencing the timeout.
So, no problem at all changing the test 😁

Copy link
Member

@atlowChemi atlowChemi Mar 4, 2025

Choose a reason for hiding this comment

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

do you typically expect users to do this

No, I was thinking of the test. IMHO having the timeout unrefed here is more explicit & readable to the flow of the test than having the forceExit flag elsewhere.

If you disagree I am OK with it staying this way 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

nono absolutely, I agree, thanks for your suggestion 😁
I'm pushing now a new commit!

@pmarchini pmarchini marked this pull request as ready for review March 4, 2025 22:22
@pmarchini pmarchini added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 4, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 4, 2025
@nodejs-github-bot
Copy link
Collaborator

Copy link

codecov bot commented Mar 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.22%. Comparing base (8c2df73) to head (97f1057).
Report is 78 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #57304      +/-   ##
==========================================
- Coverage   90.34%   90.22%   -0.13%     
==========================================
  Files         629      630       +1     
  Lines      184403   185166     +763     
  Branches    36040    36226     +186     
==========================================
+ Hits       166607   167064     +457     
- Misses      10919    11114     +195     
- Partials     6877     6988     +111     

see 81 files with indirect coverage changes

@pmarchini pmarchini requested a review from atlowChemi March 5, 2025 15:10
Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

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

LGTM, although relying on setTimeout() behavior in tests always makes me nervous.

test('deeply nested tests', async (t) => {
t.plan(1);

await t.test('level 1', async (t) => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
await t.test('level 1', async (t) => {
t.test('level 1', async (t) => {

Copy link
Member

Choose a reason for hiding this comment

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

see #56664

Copy link
Contributor

Choose a reason for hiding this comment

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

It might be worth keeping the awaits so that the commit can be backported.

await t.test('level 1', async (t) => {
t.plan(1);

await t.test('level 2', (t) => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
await t.test('level 2', (t) => {
t.test('level 2', (t) => {

Copy link
Member Author

Choose a reason for hiding this comment

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

following

It might be worth keeping the awaits so that the commit can be backported.
Do you think we can resolve these nits? 😁


test('parent test', async (t) => {
t.plan(1);
await t.test('child test', (t) => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
await t.test('child test', (t) => {
t.test('child test', (t) => {

Copy link
Member

@MoLow MoLow left a comment

Choose a reason for hiding this comment

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

LGTM. added some nitpics

@pmarchini
Copy link
Member Author

LGTM, although relying on setTimeout() behavior in tests always makes me nervous.

+100 on setTimeout concerns

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants