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-name-pattern not working for async describe suites #54084

Closed
rstagi opened this issue Jul 28, 2024 · 5 comments · Fixed by #54423
Closed

--test-name-pattern not working for async describe suites #54084

rstagi opened this issue Jul 28, 2024 · 5 comments · Fixed by #54423
Labels
test_runner Issues and PRs related to the test runner subsystem.

Comments

@rstagi
Copy link

rstagi commented Jul 28, 2024

Version

v22.5.1

Platform

Darwin Kernel Version 23.4.0

Subsystem

test runner

What steps will reproduce the bug?

With a suite like the following:

// test.mjs
import { describe, test } from "node:test";

describe("async describe", async (t) => {
  await test("some test");
});

describe("sync describe", () => {
  test("some test");
});

Run the tests with --test-name-pattern="some test":

$ node --test-name-pattern="some test" test.mjs
▶ sync describe
  ✔ some test (0.362916ms)
▶ sync describe (1.022417ms)
ℹ tests 1
ℹ suites 1
ℹ pass 1
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 6.460416

How often does it reproduce? Is there a required condition?

always

What is the expected behavior? Why is that the expected behavior?

I would expect both the test suites async describe and sync describe to work.

What do you see instead?

Only the sync describe suite seem to be working.

Additional information

By running the tests without any test name pattern, they all get executed:

$ node test.mjs
▶ async describe
  ✔ some test (0.477375ms)
▶ async describe (1.367375ms)
▶ sync describe
  ✔ some test (0.066833ms)
▶ sync describe (0.200708ms)
ℹ tests 2
ℹ suites 2
ℹ pass 2
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 7.35
@jakecastelli jakecastelli added the test_runner Issues and PRs related to the test runner subsystem. label Jul 29, 2024
@jakecastelli
Copy link
Contributor

The test with await ran but the reporter didn't collect it.

This code example works prior to v22.0 - points me to #52221

cc. @cjihrig do you mind taking a look? 👀

@rstagi
Copy link
Author

rstagi commented Jul 29, 2024

Thank you for the pointer @jakecastelli 🙏

While we wait for @cjihrig, I'll take a look myself too. I'll let you know if I find anything ⚙️

@EddieAbbondanzio
Copy link
Contributor

I took a look out of curiosity and it seems to be an async bug related to the logic that changes a suite from filtered to not filtered in postBuild here.

When the example above is ran, the sync suite gets filtered set to false before it's started, but the async suite doesn't get filtered set to false until after it was started which causes the reporter to not collect it.

@cjihrig would probably know best though.

@cjihrig
Copy link
Contributor

cjihrig commented Jul 31, 2024

Yes, without testing it, I believe what @EddieAbbondanzio is correct. I think the correct fix is to wait for the suites to be finished building before beginning to execute anything.

@cjihrig
Copy link
Contributor

cjihrig commented Aug 2, 2024

I've thought about this a bit, and I think waiting for the suites to complete is necessary, but not enough to fix this. I'm going to add another commit to #54011 that drops the returned promise from the top level test() and suite() APIs. The reason is that tests return a promise that resolves once the test runs. If we delay running tests until promises returned by tests resolve, we'll be waiting a long time.

cjihrig added a commit to cjihrig/node that referenced this issue Aug 17, 2024
This commit updates the test runner to wait for suites to finish
building before starting any tests. This is necessary when test
filtering is enabled, as suites may transition from filtered to
not filtered depending on what is inside of them.

Fixes: nodejs#54084
Fixes: nodejs#54154
cjihrig added a commit to cjihrig/node that referenced this issue Aug 18, 2024
This commit updates the test runner to wait for suites to finish
building before starting any tests. This is necessary when test
filtering is enabled, as suites may transition from filtered to
not filtered depending on what is inside of them.

Fixes: nodejs#54084
Fixes: nodejs#54154
RafaelGSS pushed a commit that referenced this issue Aug 25, 2024
This commit updates the test runner to wait for suites to finish
building before starting any tests. This is necessary when test
filtering is enabled, as suites may transition from filtered to
not filtered depending on what is inside of them.

Fixes: #54084
Fixes: #54154
PR-URL: #54423
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
4 participants