test_runner: add skip, todo, only, and expectFailure to subtest context#62156
test_runner: add skip, todo, only, and expectFailure to subtest context#62156Felipeness wants to merge 3 commits intonodejs:mainfrom
Conversation
|
Review requested:
|
|
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.
There was a problem hiding this comment.
Thanks. The DRY'ing up is an advantage over the original PR this came from; I think there is a better way to go about it though: #61251 (comment)
It's maybe not so nice that you copy+pasted an entire file from that other PR 😕 (I see you did cite the origin PR in a comment here)
|
Duplicate of #61251 |
|
Thanks for the review @JakobJingleheimer! I've addressed your feedback: Changes in the latest commit:
The approach follows the same pattern as I'm aware this overlaps with #61251. Happy to close this in favor of that PR if preferred — the DRY improvements and |
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