Skip to content

Commit

Permalink
🤖 Merge PR #65518 node: Add tests and types for new Node test runner …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
TomasHubelbauer authored May 17, 2023
1 parent b0d7dac commit a0dad36
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 3 deletions.
2 changes: 1 addition & 1 deletion types/node/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Type definitions for non-npm package Node.js 20.1
// Type definitions for non-npm package Node.js 20.2
// Project: https://nodejs.org/
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
// DefinitelyTyped <https://github.com/DefinitelyTyped>
Expand Down
37 changes: 37 additions & 0 deletions types/node/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,29 @@ declare module 'node:test' {
function test(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
function test(options?: TestOptions, fn?: TestFn): Promise<void>;
function test(fn?: TestFn): Promise<void>;
namespace test {
/**
* Shorthand for skipping a suite, same as `test([name], { skip: true }[, fn])`.
*/
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 suite as `TODO`, same as `test([name], { todo: true }[, fn])`.
*/
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 suite as `TODO`, same as `test([name], { only: true }[, fn])`.
*/
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 `describe()` function imported from the `node:test` module. Each
* invocation of this function results in the creation of a Subtest.
Expand Down Expand Up @@ -164,6 +187,13 @@ 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 `TODO`, same as `describe([name], { only: true }[, fn])`.
*/
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()`.
Expand All @@ -186,6 +216,13 @@ 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 `TODO`, same as `it([name], { only: true }[, fn])`.
*/
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
Expand Down
34 changes: 32 additions & 2 deletions types/node/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,20 @@ describe.skip('skip shorthand', {
signal: new AbortController().signal,
timeout: Infinity,
});
it.skip('todo shorthand', {
it.skip('skip shorthand', {
concurrency: 1,
only: true,
signal: new AbortController().signal,
timeout: Infinity,
});
test.skip('skip shorthand', {
concurrency: 1,
only: true,
signal: new AbortController().signal,
timeout: Infinity,
});

describe.todo('skip shorthand', {
describe.todo('todo shorthand', {
concurrency: 1,
only: true,
signal: new AbortController().signal,
Expand All @@ -157,6 +163,30 @@ it.todo('todo shorthand', {
signal: new AbortController().signal,
timeout: Infinity,
});
test.todo('todo shorthand', {
concurrency: 1,
only: 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,
timeout: Infinity,
});
test.only('only shorthand', {
concurrency: 1,
only: true,
signal: new AbortController().signal,
timeout: Infinity,
});

// Test callback mode
describe(cb => {
Expand Down
37 changes: 37 additions & 0 deletions types/node/ts4.8/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,29 @@ declare module 'node:test' {
function test(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
function test(options?: TestOptions, fn?: TestFn): Promise<void>;
function test(fn?: TestFn): Promise<void>;
namespace test {
/**
* Shorthand for skipping a suite, same as `test([name], { skip: true }[, fn])`.
*/
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 suite as `TODO`, same as `test([name], { todo: true }[, fn])`.
*/
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 suite as `TODO`, same as `test([name], { only: true }[, fn])`.
*/
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 `describe()` function imported from the `node:test` module. Each
* invocation of this function results in the creation of a Subtest.
Expand Down Expand Up @@ -164,6 +187,13 @@ 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 `TODO`, same as `describe([name], { only: true }[, fn])`.
*/
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()`.
Expand All @@ -186,6 +216,13 @@ declare module 'node:test' {
function todo(name?: string, fn?: ItFn): void;
function todo(options?: TestOptions, fn?: ItFn): void;
function todo(fn?: ItFn): void;
/**
* Shorthand for marking a suite as `TODO`, same as `it([name], { only: true }[, fn])`.
*/
function only(name?: string, options?: TestOptions, fn?: ItFn): void;
function only(name?: string, fn?: ItFn): void;
function only(options?: TestOptions, fn?: ItFn): void;
function only(fn?: ItFn): void;
}
/**
* The type of a function under test. The first argument to this function is a
Expand Down

0 comments on commit a0dad36

Please sign in to comment.