Skip to content

Commit 1565525

Browse files
antongolubDesplandis
authored andcommitted
1 parent e41f54f commit 1565525

File tree

8 files changed

+405
-100
lines changed

8 files changed

+405
-100
lines changed

types/node/test.d.ts

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -136,27 +136,20 @@ declare module 'node:test' {
136136
function test(options?: TestOptions, fn?: TestFn): Promise<void>;
137137
function test(fn?: TestFn): Promise<void>;
138138
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;
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+
};
160153
}
161154
/**
162155
* The `describe()` function imported from the `node:test` module. Each
@@ -188,7 +181,8 @@ declare module 'node:test' {
188181
function todo(options?: TestOptions, fn?: SuiteFn): void;
189182
function todo(fn?: SuiteFn): void;
190183
/**
191-
* Shorthand for marking a suite as `TODO`, same as `describe([name], { only: true }[, fn])`.
184+
* Shorthand for marking a suite as `only`, same as `describe([name], { only: true }[, fn])`.
185+
* @since v18.15.0
192186
*/
193187
function only(name?: string, options?: TestOptions, fn?: SuiteFn): void;
194188
function only(name?: string, fn?: SuiteFn): void;
@@ -217,13 +211,38 @@ declare module 'node:test' {
217211
function todo(options?: TestOptions, fn?: TestFn): void;
218212
function todo(fn?: TestFn): void;
219213
/**
220-
* Shorthand for marking a suite as `TODO`, same as `it([name], { only: true }[, fn])`.
214+
* Shorthand for marking a test as `only`, same as `it([name], { only: true }[, fn])`.
215+
* @since v18.15.0
221216
*/
222217
function only(name?: string, options?: TestOptions, fn?: TestFn): void;
223218
function only(name?: string, fn?: TestFn): void;
224219
function only(options?: TestOptions, fn?: TestFn): void;
225220
function only(fn?: TestFn): void;
226221
}
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;
227246
/**
228247
* The type of a function under test. The first argument to this function is a
229248
* {@link TestContext} object. If the test uses callbacks, the callback function is passed as
@@ -1025,5 +1044,5 @@ declare module 'node:test' {
10251044
*/
10261045
restore(): void;
10271046
}
1028-
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 };
10291048
}

types/node/test/test.ts

Lines changed: 75 additions & 12 deletions
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,56 +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', {
136176
concurrency: 1,
137-
only: true,
177+
skip: true,
138178
signal: new AbortController().signal,
139179
timeout: Infinity,
140180
});
141181
it.skip('skip shorthand', {
142182
concurrency: 1,
143-
only: true,
183+
skip: true,
144184
signal: new AbortController().signal,
145185
timeout: Infinity,
146186
});
147-
test.skip('skip shorthand', {
187+
188+
todo('todo shorthand', {
148189
concurrency: 1,
149-
only: true,
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,
150205
signal: new AbortController().signal,
151206
timeout: Infinity,
152207
});
153-
154208
describe.todo('todo shorthand', {
155209
concurrency: 1,
156-
only: true,
210+
todo: true,
157211
signal: new AbortController().signal,
158212
timeout: Infinity,
159213
});
160214
it.todo('todo shorthand', {
161215
concurrency: 1,
162-
only: true,
216+
todo: true,
163217
signal: new AbortController().signal,
164218
timeout: Infinity,
165219
});
166-
test.todo('todo shorthand', {
220+
221+
only('todo shorthand', {
167222
concurrency: 1,
168223
only: true,
169224
signal: new AbortController().signal,
170225
timeout: Infinity,
171226
});
172-
describe.only('only 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', {
173236
concurrency: 1,
174237
only: true,
175238
signal: new AbortController().signal,
176239
timeout: Infinity,
177240
});
178-
it.only('only shorthand', {
241+
describe.only('only shorthand', {
179242
concurrency: 1,
180243
only: true,
181244
signal: new AbortController().signal,
182245
timeout: Infinity,
183246
});
184-
test.only('only shorthand', {
247+
it.only('only shorthand', {
185248
concurrency: 1,
186249
only: true,
187250
signal: new AbortController().signal,

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

Lines changed: 60 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -136,27 +136,20 @@ declare module 'node:test' {
136136
function test(options?: TestOptions, fn?: TestFn): Promise<void>;
137137
function test(fn?: TestFn): Promise<void>;
138138
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;
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+
};
160153
}
161154
/**
162155
* The `describe()` function imported from the `node:test` module. Each
@@ -187,8 +180,10 @@ declare module 'node:test' {
187180
function todo(name?: string, fn?: SuiteFn): void;
188181
function todo(options?: TestOptions, fn?: SuiteFn): void;
189182
function todo(fn?: SuiteFn): void;
183+
190184
/**
191-
* Shorthand for marking a suite as `TODO`, same as `describe([name], { only: true }[, fn])`.
185+
* Shorthand for marking a suite as `only`, same as `describe([name], { only: true }[, fn])`.
186+
* @since v18.15.0
192187
*/
193188
function only(name?: string, options?: TestOptions, fn?: SuiteFn): void;
194189
function only(name?: string, fn?: SuiteFn): void;
@@ -201,29 +196,54 @@ declare module 'node:test' {
201196
* The `it()` function is imported from the `node:test` module.
202197
* @since v18.6.0, v16.17.0
203198
*/
204-
function it(name?: string, options?: TestOptions, fn?: ItFn): void;
205-
function it(name?: string, fn?: ItFn): void;
206-
function it(options?: TestOptions, fn?: ItFn): void;
207-
function it(fn?: ItFn): void;
199+
function it(name?: string, options?: TestOptions, fn?: TestFn): void;
200+
function it(name?: string, fn?: TestFn): void;
201+
function it(options?: TestOptions, fn?: TestFn): void;
202+
function it(fn?: TestFn): void;
208203
namespace it {
209204
// Shorthand for skipping a test, same as `it([name], { skip: true }[, fn])`.
210-
function skip(name?: string, options?: TestOptions, fn?: ItFn): void;
211-
function skip(name?: string, fn?: ItFn): void;
212-
function skip(options?: TestOptions, fn?: ItFn): void;
213-
function skip(fn?: ItFn): void;
205+
function skip(name?: string, options?: TestOptions, fn?: TestFn): void;
206+
function skip(name?: string, fn?: TestFn): void;
207+
function skip(options?: TestOptions, fn?: TestFn): void;
208+
function skip(fn?: TestFn): void;
214209
// Shorthand for marking a test as `TODO`, same as `it([name], { todo: true }[, fn])`.
215-
function todo(name?: string, options?: TestOptions, fn?: ItFn): void;
216-
function todo(name?: string, fn?: ItFn): void;
217-
function todo(options?: TestOptions, fn?: ItFn): void;
218-
function todo(fn?: ItFn): void;
210+
function todo(name?: string, options?: TestOptions, fn?: TestFn): void;
211+
function todo(name?: string, fn?: TestFn): void;
212+
function todo(options?: TestOptions, fn?: TestFn): void;
213+
function todo(fn?: TestFn): void;
219214
/**
220-
* Shorthand for marking a suite as `TODO`, same as `it([name], { only: true }[, fn])`.
215+
* Shorthand for marking a test as `only`, same as `it([name], { only: true }[, fn])`.
216+
* @since v18.15.0
221217
*/
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;
218+
function only(name?: string, options?: TestOptions, fn?: TestFn): void;
219+
function only(name?: string, fn?: TestFn): void;
220+
function only(options?: TestOptions, fn?: TestFn): void;
221+
function only(fn?: TestFn): void;
226222
}
223+
/**
224+
* Shorthand for skipping a test, same as `test([name], { skip: true }[, fn])`.
225+
* @since v20.2.0
226+
*/
227+
function skip(name?: string, options?: TestOptions, fn?: TestFn): void;
228+
function skip(name?: string, fn?: TestFn): void;
229+
function skip(options?: TestOptions, fn?: TestFn): void;
230+
function skip(fn?: TestFn): void;
231+
/**
232+
* Shorthand for marking a test as `TODO`, same as `test([name], { todo: true }[, fn])`.
233+
* @since v20.2.0
234+
*/
235+
function todo(name?: string, options?: TestOptions, fn?: TestFn): void;
236+
function todo(name?: string, fn?: TestFn): void;
237+
function todo(options?: TestOptions, fn?: TestFn): void;
238+
function todo(fn?: TestFn): void;
239+
/**
240+
* Shorthand for marking a test as `only`, same as `test([name], { only: true }[, fn])`.
241+
* @since v20.2.0
242+
*/
243+
function only(name?: string, options?: TestOptions, fn?: TestFn): void;
244+
function only(name?: string, fn?: TestFn): void;
245+
function only(options?: TestOptions, fn?: TestFn): void;
246+
function only(fn?: TestFn): void;
227247
/**
228248
* The type of a function under test. The first argument to this function is a
229249
* {@link TestContext} object. If the test uses callbacks, the callback function is passed as
@@ -235,11 +255,6 @@ declare module 'node:test' {
235255
* If the test uses callbacks, the callback function is passed as an argument
236256
*/
237257
type SuiteFn = (done: (result?: any) => void) => void;
238-
/**
239-
* The type of a function under test.
240-
* If the test uses callbacks, the callback function is passed as an argument
241-
*/
242-
type ItFn = (done: (result?: any) => void) => any;
243258
interface RunOptions {
244259
/**
245260
* If a number is provided, then that many files would run in parallel.
@@ -1030,5 +1045,5 @@ declare module 'node:test' {
10301045
*/
10311046
restore(): void;
10321047
}
1033-
export { test as default, run, test, describe, it, before, after, beforeEach, afterEach, mock };
1048+
export { test as default, run, test, describe, it, before, after, beforeEach, afterEach, mock, skip, only, todo };
10341049
}

0 commit comments

Comments
 (0)