Uh oh!
There was an error while loading. Please reload this page.
doc: formalize TestOptions.fn and TestOptions.name as part of the public API - #64946
Conversation
nodejs-github-bot
commented
Aug 2, 2026
Review requested:
|
719711c to
d561a84Compare`TestOptions` as provided to `node:test`'s `test`/`it` supports both
`name` and `fn` as options per its implementation.
I'd like to formalize this as part of the public, documented API.
### Motivation
I have a use-case for consuming both fields. I'd like to be able to
return the result of a function to `test`/`it` without needing to spread
the parameters; e.g.:
```js
const testOptionsFactory = (opts = {}) => {
return {
fn: () => { /* .. */ },
name: opts.name
};
};
test(testOptionsFactory({name: 'foo'}));
```
If I cannot rely on this behavior, then I would need to instead return
an array of parameters and spread them:
```js
const testParamsFactory = (opts = {}) => {
return opts.name !== undefined
? [opts.name, () => { /* .. */ }] : [() => { /* .. */ }];
};
test(...testParamsFactory({name: 'foo'}));
```
I don't think it's too terribly controversial that the former is more
ergonomic than the latter.
### Next Steps
Once this lands, I plan to propose the addition of these fields to
`@types/node`. Since the fields are not currently publicly documented, I
can't justify such a change.
Signed-off-by: Christopher Hiller <boneskull@boneskull.com>d561a84 to
480711fCompareTrott
commented
Aug 2, 2026
Would this be semver minor since we're committing to supporting an API that was previously undocumented? Also, do we have test coverage for these newly-documented properties? |
boneskull
commented
Aug 2, 2026
@Trott I could add a couple tests for it. Just to confirm: this is existing, undocumented behavior. |
This adds a test suite which proves the behavior of `test`/`it`'s options; specifically how the `name` and `fn` options take precedence over their associated parameters, and how a test can be named and run using only a single "options" parameter. Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
boneskull
commented
Aug 2, 2026
@Trott I've added a test suite. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@## main #64946 +/- ##
==========================================
- Coverage 90.29% 90.29% -0.01%
==========================================
Files 760 760 Lines 247104 247137 +33 Branches 46599 46605 +6 ==========================================
+ Hits 223130 223153 +23 - Misses 15455 15456 +1 - Partials 8519 8528 +9 🚀 New features to boost your workflow:
|
Trott
commented
Aug 2, 2026
Marking it semver minor out of an abundance of caution. |
Trott
commented
Aug 2, 2026
Doc-only changes don't need CI, but this one adds tests so let's make sure the tests pass on all our Jenkins configurations. |
nodejs-github-bot
commented
Aug 2, 2026
nodejs-github-bot
commented
Aug 3, 2026
boneskull
commented
Aug 3, 2026
@Trott I'd push back against the minor flag because there's no new behavior. It's fundamentally a docs change. But I'm not gonna die on that hill. Otherwise it doesn't look like I need to do anything else here, right? Unclear if I need to squash. |
Trott
commented
Aug 3, 2026
@boneskull No need to squash. The bot will take care of that. I too am not prepared to die on the semver hill. @jasnell@ruyadorno@cjihrig Any chance one of you feels strongly about whether or not "we are now documenting a previously undocumented API" should be patch or minor? |
cjihrig
commented
Aug 3, 2026
I don't really have a preference here since there is no behavior change. |
Trott
commented
Aug 3, 2026
@nodejs/releasers Any chance one of you feels strongly about whether or not "we are now documenting a previously undocumented API" should be patch or minor? |
Uh oh!
There was an error while loading. Please reload this page.
nodejs-github-bot
commented
Aug 4, 2026
Landed in cd78d08 |
`TestOptions` as provided to `node:test`'s `test`/`it` supports both
`name` and `fn` as options per its implementation.
I'd like to formalize this as part of the public, documented API.
### Motivation
I have a use-case for consuming both fields. I'd like to be able to
return the result of a function to `test`/`it` without needing to spread
the parameters; e.g.:
```js
const testOptionsFactory = (opts = {}) => {
return {
fn: () => { /* .. */ },
name: opts.name
};
};
test(testOptionsFactory({name: 'foo'}));
```
If I cannot rely on this behavior, then I would need to instead return
an array of parameters and spread them:
```js
const testParamsFactory = (opts = {}) => {
return opts.name !== undefined
? [opts.name, () => { /* .. */ }] : [() => { /* .. */ }];
};
test(...testParamsFactory({name: 'foo'}));
```
I don't think it's too terribly controversial that the former is more
ergonomic than the latter.
### Next Steps
Once this lands, I plan to propose the addition of these fields to
`@types/node`. Since the fields are not currently publicly documented, I
can't justify such a change.
Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
PR-URL: #64946
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruy Adorno <ruy@vlt.sh>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>Notable changes: build: * (SEMVER-MINOR) perfetto-sdk (Chengzhong Wu) #64565 crypto: * (SEMVER-MINOR) support loading private keys through STORE loaders (Filip Skokan) #63949 * update root certificates to NSS 3.125 (Node.js GitHub Bot) #64746 doc: * (SEMVER-MINOR) formalize fn/name as part of TestOptions API (Christopher Hiller) #64946 lib: * (SEMVER-MINOR) add perfetto support (Chengzhong Wu) #64565 module: * (SEMVER-MINOR) implement Symbol.dispose in ModuleHooks (Remco Haszing) #63928 net: * (SEMVER-MINOR) add experimental net/promises API (Ethan Arrowood) #63965 src: * (SEMVER-MINOR) add perfetto trace agent (Chengzhong Wu) #64565 * (SEMVER-MINOR) rename legacy trace event headers (Chengzhong Wu) #64565 * (SEMVER-MINOR) fix trace macro compatibility (Chengzhong Wu) #64565 test_runner: * (SEMVER-MINOR) add support for --test-coverage-include-all (avivkeller) #64830 PR-URL: #65027
aduh95
commented
Aug 4, 2026
I think semver-patch makes more sense. Also, ideally we would document when it was introduced |
`TestOptions` as provided to `node:test`'s `test`/`it` supports both
`name` and `fn` as options per its implementation.
I'd like to formalize this as part of the public, documented API.
### Motivation
I have a use-case for consuming both fields. I'd like to be able to
return the result of a function to `test`/`it` without needing to spread
the parameters; e.g.:
```js
const testOptionsFactory = (opts = {}) => {
return {
fn: () => { /* .. */ },
name: opts.name
};
};
test(testOptionsFactory({name: 'foo'}));
```
If I cannot rely on this behavior, then I would need to instead return
an array of parameters and spread them:
```js
const testParamsFactory = (opts = {}) => {
return opts.name !== undefined
? [opts.name, () => { /* .. */ }] : [() => { /* .. */ }];
};
test(...testParamsFactory({name: 'foo'}));
```
I don't think it's too terribly controversial that the former is more
ergonomic than the latter.
### Next Steps
Once this lands, I plan to propose the addition of these fields to
`@types/node`. Since the fields are not currently publicly documented, I
can't justify such a change.
Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
PR-URL: #64946
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruy Adorno <ruy@vlt.sh>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
TestOptionsas provided tonode:test'stest/itsupports bothnameandfnas options per its implementation.I'd like to formalize this as part of the public, documented API.
Motivation
I have a use-case for consuming both fields. I'd like to be able to return the result of a function to
test/itwithout needing to spread the parameters; e.g.:If I cannot rely on this behavior, then I would need to instead return an array of parameters and spread them:
I don't think it's too terribly controversial that the former is more ergonomic than the latter.
Next Steps
Once this lands, I plan to propose the addition of these fields to
@types/node. Since the fields are not currently publicly documented, I can't justify such a change.