test_runner: add skip, todo, only, and expectFailure to subtest context#62156
Open
Felipeness wants to merge 2 commits intonodejs:mainfrom
Open
test_runner: add skip, todo, only, and expectFailure to subtest context#62156Felipeness wants to merge 2 commits intonodejs:mainfrom
Felipeness wants to merge 2 commits intonodejs:mainfrom
Conversation
Collaborator
|
Review requested:
|
Author
|
This is an alternative to #61251, addressing the same issue. Key differences:
|
The top-level test() function exposes test.skip(), test.todo(), test.only(), and test.expectFailure() variants, but these were missing from TestContext's test() method used in subtests, causing TypeError. Move test() from the class prototype to an arrow function in the constructor, allowing variants to be attached as properties. Extract a shared runSubtest() helper to avoid duplicating the plan counting and createSubtest logic. This trades one shared prototype method for 5 closures per TestContext instance (one base + four variants), which is acceptable given V8's closure optimization for same-shape functions. Includes tests for: variant existence, skip preventing callback execution, todo with and without callback, plan counting with variants, and nested subtest variant availability. Fixes: nodejs#50665
d9bb1f7 to
60db1ec
Compare
Node.js core lint rule (node-core/set-proto-to-null-in-object) requires every object literal in lib/ to have __proto__: null to prevent prototype pollution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The top-level
test()function exposestest.skip(),test.todo(),test.only(), andtest.expectFailure()variants, but these were missing fromTestContext'stest()method. Callingt.test.skip()inside a test callback threwTypeError: t.test.skip is not a function.The documentation states that
t.test()"behaves identically to the top leveltest()", so this is a bug.Changes
test()from theTestContextclass prototype to an arrow function in the constructor, allowing variant methods to be attached as propertiesrunSubtest()helper to avoid duplicating plan counting andcreateSubtestlogic.skip,.todo,.only, and.expectFailure— matching the exact same list used inharness.jsfor the top-leveltest()Trade-off
This trades one shared prototype method for 5 closures per
TestContextinstance (one base + four variants). This is acceptable given V8's closure optimization for same-shape functions, and is the same pattern used by the top-leveltest()inharness.js.Test plan
TestContext(includingexpectFailure)t.test.skip()prevents callback executiont.test.todo()without callback (marks as todo, skips)t.test.todo()with callback (runs callback, marks as todo)t.plan()counting works with subtest variantsFixes: #50665