doc: formalize TestOptions.fn and TestOptions.name as part of the public API - #64946
doc: formalize TestOptions.fn and TestOptions.name as part of the public API#64946boneskull wants to merge 2 commits into
Conversation
|
Review requested:
|
719711c to
d561a84
Compare
`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
480711f
Compare
|
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? |
|
@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>
|
@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:
|
|
Marking it semver minor out of an abundance of caution. |
|
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. |
|
@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. |
|
@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? |
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.