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: fix #50665 .skip, .todo and .only missing in subtests #50673

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rluvaton
Copy link
Member

Fix #50665

@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 Nov 11, 2023
@rluvaton rluvaton force-pushed the fix-50665-only-skip-todo-not-available-for-subtest branch 2 times, most recently from 638b7b6 to 63fdacf Compare November 11, 2023 21:28
@rluvaton rluvaton marked this pull request as ready for review November 11, 2023 21:28
@rluvaton rluvaton added the request-ci Add this label to start a Jenkins CI on a PR. label Nov 11, 2023
@rluvaton rluvaton force-pushed the fix-50665-only-skip-todo-not-available-for-subtest branch from 63fdacf to 8834f4b Compare November 11, 2023 21:31
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Nov 11, 2023
@nodejs-github-bot
Copy link
Collaborator

@rluvaton rluvaton added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Nov 11, 2023
@rluvaton rluvaton requested review from MoLow, cjihrig and atlowChemi and removed request for cjihrig November 11, 2023 23:36
Comment on lines 127 to 236
this.test = (name, options, fn) => {
const overrides = {
__proto__: null,
loc: getCallerLocation(),
};
// eslint-disable-next-line no-use-before-define
const subtest = this.#test.createSubtest(Test, name, options, fn, overrides);
return subtest.start();
};
Copy link
Member

Choose a reason for hiding this comment

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

wouldn't it be more performant to leave this as a prototype method, and instead do a public class field test = FunctionPrototypeBind(this.test, this);, so that the "meat" of the method can be shared and optimized across all instances?

separately, couldn't the skip/todo/only methods be assigned to the prototype method once, in a static block, instead of a new function created on every instance?

Copy link
Member Author

Choose a reason for hiding this comment

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

If you mean with Object.defineProperty, then without changing the #test to [kTest] it can't as it cannot access private method outside the class.
if you mean adding the skip/todo/any in the constructor but keeping the test function as is, than for some reason it did not work for me

The skip/todo/any methods are needed to assign on the test function, not on the TestContext

Copy link
Member

Choose a reason for hiding this comment

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

Ah, true, the 3 expandos need to be done in the constructor every time - altho the meat could be shared private methods and the per-instance thing could just be a bound function.

@@ -153,20 +178,6 @@ class TestContext {
this.#test.todo(message);
}

test(name, options, fn) {
Copy link
Member

Choose a reason for hiding this comment

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

why not keep as prototype methods?

Copy link
Member Author

Choose a reason for hiding this comment

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

for some reason it did not work for me adding skip/todo/etc to the test function

@bakkot
Copy link

bakkot commented Nov 13, 2023

The docs for only say

it is possible to skip all top level tests except for a selected subset by passing the only option to the tests that should be run. When a test with the only option set is run, all subtests are also run.

How is that supposed to map to use of only in subtests? Consider test('a', t => { t.test.only('b', () => {}); }) - i.e., a top-level test which is not marked as only with a subtest which is. I can imagine at least two possibilities:

  • Since the top-level test does not have only, running in --test-only skips the entire top-level test. You'd have to use test.only('a', t => { t.test.only('b', () => {}); }) for this to work.
  • It somehow figures out that the top-level test contains a t.only, and enables the top-level test, but skips subtests of that test.

Presumably this implements the first one (though I don't see any tests for that scenario). Either way the docs should be updated, because right now they imply that only is specific to top-level tests. Maybe something like:

When a test with the only option set is run, all subtests are also run, unless some of the subtests of that test also have the only option set, in which case only those subtests are run. Using only for a subtest has no effect unless its parent test also has only set.

@rluvaton
Copy link
Member Author

rluvaton commented Nov 15, 2023

@bakkot this is a known issue and unrelated to this PR or the linked issue

If I'm correct #48932 is the one to fix that issue

@aduh95 aduh95 removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Nov 29, 2023
@aduh95
Copy link
Contributor

aduh95 commented Nov 29, 2023

Removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. as this PR has no approvals

@rluvaton rluvaton force-pushed the fix-50665-only-skip-todo-not-available-for-subtest branch from 8834f4b to 8ba986d Compare January 20, 2024 19:55
@rluvaton rluvaton force-pushed the fix-50665-only-skip-todo-not-available-for-subtest branch from 8ba986d to 77128c7 Compare June 25, 2024 09:16
@cjihrig cjihrig added the stalled Issues and PRs that are stalled. label Sep 19, 2024
Copy link
Contributor

This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open.

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. stalled Issues and PRs that are stalled. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test runner (--test, node:test) subtest test context lack .skip, .only and .todo functions
7 participants