|
| 1 | +// TypeScript Version: 3.0 |
| 2 | + |
| 3 | +export = tape; |
| 4 | + |
| 5 | +/** |
| 6 | + * Create a new test with an optional name string and optional opts object. |
| 7 | + * cb(t) fires with the new test object t once all preceeding tests have finished. |
| 8 | + * Tests execute serially. |
| 9 | + */ |
| 10 | +declare function tape(name: string | tape.TestOptions, cb?: tape.TestCase): void; |
| 11 | +declare function tape(name: string, opts: tape.TestOptions, cb: tape.TestCase): void; |
| 12 | +declare function tape(cb: tape.TestCase): void; |
| 13 | + |
| 14 | +declare namespace tape { |
| 15 | + /* eslint-disable-next-line @typescript-eslint/no-invalid-void-type */ |
| 16 | + type TestCase = (test: Test) => void | Promise<void>; |
| 17 | + |
| 18 | + /** |
| 19 | + * Available opts options for the tape function. |
| 20 | + */ |
| 21 | + interface TestOptions { |
| 22 | + skip?: boolean; // See tape.skip. |
| 23 | + timeout?: number; // Set a timeout for the test, after which it will fail. See tape.timeoutAfter. |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * Options for the createStream function. |
| 28 | + */ |
| 29 | + interface StreamOptions { |
| 30 | + objectMode?: boolean; |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Generate a new test that will be skipped over. |
| 35 | + */ |
| 36 | + function skip(name: string | TestOptions, cb: TestCase): void; |
| 37 | + function skip(name: string | TestCase): void; |
| 38 | + function skip(name: string, opts: TestOptions, cb: TestCase): void; |
| 39 | + |
| 40 | + /** |
| 41 | + * The onFinish hook will get invoked when ALL tape tests have finished right before tape is about to print the test summary. |
| 42 | + */ |
| 43 | + function onFinish(cb: () => void): void; |
| 44 | + |
| 45 | + /** |
| 46 | + * Like test(name?, opts?, cb) except if you use .only this is the only test case that will run for the entire process, all other test cases using tape will be ignored. |
| 47 | + */ |
| 48 | + function only(name: string | TestOptions, cb?: TestCase): void; |
| 49 | + function only(name: string, opts: TestOptions, cb: TestCase): void; |
| 50 | + function only(cb: TestCase): void; |
| 51 | + |
| 52 | + /** |
| 53 | + * Create a new test harness instance, which is a function like test(), but with a new pending stack and test state. |
| 54 | + */ |
| 55 | + function createHarness(): typeof tape; |
| 56 | + /** |
| 57 | + * Create a stream of output, bypassing the default output stream that writes messages to console.log(). |
| 58 | + * By default stream will be a text stream of TAP output, but you can get an object stream instead by setting opts.objectMode to true. |
| 59 | + */ |
| 60 | + function createStream(opts?: StreamOptions): NodeJS.ReadableStream; |
| 61 | + |
| 62 | + interface Test { |
| 63 | + /** |
| 64 | + * Create a subtest with a new test handle st from cb(st) inside the current test. |
| 65 | + * cb(st) will only fire when t finishes. |
| 66 | + * Additional tests queued up after t will not be run until all subtests finish. |
| 67 | + */ |
| 68 | + test(name: string, cb: TestCase): void; |
| 69 | + test(name: string, opts: TestOptions, cb: TestCase): void; |
| 70 | + |
| 71 | + /** |
| 72 | + * Declare that n assertions should be run. end() will be called automatically after the nth assertion. |
| 73 | + * If there are any more assertions after the nth, or after end() is called, they will generate errors. |
| 74 | + */ |
| 75 | + plan(n: number): void; |
| 76 | + |
| 77 | + /** |
| 78 | + * Declare the end of a test explicitly. |
| 79 | + * If err is passed in t.end will assert that it is falsey. |
| 80 | + */ |
| 81 | + end(err?: unknown): void; |
| 82 | + |
| 83 | + /** |
| 84 | + * Generate a failing assertion with a message msg. |
| 85 | + */ |
| 86 | + fail(msg?: string): void; |
| 87 | + |
| 88 | + /** |
| 89 | + * Generate a passing assertion with a message msg. |
| 90 | + */ |
| 91 | + pass(msg?: string): void; |
| 92 | + |
| 93 | + /** |
| 94 | + * Automatically timeout the test after X ms. |
| 95 | + */ |
| 96 | + timeoutAfter(ms: number): void; |
| 97 | + |
| 98 | + /** |
| 99 | + * Generate an assertion that will be skipped over. |
| 100 | + */ |
| 101 | + skip(msg?: string): void; |
| 102 | + |
| 103 | + /** |
| 104 | + * Assert that value is truthy with an optional description message msg. |
| 105 | + */ |
| 106 | + ok(value: unknown, msg?: string): void; |
| 107 | + true(value: unknown, msg?: string): void; |
| 108 | + assert(value: unknown, msg?: string): void; |
| 109 | + |
| 110 | + /** |
| 111 | + * Assert that value is falsy with an optional description message msg. |
| 112 | + */ |
| 113 | + notOk(value: unknown, msg?: string): void; |
| 114 | + false(value: unknown, msg?: string): void; |
| 115 | + notok(value: unknown, msg?: string): void; |
| 116 | + |
| 117 | + /** |
| 118 | + * Assert that err is falsy. |
| 119 | + * If err is non-falsy, use its err.message as the description message. |
| 120 | + */ |
| 121 | + error(err: unknown, msg?: string): void; |
| 122 | + ifError(err: unknown, msg?: string): void; |
| 123 | + ifErr(err: unknown, msg?: string): void; |
| 124 | + iferror(err: unknown, msg?: string): void; |
| 125 | + |
| 126 | + /** |
| 127 | + * Assert that a === b with an optional description msg. |
| 128 | + */ |
| 129 | + equal<T>(actual: T, expected: T, msg?: string): void; |
| 130 | + equals<T>(actual: T, expected: T, msg?: string): void; |
| 131 | + isEqual<T>(actual: T, expected: T, msg?: string): void; |
| 132 | + is<T>(actual: T, expected: T, msg?: string): void; |
| 133 | + strictEqual<T>(actual: T, expected: T, msg?: string): void; |
| 134 | + strictEquals<T>(actual: T, expected: T, msg?: string): void; |
| 135 | + |
| 136 | + /** |
| 137 | + * Assert that a !== b with an optional description msg. |
| 138 | + */ |
| 139 | + notEqual(actual: unknown, expected: unknown, msg?: string): void; |
| 140 | + notEquals(actual: unknown, expected: unknown, msg?: string): void; |
| 141 | + notStrictEqual(actual: unknown, expected: unknown, msg?: string): void; |
| 142 | + notStrictEquals(actual: unknown, expected: unknown, msg?: string): void; |
| 143 | + isNotEqual(actual: unknown, expected: unknown, msg?: string): void; |
| 144 | + isNot(actual: unknown, expected: unknown, msg?: string): void; |
| 145 | + not(actual: unknown, expected: unknown, msg?: string): void; |
| 146 | + doesNotEqual(actual: unknown, expected: unknown, msg?: string): void; |
| 147 | + isInequal(actual: unknown, expected: unknown, msg?: string): void; |
| 148 | + |
| 149 | + /** |
| 150 | + * Assert that a and b have the same structure and nested values using node's deepEqual() algorithm with strict comparisons (===) on leaf nodes and an optional description msg. |
| 151 | + */ |
| 152 | + deepEqual<T>(actual: T, expected: T, msg?: string): void; |
| 153 | + deepEquals<T>(actual: T, expected: T, msg?: string): void; |
| 154 | + isEquivalent<T>(actual: T, expected: T, msg?: string): void; |
| 155 | + same<T>(actual: T, expected: T, msg?: string): void; |
| 156 | + |
| 157 | + /** |
| 158 | + * Assert that a and b do not have the same structure and nested values using node's deepEqual() algorithm with strict comparisons (===) on leaf nodes and an optional description msg. |
| 159 | + */ |
| 160 | + notDeepEqual(actual: unknown, expected: unknown, msg?: string): void; |
| 161 | + notEquivalent(actual: unknown, expected: unknown, msg?: string): void; |
| 162 | + notDeeply(actual: unknown, expected: unknown, msg?: string): void; |
| 163 | + notSame(actual: unknown, expected: unknown, msg?: string): void; |
| 164 | + isNotDeepEqual(actual: unknown, expected: unknown, msg?: string): void; |
| 165 | + isNotDeeply(actual: unknown, expected: unknown, msg?: string): void; |
| 166 | + isNotEquivalent(actual: unknown, expected: unknown, msg?: string): void; |
| 167 | + isInequivalent(actual: unknown, expected: unknown, msg?: string): void; |
| 168 | + |
| 169 | + /** |
| 170 | + * Assert that a and b have the same structure and nested values using node's deepEqual() algorithm with loose comparisons (==) on leaf nodes and an optional description msg. |
| 171 | + */ |
| 172 | + deepLooseEqual(actual: unknown, expected: unknown, msg?: string): void; |
| 173 | + looseEqual(actual: unknown, expected: unknown, msg?: string): void; |
| 174 | + looseEquals(actual: unknown, expected: unknown, msg?: string): void; |
| 175 | + |
| 176 | + /** |
| 177 | + * Assert that a and b do not have the same structure and nested values using node's deepEqual() algorithm with loose comparisons (==) on leaf nodes and an optional description msg. |
| 178 | + */ |
| 179 | + notDeepLooseEqual(actual: unknown, expected: unknown, msg?: string): void; |
| 180 | + notLooseEqual(actual: unknown, expected: unknown, msg?: string): void; |
| 181 | + notLooseEquals(actual: unknown, expected: unknown, msg?: string): void; |
| 182 | + |
| 183 | + /** |
| 184 | + * Assert that the function call fn() throws an exception. |
| 185 | + * expected, if present, must be a RegExp or Function, which is used to test the exception object. |
| 186 | + */ |
| 187 | + throws(fn: () => void, msg?: string): void; |
| 188 | + throws(fn: () => void, exceptionExpected: RegExp | typeof Error, msg?: string): void; |
| 189 | + |
| 190 | + /** |
| 191 | + * Assert that the function call fn() does not throw an exception. |
| 192 | + */ |
| 193 | + doesNotThrow(fn: () => void, msg?: string): void; |
| 194 | + doesNotThrow(fn: () => void, exceptionExpected: RegExp | typeof Error, msg?: string): void; |
| 195 | + |
| 196 | + /** |
| 197 | + * Print a message without breaking the tap output. |
| 198 | + * (Useful when using e.g. tap-colorize where output is buffered & console.log will print in incorrect order vis-a-vis tap output.) |
| 199 | + */ |
| 200 | + comment(msg: string): void; |
| 201 | + } |
| 202 | +} |
0 commit comments