Skip to content

Commit 29c2e47

Browse files
committed
1 parent da89ad3 commit 29c2e47

File tree

6 files changed

+283
-19
lines changed

6 files changed

+283
-19
lines changed

types/node/test.d.ts

+57-1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@ 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+
export {
140+
after,
141+
afterEach,
142+
before,
143+
beforeEach,
144+
describe,
145+
it,
146+
run,
147+
mock,
148+
test,
149+
skip,
150+
todo,
151+
only
152+
};
153+
}
138154
/**
139155
* The `describe()` function imported from the `node:test` module. Each
140156
* invocation of this function results in the creation of a Subtest.
@@ -164,6 +180,14 @@ declare module 'node:test' {
164180
function todo(name?: string, fn?: SuiteFn): void;
165181
function todo(options?: TestOptions, fn?: SuiteFn): void;
166182
function todo(fn?: SuiteFn): void;
183+
/**
184+
* Shorthand for marking a suite as `only`, same as `describe([name], { only: true }[, fn])`.
185+
* @since v18.15.0
186+
*/
187+
function only(name?: string, options?: TestOptions, fn?: SuiteFn): void;
188+
function only(name?: string, fn?: SuiteFn): void;
189+
function only(options?: TestOptions, fn?: SuiteFn): void;
190+
function only(fn?: SuiteFn): void;
167191
}
168192
/**
169193
* Shorthand for `test()`.
@@ -186,7 +210,39 @@ declare module 'node:test' {
186210
function todo(name?: string, fn?: TestFn): void;
187211
function todo(options?: TestOptions, fn?: TestFn): void;
188212
function todo(fn?: TestFn): void;
213+
/**
214+
* Shorthand for marking a suite as `only`, same as `describe([name], { only: true }[, fn])`.
215+
* @since v18.15.0
216+
*/
217+
function only(name?: string, options?: TestOptions, fn?: TestFn): void;
218+
function only(name?: string, fn?: TestFn): void;
219+
function only(options?: TestOptions, fn?: TestFn): void;
220+
function only(fn?: TestFn): void;
189221
}
222+
/**
223+
* Shorthand for skipping a test, same as `test([name], { skip: true }[, fn])`.
224+
* @since v20.2.0
225+
*/
226+
function skip(name?: string, options?: TestOptions, fn?: TestFn): void;
227+
function skip(name?: string, fn?: TestFn): void;
228+
function skip(options?: TestOptions, fn?: TestFn): void;
229+
function skip(fn?: TestFn): void;
230+
/**
231+
* Shorthand for marking a test as `TODO`, same as `test([name], { todo: true }[, fn])`.
232+
* @since v20.2.0
233+
*/
234+
function todo(name?: string, options?: TestOptions, fn?: TestFn): void;
235+
function todo(name?: string, fn?: TestFn): void;
236+
function todo(options?: TestOptions, fn?: TestFn): void;
237+
function todo(fn?: TestFn): void;
238+
/**
239+
* Shorthand for marking a test as `only`, same as `test([name], { only: true }[, fn])`.
240+
* @since v20.2.0
241+
*/
242+
function only(name?: string, options?: TestOptions, fn?: TestFn): void;
243+
function only(name?: string, fn?: TestFn): void;
244+
function only(options?: TestOptions, fn?: TestFn): void;
245+
function only(fn?: TestFn): void;
190246
/**
191247
* The type of a function under test. The first argument to this function is a
192248
* {@link TestContext} object. If the test uses callbacks, the callback function is passed as
@@ -988,5 +1044,5 @@ declare module 'node:test' {
9881044
*/
9891045
restore(): void;
9901046
}
991-
export { test as default, run, test, describe, it, before, after, beforeEach, afterEach, mock };
1047+
export { test as default, run, test, describe, it, before, after, beforeEach, afterEach, mock, skip, only, todo };
9921048
}

types/node/test/test.ts

+98-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, run, test, before, beforeEach, after, afterEach } from 'node:test';
1+
import { describe, it, run, test, before, beforeEach, after, afterEach, skip, todo, only } from 'node:test';
22

33
// run without options
44
// $ExpectType TestsStream
@@ -53,6 +53,8 @@ test('options with booleans', {
5353

5454
// Test callback mode
5555
test((t, cb) => {
56+
// $ExpectedType TestContext
57+
t;
5658
// $ExpectType (result?: any) => void
5759
cb;
5860
// $ExpectType void
@@ -98,6 +100,24 @@ test(t => {
98100
// @ts-expect-error
99101
test(1, () => {});
100102

103+
test.after(() => {});
104+
test.afterEach(() => {});
105+
test.before(() => {});
106+
test.beforeEach(() => {});
107+
test.describe('describe', () => {});
108+
test.it('it', () => {});
109+
// $ExpectType MockTracker
110+
test.mock;
111+
// $ExpectType typeof test
112+
test.test;
113+
test.test.test('chained self ref', (t) => {
114+
// $ExpectType typeof test
115+
t.test;
116+
});
117+
test.skip('skip', () => {});
118+
test.todo('todo', () => {});
119+
test.only('only', () => {});
120+
101121
describe('foo', () => {
102122
it('it', () => {});
103123
});
@@ -132,26 +152,99 @@ it('options with booleans', {
132152
todo: false,
133153
});
134154

155+
skip('skip shorthand', {
156+
concurrency: 1,
157+
skip: true,
158+
signal: new AbortController().signal,
159+
timeout: Infinity,
160+
});
161+
skip((t, cb) => {
162+
// $ExpectType TestContext
163+
t;
164+
// $ExpectType (result?: any) => void
165+
cb;
166+
// $ExpectType void
167+
cb({ x: 'anything' });
168+
});
169+
test.skip('skip shorthand', {
170+
concurrency: 1,
171+
skip: true,
172+
signal: new AbortController().signal,
173+
timeout: Infinity,
174+
});
135175
describe.skip('skip shorthand', {
176+
concurrency: 1,
177+
skip: true,
178+
signal: new AbortController().signal,
179+
timeout: Infinity,
180+
});
181+
it.skip('skip shorthand', {
182+
concurrency: 1,
183+
skip: true,
184+
signal: new AbortController().signal,
185+
timeout: Infinity,
186+
});
187+
188+
todo('todo shorthand', {
189+
concurrency: 1,
190+
todo: true,
191+
signal: new AbortController().signal,
192+
timeout: Infinity,
193+
});
194+
todo((t, cb) => {
195+
// $ExpectType TestContext
196+
t;
197+
// $ExpectType (result?: any) => void
198+
cb;
199+
// $ExpectType void
200+
cb({ x: 'anything' });
201+
});
202+
test.todo('todo shorthand', {
203+
concurrency: 1,
204+
todo: true,
205+
signal: new AbortController().signal,
206+
timeout: Infinity,
207+
});
208+
describe.todo('todo shorthand', {
209+
concurrency: 1,
210+
todo: true,
211+
signal: new AbortController().signal,
212+
timeout: Infinity,
213+
});
214+
it.todo('todo shorthand', {
215+
concurrency: 1,
216+
todo: true,
217+
signal: new AbortController().signal,
218+
timeout: Infinity,
219+
});
220+
221+
only('todo shorthand', {
136222
concurrency: 1,
137223
only: true,
138224
signal: new AbortController().signal,
139225
timeout: Infinity,
140226
});
141-
it.skip('todo shorthand', {
227+
only((t, cb) => {
228+
// $ExpectType TestContext
229+
t;
230+
// $ExpectType (result?: any) => void
231+
cb;
232+
// $ExpectType void
233+
cb({ x: 'anything' });
234+
});
235+
test.only('only shorthand', {
142236
concurrency: 1,
143237
only: true,
144238
signal: new AbortController().signal,
145239
timeout: Infinity,
146240
});
147-
148-
describe.todo('skip shorthand', {
241+
describe.only('only shorthand', {
149242
concurrency: 1,
150243
only: true,
151244
signal: new AbortController().signal,
152245
timeout: Infinity,
153246
});
154-
it.todo('todo shorthand', {
247+
it.only('only shorthand', {
155248
concurrency: 1,
156249
only: true,
157250
signal: new AbortController().signal,

types/node/v18/test.d.ts

+31-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ declare module 'node:test' {
1010
* @returns A {@link TestsStream} that emits events about the test execution.
1111
*/
1212
function run(options?: RunOptions): TestsStream;
13-
1413
/**
1514
* The `test()` function is the value imported from the test module. Each invocation of this
1615
* function results in reporting the test to the {@link TestsStream}.
@@ -49,7 +48,19 @@ declare module 'node:test' {
4948
function test(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
5049
function test(options?: TestOptions, fn?: TestFn): Promise<void>;
5150
function test(fn?: TestFn): Promise<void>;
52-
51+
namespace test {
52+
export {
53+
after,
54+
afterEach,
55+
before,
56+
beforeEach,
57+
describe,
58+
it,
59+
run,
60+
mock,
61+
test
62+
};
63+
}
5364
/**
5465
* @since v18.6.0
5566
* @param name The name of the suite, which is displayed when reporting suite results.
@@ -73,6 +84,15 @@ declare module 'node:test' {
7384
function todo(name?: string, fn?: SuiteFn): void;
7485
function todo(options?: TestOptions, fn?: SuiteFn): void;
7586
function todo(fn?: SuiteFn): void;
87+
88+
/**
89+
* Shorthand for marking a suite as `only`, same as `describe([name], { only: true }[, fn])`.
90+
* @since v18.15.0
91+
*/
92+
function only(name?: string, options?: TestOptions, fn?: SuiteFn): void;
93+
function only(name?: string, fn?: SuiteFn): void;
94+
function only(options?: TestOptions, fn?: SuiteFn): void;
95+
function only(fn?: SuiteFn): void;
7696
}
7797

7898
/**
@@ -99,6 +119,15 @@ declare module 'node:test' {
99119
function todo(name?: string, fn?: TestFn): void;
100120
function todo(options?: TestOptions, fn?: TestFn): void;
101121
function todo(fn?: TestFn): void;
122+
123+
/**
124+
* Shorthand for marking a suite as `only`, same as `describe([name], { only: true }[, fn])`.
125+
* @since v18.15.0
126+
*/
127+
function only(name?: string, options?: TestOptions, fn?: TestFn): void;
128+
function only(name?: string, fn?: TestFn): void;
129+
function only(options?: TestOptions, fn?: TestFn): void;
130+
function only(fn?: TestFn): void;
102131
}
103132

104133
/**

types/node/v18/test/test.ts

+33-5
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ test(t => {
9595
// @ts-expect-error
9696
test(1, () => {});
9797

98+
test.after(() => {});
99+
test.afterEach(() => {});
100+
test.before(() => {});
101+
test.beforeEach(() => {});
102+
test.describe('describe', () => {});
103+
test.it('it', () => {});
104+
// $ExpectType MockTracker
105+
test.mock;
106+
// $ExpectType typeof test
107+
test.test;
108+
test.test.test('chained self ref', (t) => {
109+
// $ExpectType typeof test
110+
t.test;
111+
});
112+
98113
describe('foo', () => {
99114
it('it', () => {});
100115
});
@@ -131,24 +146,37 @@ it('options with booleans', {
131146

132147
describe.skip('skip shorthand', {
133148
concurrency: 1,
134-
only: true,
149+
skip: true,
135150
signal: new AbortController().signal,
136151
timeout: Infinity,
137152
});
138-
it.skip('todo shorthand', {
153+
it.skip('skip shorthand', {
139154
concurrency: 1,
140-
only: true,
155+
skip: true,
141156
signal: new AbortController().signal,
142157
timeout: Infinity,
143158
});
144159

145-
describe.todo('skip shorthand', {
160+
describe.todo('todo shorthand', {
146161
concurrency: 1,
147-
only: true,
162+
todo: true,
148163
signal: new AbortController().signal,
149164
timeout: Infinity,
150165
});
151166
it.todo('todo shorthand', {
167+
concurrency: 1,
168+
todo: true,
169+
signal: new AbortController().signal,
170+
timeout: Infinity,
171+
});
172+
173+
describe.only('only shorthand', {
174+
concurrency: 1,
175+
only: true,
176+
signal: new AbortController().signal,
177+
timeout: Infinity,
178+
});
179+
it.only('only shorthand', {
152180
concurrency: 1,
153181
only: true,
154182
signal: new AbortController().signal,

0 commit comments

Comments
 (0)