Skip to content

Revert https://github.com/nodejs/node/pull/56664 #58282

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

Closed
wants to merge 4 commits into from

Conversation

romainmenke
Copy link
Contributor

@romainmenke romainmenke commented May 11, 2025

Being able to await sub tests and orchestrate the order of sub tests and other async functions was no longer possible after #56664

I think this was an obvious mistake.

As far as I understand from #51292 the original issue was that sometimes people get linter nags.

No one actually sufficiently argued that the previous behavior was either wrong or not a useful capability.

I suggest the changes are reverted to restore the previous capabilities.
Being able to await sub tests was a really useful feature.

The linter concerns should be secondary to the capabilities of node:test

Fixes: #58227

@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_runner Issues and PRs related to the test runner subsystem. labels May 11, 2025
@pmarchini
Copy link
Member

Hey @romainmenke , thanks for your contribution!
As a first-time contributor, I suggest you take a look at https://github.com/nodejs/core-validate-commit.

Regarding the content of the PR: I think that, as the behaviour has already been implemented, it would be reasonable to try to make this behaviour configurable via a flag.
What do you think?

@romainmenke
Copy link
Contributor Author

Regarding the content of the PR: I think that, as the behaviour has already been implemented, it would be reasonable to try to make this behaviour configurable via a flag.
What do you think?

I think it is also reasonable to consider a straight up revert :)
The previous behavior has been around for a lot longer and many people depend on it.
It also offers more capabilities.

As I said in the pull request message, I don't think the change was sufficiently argued for.
Reverting to the previous state and re-opening the original issue might reveal a better way forwards.


As a first-time contributor, I suggest you take a look at https://github.com/nodejs/core-validate-commit.

Happy to look at this, but unsure how to proceed.
Do you mean that I should not have commit messages in the default git revert style?
And that I should alter each message and do a force push?

@pmarchini
Copy link
Member

pmarchini commented May 11, 2025

Happy to look at this, but unsure how to proceed.
Do you mean that I should not have commit messages in the default git revert style?

Sorry, I only just noticed that the original PR landed without a squash commit!
The PR should be fine as is 😁

I think it is also reasonable to consider a straight up revert :)

Personally I agree, IMHO we already have suite-test/describe-it that covers that use case.
On second thought, I still think that the introduced behaviour provides a more intuitive devEx, and that an optional configuration could be added to cover these use cases.

I'd like to collect some feedback from @MoLow, @cjihrig, @jakecastelli, and @atlowChemi too!

@aduh95
Copy link
Contributor

aduh95 commented May 11, 2025

Could you give an example of something that no longer works with the new behavior in #51292, with a link to this PR? That should give everyone who participated in that issue a notification so they can participate in this discussion

@romainmenke
Copy link
Contributor Author

romainmenke commented May 11, 2025

See: #51292 (comment)

Copy link

codecov bot commented May 11, 2025

Codecov Report

Attention: Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.

Project coverage is 90.21%. Comparing base (770be2c) to head (afe2fea).
Report is 314 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/test_runner/harness.js 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #58282      +/-   ##
==========================================
+ Coverage   90.18%   90.21%   +0.03%     
==========================================
  Files         631      633       +2     
  Lines      186689   186793     +104     
  Branches    36663    36672       +9     
==========================================
+ Hits       168359   168519     +160     
+ Misses      11128    11045      -83     
- Partials     7202     7229      +27     
Files with missing lines Coverage Δ
lib/internal/test_runner/test.js 97.11% <100.00%> (-0.03%) ⬇️
lib/internal/test_runner/harness.js 93.13% <85.71%> (-0.22%) ⬇️

... and 41 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pmarchini
Copy link
Member

I think we should avoid reverting this feature and instead explore an idea that aligns with the current direction: the addition of a step method similar to what Deno provides.
Correct me if I’m wrong, but from your perspective the issue doesn’t seem to be about the return type itself (or how promises are handled), but rather about a lost capability, specifically the ability to have asynchronous intermediate steps executed in a controlled way between tests.

Here’s an example, based on what you shared in the other issue, of what it could look like using steps:

import { test } from 'node:test';
import assert from 'node:assert';

test('outer', async (t1) => {
	let a = 1;
	let b = 1;

	// Run a first sub test
	t1.test('inner 1', async (t2) => {
		await new Promise((resolve) => setTimeout(resolve, 1000));
		assert.equal(a, b);

		t2.after(async () => {
			await new Promise((resolve) => {
				b = 2;
				resolve();
			});
		});
	});

	// Do some async workload in between sub tests
	t1.step('async workload', async () => new Promise((resolve) => {
		b = 2;
		resolve();
	}));

	// Run a second sub test
	t1.test('inner 2', async () => {
		// Run some extra asserts
		assert.equal(b, 2);
	});
});

Something like this could potentially address the issue while avoiding the reintroduction of the discrepancy between suite/test and t.test.

@romainmenke
Copy link
Contributor Author

romainmenke commented May 12, 2025

I think we should avoid reverting this feature and instead explore an idea that aligns with the current direction: the addition of a step method similar to what Deno provides.

Such new API doesn't really help when we still support a wide range of node versions.
In the long term it might, but it doesn't resolve the short term disruption.

I also honestly do not understand how this change got through in the first place.
I don't understand how anyone favored more callbacks over async/await.
Being able to await async workloads is a better DX than callback hell, it is why we have async/await in the first place.

Before the change made in #56664 it was possible to intuitively and organically add sub tests in between existing code. Or to add some non-test code in between sub tests

After #56664 you have to be very careful that in a given test you either have only sub tests or only non-sub test code. You can no longer interleave these without race conditions.

This is clearly bad, right?
Needing to invent new API that is somewhat equivalent to a sub test is just making it worse, not better imho.

I really liked that node:test and node --test foo.mjs had the core principle that every test is just a JavaScript program and that there weren't any gotcha's. It's just JavaScript code as any other JavaScript code. After #56664 I think this is no longer true. You have to carefully keep within the bounds of the "framework" or your tests won't work as expected.

@mcollina mcollina added the tsc-agenda Issues and PRs to discuss during the meetings of the TSC. label May 12, 2025
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina
Copy link
Member

I concur on a quick revert.

@mcollina
Copy link
Member

@romainmenke can you please amend the other tests that are failing?

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label May 12, 2025
@aduh95 aduh95 removed the request-ci Add this label to start a Jenkins CI on a PR. label May 12, 2025
@aduh95
Copy link
Contributor

aduh95 commented May 12, 2025

Tests are failing on GHA, I don't think it makes sense to run Jenkins CI now

@pmarchini
Copy link
Member

As far as I can tell, it seems that #57672 is the origin of the failing tests (cc @jakecastelli).
@romainmenke, I saw that you updated the test in this commit 0c3e8dc, but it requires a snapshot regeneration as well.

You can do it via NODE_REGENERATE_SNAPSHOTS=1 out/Release/node --expose-internals test/parallel/test-runner-output.mjs.

Unfortunately, I just tried and it seems that the behavior introduced by #57672 is broken after the revert.

marco-ippolito
marco-ippolito previously approved these changes May 12, 2025
Copy link
Member

@marco-ippolito marco-ippolito left a comment

Choose a reason for hiding this comment

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

I agree the previous behavior was more sane

@pmarchini
Copy link
Member

If nobody precedes me, I'll take a look at the failing tests ASAP.

@marco-ippolito marco-ippolito dismissed their stale review May 14, 2025 14:49

After thinking about it I changed my mind, the use case provided is very uncommon and not worth reverting. Maybe we should provide another setting/api that returns a promise

@pmarchini
Copy link
Member

Hey @romainmenke, if you want, you can cherry-pick my latest commit from #58320.

After this commit, I think everything is in place for a potential revert.

IMHO, reverting is still not the right choice, and finding an alternative way to provide this capability would be much better from a DevEx/consistency perspective.

I won't accept this PR for that reason. I provided support to avoid blocking progress in case a decision is made to revert.

I've seen that we have a tsc-agenda set, so let's see!

@nodejs-github-bot
Copy link
Collaborator

@alcuadrado
Copy link

alcuadrado commented Jun 19, 2025

Reverting feels like optimizing for the edge case instead of the most common case. I'm not a contributor, so I don't know how much my opinion matters, but not being able to lint with no-floating-promises in tests is a huge drawback.

@alcuadrado
Copy link

Paraphrasing, @mcollina, it feels a bit like this:

image

@LiviaMedeiros
Copy link
Member

@nodejs/tsc given that this was on the tsc-agenda Issues and PRs to discuss during the meetings of the TSC. for several meetings and no objections were raised, is there any reason to keep this PR in its current state?

The consensus seems to be that there's slight chance of partial revert to be breaking, I suggest to simply merge this right away as-is. After that,

@LiviaMedeiros LiviaMedeiros added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. labels Jun 23, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 23, 2025
@nodejs-github-bot
Copy link
Collaborator

Landed in af66574...04cb572

nodejs-github-bot pushed a commit that referenced this pull request Jun 23, 2025
This reverts commit aa3523e.

PR-URL: #58282
Fixes: #58227
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
nodejs-github-bot pushed a commit that referenced this pull request Jun 23, 2025
This reverts commit 9671826.

PR-URL: #58282
Fixes: #58227
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
nodejs-github-bot pushed a commit that referenced this pull request Jun 23, 2025
This reverts commit 1a2eb15.

PR-URL: #58282
Fixes: #58227
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
nodejs-github-bot pushed a commit that referenced this pull request Jun 23, 2025
PR-URL: #58282
Fixes: #58227
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
@LiviaMedeiros
Copy link
Member

@romainmenke thanks for the contribution!

Opened #58800 to re-introduce aa3523e.

@romainmenke
Copy link
Contributor Author

Thank you everyone for the help and thoughtful approach to this change 🙇

RafaelGSS pushed a commit that referenced this pull request Jun 23, 2025
This reverts commit aa3523e.

PR-URL: #58282
Fixes: #58227
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
RafaelGSS pushed a commit that referenced this pull request Jun 23, 2025
This reverts commit 9671826.

PR-URL: #58282
Fixes: #58227
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
RafaelGSS pushed a commit that referenced this pull request Jun 23, 2025
This reverts commit 1a2eb15.

PR-URL: #58282
Fixes: #58227
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
RafaelGSS pushed a commit that referenced this pull request Jun 23, 2025
PR-URL: #58282
Fixes: #58227
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
@LiviaMedeiros LiviaMedeiros added the notable-change PRs with changes that should be highlighted in changelogs. label Jun 23, 2025
Copy link
Contributor

The notable-change PRs with changes that should be highlighted in changelogs. label has been added by @LiviaMedeiros.

Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. Otherwise, the commit will be placed in the Other Notable Changes section.

@LiviaMedeiros
Copy link
Member

Retroactively adding notable-change PRs with changes that should be highlighted in changelogs. , we probably should reflect in the changelog that subtests can/should be awaited again.

nodejs-github-bot added a commit that referenced this pull request Jun 24, 2025
Notable changes:

doc:
  * add islandryu to collaborators (Shima Ryuhei) #58714
fs:
  * (SEMVER-MINOR) allow correct handling of burst in fs-events with AsyncIterator (Philipp Dunkel) #58490
module:
  * (SEMVER-MINOR) remove experimental warning from type stripping (Marco Ippolito) #58643
test:
  * fix test-timeout-flag after revert of auto subtest wait (Pietro Marchini) #58282
test_runner:
  * Revert "test_runner: remove promises returned by t.test() (Romain Menke) #58282
  * Revert "test_runner: remove promises returned by test() (Romain Menke) #58282
  * Revert "test_runner: automatically wait for subtests to finish (Romain Menke) #58282
  * (SEMVER-MINOR) support object property mocking (Idan Goshen) #58438
url:
  * (SEMVER-MINOR) add fileURLToPathBuffer API (James M Snell) #58700

PR-URL: #58813
RafaelGSS added a commit that referenced this pull request Jun 24, 2025
Notable changes:

doc:
  * add islandryu to collaborators (Shima Ryuhei) #58714
fs:
  * (SEMVER-MINOR) allow correct handling of burst in fs-events with AsyncIterator (Philipp Dunkel) #58490
module:
  * (SEMVER-MINOR) remove experimental warning from type stripping (Marco Ippolito) #58643
test:
  * fix test-timeout-flag after revert of auto subtest wait (Pietro Marchini) #58282
test_runner:
  * (SEMVER-MINOR) support object property mocking (Idan Goshen) #58438
url:
  * (SEMVER-MINOR) add fileURLToPathBuffer API (James M Snell) #58700

PR-URL: #58813
RafaelGSS added a commit that referenced this pull request Jun 24, 2025
Notable changes:

doc:
  * add islandryu to collaborators (Shima Ryuhei) #58714
fs:
  * (SEMVER-MINOR) allow correct handling of burst in fs-events with AsyncIterator (Philipp Dunkel) #58490
module:
  * (SEMVER-MINOR) remove experimental warning from type stripping (Marco Ippolito) #58643
test:
  * fix test-timeout-flag after revert of auto subtest wait (Pietro Marchini) #58282
test_runner:
  * (SEMVER-MINOR) support object property mocking (Idan Goshen) #58438
url:
  * (SEMVER-MINOR) add fileURLToPathBuffer API (James M Snell) #58700

PR-URL: #58813
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. dont-land-on-v22.x PRs that should not land on the v22.x-staging branch and should not be released in v22.x. needs-ci PRs that need a full CI run. notable-change PRs with changes that should be highlighted in changelogs. test_runner Issues and PRs related to the test runner subsystem. tsc-agenda Issues and PRs to discuss during the meetings of the TSC.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Node 24 test runner module does not wait for subtests to finish