Skip to content

Commit a0dad36

Browse files
🤖 Merge PR #65518 node: Add tests and types for new Node test runner todo shorthands (skip and todo) by @TomasHubelbauer
* Add tests and types for new Node test runner todo shorthands (skip and todo) Node introduced these recently: nodejs/node#47909 I noticed the types are missing the `only` shorthand for all of `it`, `describe` and `test`. Should I add them in this PR or in a new one once this is merged? * Add the `only` shorthands These were missing before and even though they were not introduced with the `test` shorthands I was asked by the types maintainer to add them in this PR. * Add tests for the `only` shorthand I think this is how it should be done. * Update version in `index.d.ts` The `todo` shorthands were added in the as of writing latest stable version of Node. * Add the same to `ts4.8` and fix `TestFn`/`SuiteFn` type This should be correct. * Use MAJOR.MINOR version as is enforced in the CI Didn't realize this was the case.
1 parent b0d7dac commit a0dad36

File tree

4 files changed

+107
-3
lines changed

4 files changed

+107
-3
lines changed

‎types/node/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type definitions for non-npm package Node.js 20.1
1+
// Type definitions for non-npm package Node.js 20.2
22
// Project: https://nodejs.org/
33
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
44
// DefinitelyTyped <https://github.com/DefinitelyTyped>

‎types/node/test.d.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,29 @@ declare module 'node:test' {
135135
function test(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
136136
function test(options?: TestOptions, fn?: TestFn): Promise<void>;
137137
function test(fn?: TestFn): Promise<void>;
138+
namespace test {
139+
/**
140+
* Shorthand for skipping a suite, same as `test([name], { skip: true }[, fn])`.
141+
*/
142+
function skip(name?: string, options?: TestOptions, fn?: TestFn): void;
143+
function skip(name?: string, fn?: TestFn): void;
144+
function skip(options?: TestOptions, fn?: TestFn): void;
145+
function skip(fn?: TestFn): void;
146+
/**
147+
* Shorthand for marking a suite as `TODO`, same as `test([name], { todo: true }[, fn])`.
148+
*/
149+
function todo(name?: string, options?: TestOptions, fn?: TestFn): void;
150+
function todo(name?: string, fn?: TestFn): void;
151+
function todo(options?: TestOptions, fn?: TestFn): void;
152+
function todo(fn?: TestFn): void;
153+
/**
154+
* Shorthand for marking a suite as `TODO`, same as `test([name], { only: true }[, fn])`.
155+
*/
156+
function only(name?: string, options?: TestOptions, fn?: TestFn): void;
157+
function only(name?: string, fn?: TestFn): void;
158+
function only(options?: TestOptions, fn?: TestFn): void;
159+
function only(fn?: TestFn): void;
160+
}
138161
/**
139162
* The `describe()` function imported from the `node:test` module. Each
140163
* invocation of this function results in the creation of a Subtest.
@@ -164,6 +187,13 @@ declare module 'node:test' {
164187
function todo(name?: string, fn?: SuiteFn): void;
165188
function todo(options?: TestOptions, fn?: SuiteFn): void;
166189
function todo(fn?: SuiteFn): void;
190+
/**
191+
* Shorthand for marking a suite as `TODO`, same as `describe([name], { only: true }[, fn])`.
192+
*/
193+
function only(name?: string, options?: TestOptions, fn?: SuiteFn): void;
194+
function only(name?: string, fn?: SuiteFn): void;
195+
function only(options?: TestOptions, fn?: SuiteFn): void;
196+
function only(fn?: SuiteFn): void;
167197
}
168198
/**
169199
* Shorthand for `test()`.
@@ -186,6 +216,13 @@ declare module 'node:test' {
186216
function todo(name?: string, fn?: TestFn): void;
187217
function todo(options?: TestOptions, fn?: TestFn): void;
188218
function todo(fn?: TestFn): void;
219+
/**
220+
* Shorthand for marking a suite as `TODO`, same as `it([name], { only: true }[, fn])`.
221+
*/
222+
function only(name?: string, options?: TestOptions, fn?: TestFn): void;
223+
function only(name?: string, fn?: TestFn): void;
224+
function only(options?: TestOptions, fn?: TestFn): void;
225+
function only(fn?: TestFn): void;
189226
}
190227
/**
191228
* The type of a function under test. The first argument to this function is a

‎types/node/test/test.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,20 @@ describe.skip('skip shorthand', {
138138
signal: new AbortController().signal,
139139
timeout: Infinity,
140140
});
141-
it.skip('todo shorthand', {
141+
it.skip('skip shorthand', {
142+
concurrency: 1,
143+
only: true,
144+
signal: new AbortController().signal,
145+
timeout: Infinity,
146+
});
147+
test.skip('skip shorthand', {
142148
concurrency: 1,
143149
only: true,
144150
signal: new AbortController().signal,
145151
timeout: Infinity,
146152
});
147153

148-
describe.todo('skip shorthand', {
154+
describe.todo('todo shorthand', {
149155
concurrency: 1,
150156
only: true,
151157
signal: new AbortController().signal,
@@ -157,6 +163,30 @@ it.todo('todo shorthand', {
157163
signal: new AbortController().signal,
158164
timeout: Infinity,
159165
});
166+
test.todo('todo shorthand', {
167+
concurrency: 1,
168+
only: true,
169+
signal: new AbortController().signal,
170+
timeout: Infinity,
171+
});
172+
describe.only('only shorthand', {
173+
concurrency: 1,
174+
only: true,
175+
signal: new AbortController().signal,
176+
timeout: Infinity,
177+
});
178+
it.only('only shorthand', {
179+
concurrency: 1,
180+
only: true,
181+
signal: new AbortController().signal,
182+
timeout: Infinity,
183+
});
184+
test.only('only shorthand', {
185+
concurrency: 1,
186+
only: true,
187+
signal: new AbortController().signal,
188+
timeout: Infinity,
189+
});
160190

161191
// Test callback mode
162192
describe(cb => {

‎types/node/ts4.8/test.d.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,29 @@ declare module 'node:test' {
135135
function test(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
136136
function test(options?: TestOptions, fn?: TestFn): Promise<void>;
137137
function test(fn?: TestFn): Promise<void>;
138+
namespace test {
139+
/**
140+
* Shorthand for skipping a suite, same as `test([name], { skip: true }[, fn])`.
141+
*/
142+
function skip(name?: string, options?: TestOptions, fn?: TestFn): void;
143+
function skip(name?: string, fn?: TestFn): void;
144+
function skip(options?: TestOptions, fn?: TestFn): void;
145+
function skip(fn?: TestFn): void;
146+
/**
147+
* Shorthand for marking a suite as `TODO`, same as `test([name], { todo: true }[, fn])`.
148+
*/
149+
function todo(name?: string, options?: TestOptions, fn?: TestFn): void;
150+
function todo(name?: string, fn?: TestFn): void;
151+
function todo(options?: TestOptions, fn?: TestFn): void;
152+
function todo(fn?: TestFn): void;
153+
/**
154+
* Shorthand for marking a suite as `TODO`, same as `test([name], { only: true }[, fn])`.
155+
*/
156+
function only(name?: string, options?: TestOptions, fn?: TestFn): void;
157+
function only(name?: string, fn?: TestFn): void;
158+
function only(options?: TestOptions, fn?: TestFn): void;
159+
function only(fn?: TestFn): void;
160+
}
138161
/**
139162
* The `describe()` function imported from the `node:test` module. Each
140163
* invocation of this function results in the creation of a Subtest.
@@ -164,6 +187,13 @@ declare module 'node:test' {
164187
function todo(name?: string, fn?: SuiteFn): void;
165188
function todo(options?: TestOptions, fn?: SuiteFn): void;
166189
function todo(fn?: SuiteFn): void;
190+
/**
191+
* Shorthand for marking a suite as `TODO`, same as `describe([name], { only: true }[, fn])`.
192+
*/
193+
function only(name?: string, options?: TestOptions, fn?: SuiteFn): void;
194+
function only(name?: string, fn?: SuiteFn): void;
195+
function only(options?: TestOptions, fn?: SuiteFn): void;
196+
function only(fn?: SuiteFn): void;
167197
}
168198
/**
169199
* Shorthand for `test()`.
@@ -186,6 +216,13 @@ declare module 'node:test' {
186216
function todo(name?: string, fn?: ItFn): void;
187217
function todo(options?: TestOptions, fn?: ItFn): void;
188218
function todo(fn?: ItFn): void;
219+
/**
220+
* Shorthand for marking a suite as `TODO`, same as `it([name], { only: true }[, fn])`.
221+
*/
222+
function only(name?: string, options?: TestOptions, fn?: ItFn): void;
223+
function only(name?: string, fn?: ItFn): void;
224+
function only(options?: TestOptions, fn?: ItFn): void;
225+
function only(fn?: ItFn): void;
189226
}
190227
/**
191228
* The type of a function under test. The first argument to this function is a

0 commit comments

Comments
 (0)