diff --git a/types/node/test.d.ts b/types/node/test.d.ts index 3d1cb9ce914252b..b365509e8cad89e 100644 --- a/types/node/test.d.ts +++ b/types/node/test.d.ts @@ -135,6 +135,22 @@ declare module 'node:test' { function test(name?: string, options?: TestOptions, fn?: TestFn): Promise; function test(options?: TestOptions, fn?: TestFn): Promise; function test(fn?: TestFn): Promise; + namespace test { + export { + after, + afterEach, + before, + beforeEach, + describe, + it, + run, + mock, + test, + skip, + todo, + only + }; + } /** * The `describe()` function imported from the `node:test` module. Each * invocation of this function results in the creation of a Subtest. @@ -164,6 +180,14 @@ declare module 'node:test' { function todo(name?: string, fn?: SuiteFn): void; function todo(options?: TestOptions, fn?: SuiteFn): void; function todo(fn?: SuiteFn): void; + /** + * Shorthand for marking a suite as `only`, same as `describe([name], { only: true }[, fn])`. + * @since v18.15.0 + */ + function only(name?: string, options?: TestOptions, fn?: SuiteFn): void; + function only(name?: string, fn?: SuiteFn): void; + function only(options?: TestOptions, fn?: SuiteFn): void; + function only(fn?: SuiteFn): void; } /** * Shorthand for `test()`. @@ -186,7 +210,39 @@ declare module 'node:test' { function todo(name?: string, fn?: TestFn): void; function todo(options?: TestOptions, fn?: TestFn): void; function todo(fn?: TestFn): void; + /** + * Shorthand for marking a suite as `only`, same as `describe([name], { only: true }[, fn])`. + * @since v18.15.0 + */ + function only(name?: string, options?: TestOptions, fn?: TestFn): void; + function only(name?: string, fn?: TestFn): void; + function only(options?: TestOptions, fn?: TestFn): void; + function only(fn?: TestFn): void; } + /** + * Shorthand for skipping a test, same as `test([name], { skip: true }[, fn])`. + * @since v20.2.0 + */ + function skip(name?: string, options?: TestOptions, fn?: TestFn): void; + function skip(name?: string, fn?: TestFn): void; + function skip(options?: TestOptions, fn?: TestFn): void; + function skip(fn?: TestFn): void; + /** + * Shorthand for marking a test as `TODO`, same as `test([name], { todo: true }[, fn])`. + * @since v20.2.0 + */ + function todo(name?: string, options?: TestOptions, fn?: TestFn): void; + function todo(name?: string, fn?: TestFn): void; + function todo(options?: TestOptions, fn?: TestFn): void; + function todo(fn?: TestFn): void; + /** + * Shorthand for marking a test as `only`, same as `test([name], { only: true }[, fn])`. + * @since v20.2.0 + */ + function only(name?: string, options?: TestOptions, fn?: TestFn): void; + function only(name?: string, fn?: TestFn): void; + function only(options?: TestOptions, fn?: TestFn): void; + function only(fn?: TestFn): void; /** * The type of a function under test. The first argument to this function is a * {@link TestContext} object. If the test uses callbacks, the callback function is passed as @@ -988,5 +1044,5 @@ declare module 'node:test' { */ restore(): void; } - export { test as default, run, test, describe, it, before, after, beforeEach, afterEach, mock }; + export { test as default, run, test, describe, it, before, after, beforeEach, afterEach, mock, skip, only, todo }; } diff --git a/types/node/test/test.ts b/types/node/test/test.ts index 169351352846968..2d774e494a77e32 100644 --- a/types/node/test/test.ts +++ b/types/node/test/test.ts @@ -1,4 +1,4 @@ -import { describe, it, run, test, before, beforeEach, after, afterEach } from 'node:test'; +import { describe, it, run, test, before, beforeEach, after, afterEach, skip, todo, only } from 'node:test'; // run without options // $ExpectType TestsStream @@ -53,6 +53,8 @@ test('options with booleans', { // Test callback mode test((t, cb) => { + // $ExpectedType TestContext + t; // $ExpectType (result?: any) => void cb; // $ExpectType void @@ -98,6 +100,24 @@ test(t => { // @ts-expect-error test(1, () => {}); +test.after(() => {}); +test.afterEach(() => {}); +test.before(() => {}); +test.beforeEach(() => {}); +test.describe('describe', () => {}); +test.it('it', () => {}); +// $ExpectType MockTracker +test.mock; +// $ExpectType typeof test +test.test; +test.test.test('chained self ref', (t) => { + // $ExpectType typeof test + t.test; +}); +test.skip('skip', () => {}); +test.todo('todo', () => {}); +test.only('only', () => {}); + describe('foo', () => { it('it', () => {}); }); @@ -132,26 +152,99 @@ it('options with booleans', { todo: false, }); +skip('skip shorthand', { + concurrency: 1, + skip: true, + signal: new AbortController().signal, + timeout: Infinity, +}); +skip((t, cb) => { + // $ExpectType TestContext + t; + // $ExpectType (result?: any) => void + cb; + // $ExpectType void + cb({ x: 'anything' }); +}); +test.skip('skip shorthand', { + concurrency: 1, + skip: true, + signal: new AbortController().signal, + timeout: Infinity, +}); describe.skip('skip shorthand', { + concurrency: 1, + skip: true, + signal: new AbortController().signal, + timeout: Infinity, +}); +it.skip('skip shorthand', { + concurrency: 1, + skip: true, + signal: new AbortController().signal, + timeout: Infinity, +}); + +todo('todo shorthand', { + concurrency: 1, + todo: true, + signal: new AbortController().signal, + timeout: Infinity, +}); +todo((t, cb) => { + // $ExpectType TestContext + t; + // $ExpectType (result?: any) => void + cb; + // $ExpectType void + cb({ x: 'anything' }); +}); +test.todo('todo shorthand', { + concurrency: 1, + todo: true, + signal: new AbortController().signal, + timeout: Infinity, +}); +describe.todo('todo shorthand', { + concurrency: 1, + todo: true, + signal: new AbortController().signal, + timeout: Infinity, +}); +it.todo('todo shorthand', { + concurrency: 1, + todo: true, + signal: new AbortController().signal, + timeout: Infinity, +}); + +only('todo shorthand', { concurrency: 1, only: true, signal: new AbortController().signal, timeout: Infinity, }); -it.skip('todo shorthand', { +only((t, cb) => { + // $ExpectType TestContext + t; + // $ExpectType (result?: any) => void + cb; + // $ExpectType void + cb({ x: 'anything' }); +}); +test.only('only shorthand', { concurrency: 1, only: true, signal: new AbortController().signal, timeout: Infinity, }); - -describe.todo('skip shorthand', { +describe.only('only shorthand', { concurrency: 1, only: true, signal: new AbortController().signal, timeout: Infinity, }); -it.todo('todo shorthand', { +it.only('only shorthand', { concurrency: 1, only: true, signal: new AbortController().signal, diff --git a/types/node/v18/test.d.ts b/types/node/v18/test.d.ts index 0196cbc10f72fc8..3b0265c6972223b 100644 --- a/types/node/v18/test.d.ts +++ b/types/node/v18/test.d.ts @@ -10,7 +10,6 @@ declare module 'node:test' { * @returns A {@link TestsStream} that emits events about the test execution. */ function run(options?: RunOptions): TestsStream; - /** * The `test()` function is the value imported from the test module. Each invocation of this * function results in reporting the test to the {@link TestsStream}. @@ -49,7 +48,19 @@ declare module 'node:test' { function test(name?: string, options?: TestOptions, fn?: TestFn): Promise; function test(options?: TestOptions, fn?: TestFn): Promise; function test(fn?: TestFn): Promise; - + namespace test { + export { + after, + afterEach, + before, + beforeEach, + describe, + it, + run, + mock, + test + }; + } /** * @since v18.6.0 * @param name The name of the suite, which is displayed when reporting suite results. @@ -73,6 +84,15 @@ declare module 'node:test' { function todo(name?: string, fn?: SuiteFn): void; function todo(options?: TestOptions, fn?: SuiteFn): void; function todo(fn?: SuiteFn): void; + + /** + * Shorthand for marking a suite as `only`, same as `describe([name], { only: true }[, fn])`. + * @since v18.15.0 + */ + function only(name?: string, options?: TestOptions, fn?: SuiteFn): void; + function only(name?: string, fn?: SuiteFn): void; + function only(options?: TestOptions, fn?: SuiteFn): void; + function only(fn?: SuiteFn): void; } /** @@ -99,6 +119,15 @@ declare module 'node:test' { function todo(name?: string, fn?: TestFn): void; function todo(options?: TestOptions, fn?: TestFn): void; function todo(fn?: TestFn): void; + + /** + * Shorthand for marking a suite as `only`, same as `describe([name], { only: true }[, fn])`. + * @since v18.15.0 + */ + function only(name?: string, options?: TestOptions, fn?: TestFn): void; + function only(name?: string, fn?: TestFn): void; + function only(options?: TestOptions, fn?: TestFn): void; + function only(fn?: TestFn): void; } /** diff --git a/types/node/v18/test/test.ts b/types/node/v18/test/test.ts index 1c9cdf45004016e..b58b6bb52ab3a4e 100644 --- a/types/node/v18/test/test.ts +++ b/types/node/v18/test/test.ts @@ -95,6 +95,21 @@ test(t => { // @ts-expect-error test(1, () => {}); +test.after(() => {}); +test.afterEach(() => {}); +test.before(() => {}); +test.beforeEach(() => {}); +test.describe('describe', () => {}); +test.it('it', () => {}); +// $ExpectType MockTracker +test.mock; +// $ExpectType typeof test +test.test; +test.test.test('chained self ref', (t) => { + // $ExpectType typeof test + t.test; +}); + describe('foo', () => { it('it', () => {}); }); @@ -131,24 +146,37 @@ it('options with booleans', { describe.skip('skip shorthand', { concurrency: 1, - only: true, + skip: true, signal: new AbortController().signal, timeout: Infinity, }); -it.skip('todo shorthand', { +it.skip('skip shorthand', { concurrency: 1, - only: true, + skip: true, signal: new AbortController().signal, timeout: Infinity, }); -describe.todo('skip shorthand', { +describe.todo('todo shorthand', { concurrency: 1, - only: true, + todo: true, signal: new AbortController().signal, timeout: Infinity, }); it.todo('todo shorthand', { + concurrency: 1, + todo: true, + signal: new AbortController().signal, + timeout: Infinity, +}); + +describe.only('only shorthand', { + concurrency: 1, + only: true, + signal: new AbortController().signal, + timeout: Infinity, +}); +it.only('only shorthand', { concurrency: 1, only: true, signal: new AbortController().signal, diff --git a/types/node/v18/ts4.8/test.d.ts b/types/node/v18/ts4.8/test.d.ts index 0196cbc10f72fc8..c1c96b9d59f3617 100644 --- a/types/node/v18/ts4.8/test.d.ts +++ b/types/node/v18/ts4.8/test.d.ts @@ -49,7 +49,22 @@ declare module 'node:test' { function test(name?: string, options?: TestOptions, fn?: TestFn): Promise; function test(options?: TestOptions, fn?: TestFn): Promise; function test(fn?: TestFn): Promise; - + namespace test { + export { + after, + afterEach, + before, + beforeEach, + describe, + it, + run, + mock, + test, + only, + skip, + todo + }; + } /** * @since v18.6.0 * @param name The name of the suite, which is displayed when reporting suite results. @@ -73,6 +88,15 @@ declare module 'node:test' { function todo(name?: string, fn?: SuiteFn): void; function todo(options?: TestOptions, fn?: SuiteFn): void; function todo(fn?: SuiteFn): void; + + /** + * Shorthand for marking a suite as `only`, same as `describe([name], { only: true }[, fn])`. + * @since v18.15.0 + */ + function only(name?: string, options?: TestOptions, fn?: SuiteFn): void; + function only(name?: string, fn?: SuiteFn): void; + function only(options?: TestOptions, fn?: SuiteFn): void; + function only(fn?: SuiteFn): void; } /** @@ -99,7 +123,40 @@ declare module 'node:test' { function todo(name?: string, fn?: TestFn): void; function todo(options?: TestOptions, fn?: TestFn): void; function todo(fn?: TestFn): void; + + /** + * Shorthand for marking a suite as `only`, same as `describe([name], { only: true }[, fn])`. + * @since v18.15.0 + */ + function only(name?: string, options?: TestOptions, fn?: TestFn): void; + function only(name?: string, fn?: TestFn): void; + function only(options?: TestOptions, fn?: TestFn): void; + function only(fn?: TestFn): void; } + /** + * Shorthand for skipping a test, same as `test([name], { skip: true }[, fn])`. + * @since v20.2.0 + */ + function skip(name?: string, options?: TestOptions, fn?: TestFn): void; + function skip(name?: string, fn?: TestFn): void; + function skip(options?: TestOptions, fn?: TestFn): void; + function skip(fn?: TestFn): void; + /** + * Shorthand for marking a test as `TODO`, same as `test([name], { todo: true }[, fn])`. + * @since v20.2.0 + */ + function todo(name?: string, options?: TestOptions, fn?: TestFn): void; + function todo(name?: string, fn?: TestFn): void; + function todo(options?: TestOptions, fn?: TestFn): void; + function todo(fn?: TestFn): void; + /** + * Shorthand for marking a test as `only`, same as `test([name], { only: true }[, fn])`. + * @since v20.2.0 + */ + function only(name?: string, options?: TestOptions, fn?: TestFn): void; + function only(name?: string, fn?: TestFn): void; + function only(options?: TestOptions, fn?: TestFn): void; + function only(fn?: TestFn): void; /** * The type of a function under test. The first argument to this function is a @@ -750,5 +807,5 @@ declare module 'node:test' { restore(): void; } - export { test as default, run, test, describe, it, before, after, beforeEach, afterEach, mock }; + export { test as default, run, test, describe, it, before, after, beforeEach, afterEach, mock, skip, only, todo }; } diff --git a/types/node/v18/ts4.8/test/test.ts b/types/node/v18/ts4.8/test/test.ts index 1c9cdf45004016e..9eda08eee048f31 100644 --- a/types/node/v18/ts4.8/test/test.ts +++ b/types/node/v18/ts4.8/test/test.ts @@ -1,4 +1,4 @@ -import { describe, it, run, test, before, beforeEach, after, afterEach } from 'node:test'; +import {describe, it, run, test, before, beforeEach, after, afterEach, skip, todo, only} from 'node:test'; // run without options // $ExpectType TestsStream @@ -95,6 +95,24 @@ test(t => { // @ts-expect-error test(1, () => {}); +test.after(() => {}); +test.afterEach(() => {}); +test.before(() => {}); +test.beforeEach(() => {}); +test.describe('describe', () => {}); +test.it('it', () => {}); +// $ExpectType MockTracker +test.mock; +// $ExpectType typeof test +test.test; +test.test.test('chained self ref', (t) => { + // $ExpectType typeof test + t.test; +}); +test.skip('skip', () => {}); +test.todo('todo', () => {}); +test.only('only', () => {}); + describe('foo', () => { it('it', () => {}); }); @@ -129,26 +147,99 @@ it('options with booleans', { todo: false, }); +skip('skip shorthand', { + concurrency: 1, + skip: true, + signal: new AbortController().signal, + timeout: Infinity, +}); +skip((t, cb) => { + // $ExpectType TestContext + t; + // $ExpectType (result?: any) => void + cb; + // $ExpectType void + cb({ x: 'anything' }); +}); +test.skip('skip shorthand', { + concurrency: 1, + skip: true, + signal: new AbortController().signal, + timeout: Infinity, +}); describe.skip('skip shorthand', { + concurrency: 1, + skip: true, + signal: new AbortController().signal, + timeout: Infinity, +}); +it.skip('skip shorthand', { + concurrency: 1, + skip: true, + signal: new AbortController().signal, + timeout: Infinity, +}); + +todo('todo shorthand', { + concurrency: 1, + todo: true, + signal: new AbortController().signal, + timeout: Infinity, +}); +todo((t, cb) => { + // $ExpectType TestContext + t; + // $ExpectType (result?: any) => void + cb; + // $ExpectType void + cb({ x: 'anything' }); +}); +test.todo('todo shorthand', { + concurrency: 1, + todo: true, + signal: new AbortController().signal, + timeout: Infinity, +}); +describe.todo('todo shorthand', { + concurrency: 1, + todo: true, + signal: new AbortController().signal, + timeout: Infinity, +}); +it.todo('todo shorthand', { + concurrency: 1, + todo: true, + signal: new AbortController().signal, + timeout: Infinity, +}); + +only('todo shorthand', { concurrency: 1, only: true, signal: new AbortController().signal, timeout: Infinity, }); -it.skip('todo shorthand', { +only((t, cb) => { + // $ExpectType TestContext + t; + // $ExpectType (result?: any) => void + cb; + // $ExpectType void + cb({ x: 'anything' }); +}); +test.only('only shorthand', { concurrency: 1, only: true, signal: new AbortController().signal, timeout: Infinity, }); - -describe.todo('skip shorthand', { +describe.only('only shorthand', { concurrency: 1, only: true, signal: new AbortController().signal, timeout: Infinity, }); -it.todo('todo shorthand', { +it.only('only shorthand', { concurrency: 1, only: true, signal: new AbortController().signal,