Skip to content

Commit 0922a50

Browse files
authored
Publish typescript definitions (#2)
1 parent ab8be46 commit 0922a50

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

index.d.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
interface TestOptions {
2+
/**
3+
* The number of tests that can be run at the same time. If unspecified, subtests inherit this value from their parent.
4+
* Default: 1.
5+
*/
6+
concurrency?: number;
7+
8+
/**
9+
* If truthy, the test is skipped. If a string is provided, that string is displayed in the test results as the reason for skipping the test.
10+
* Default: false.
11+
*/
12+
skip?: boolean | string;
13+
14+
/**
15+
* If truthy, the test marked as TODO. If a string is provided, that string is displayed in the test results as the reason why the test is TODO.
16+
* Default: false.
17+
*/
18+
todo?: boolean | string;
19+
}
20+
21+
type TestFn = (t: TestContext) => any | Promise<any>;
22+
23+
export default test;
24+
25+
/**
26+
* @returns Whether `string` is a URL.
27+
*/
28+
declare function test(name: string, options: TestOptions, fn: TestFn): void;
29+
declare function test(name: string, fn: TestFn): void;
30+
declare function test(fn: TestFn): void;
31+
32+
/**
33+
* An instance of TestContext is passed to each test function in order to interact with the test runner.
34+
* However, the TestContext constructor is not exposed as part of the API.
35+
*/
36+
export class TestContext {
37+
/**
38+
* This function is used to create subtests under the current test. This function behaves in the same fashion as the top level test() function.
39+
*/
40+
public test(name: string, options: TestOptions, fn: TestFn): Promise<void>;
41+
public test(name: string, fn: TestFn): Promise<void>;
42+
public test(fn: TestFn): Promise<void>;
43+
44+
/**
45+
* This function is used to write TAP diagnostics to the output.
46+
* Any diagnostic information is included at the end of the test's results. This function does not return a value.
47+
*
48+
* @param message Message to be displayed as a TAP diagnostic.
49+
*/
50+
public diagnostic(message: string): void;
51+
52+
/**
53+
* This function causes the test's output to indicate the test as skipped.
54+
* If message is provided, it is included in the TAP output.
55+
* Calling skip() does not terminate execution of the test function. This function does not return a value.
56+
*
57+
* @param message Optional skip message to be displayed in TAP output.
58+
*/
59+
public skip(message?: string): void;
60+
61+
/**
62+
* This function adds a TODO directive to the test's output.
63+
* If message is provided, it is included in the TAP output.
64+
* Calling todo() does not terminate execution of the test function. This function does not return a value.
65+
*
66+
* @param message Optional TODO message to be displayed in TAP output.
67+
*/
68+
public todo(message?: string): void;
69+
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"description": "Node 18's node:test, as a node module",
55
"license": "MIT",
66
"repository": "juliangruber/node-core-test",
7+
"main": "./index.js",
8+
"types": "./index.d.ts",
79
"scripts": {
810
"test": "prettier-standard && standard && node test/parallel/* && node test/message"
911
},

0 commit comments

Comments
 (0)