|
| 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 | +} |
0 commit comments