|
| 1 | +export interface Observable { |
| 2 | + subscribe(observer: (value: {}) => void): void; |
| 3 | +} |
| 4 | + |
| 5 | +export type Test = (t: TestContext) => Promise<void> | Iterator<any> | Observable | void; |
| 6 | +export type SerialTest = (t: TestContext) => void; |
| 7 | +export type CallbackTest = (t: CallbackTestContext) => void; |
| 8 | + |
| 9 | +export interface Runner { |
| 10 | + (name: string, run: Test): void; |
| 11 | + (run: Test): void; |
| 12 | + skip: Runner; |
| 13 | + cb: CallbackRunner; |
| 14 | +} |
| 15 | +export interface SerialRunner { |
| 16 | + (name: string, run: SerialTest): void; |
| 17 | + (run: SerialTest): void; |
| 18 | + skip: SerialRunner; |
| 19 | +} |
| 20 | +export interface CallbackRunner { |
| 21 | + (name: string, run: CallbackTest): void; |
| 22 | + (run: CallbackTest): void; |
| 23 | + skip: CallbackRunner; |
| 24 | +} |
| 25 | + |
| 26 | +export function test(name: string, run: Test): void; |
| 27 | +export function test(run: Test): void; |
| 28 | +export namespace test { |
| 29 | + export const before: Runner; |
| 30 | + export const after: Runner; |
| 31 | + export const beforeEach: Runner; |
| 32 | + export const afterEach: Runner; |
| 33 | + |
| 34 | + export const skip: typeof test; |
| 35 | + export const only: typeof test; |
| 36 | + |
| 37 | + export function serial(name: string, run: SerialTest): void; |
| 38 | + export function serial(run: SerialTest): void; |
| 39 | + export function cb(name: string, run: CallbackTest): void; |
| 40 | + export function cb(run: CallbackTest): void; |
| 41 | +} |
| 42 | +export namespace test.serial { |
| 43 | + export const before: SerialRunner; |
| 44 | + export const after: SerialRunner; |
| 45 | + export const beforeEach: SerialRunner; |
| 46 | + export const afterEach: SerialRunner; |
| 47 | + |
| 48 | + export const skip: typeof test.serial; |
| 49 | + export const only: typeof test.serial; |
| 50 | +} |
| 51 | +export namespace test.cb { |
| 52 | + export const before: CallbackRunner; |
| 53 | + export const after: CallbackRunner; |
| 54 | + export const beforeEach: CallbackRunner; |
| 55 | + export const afterEach: CallbackRunner; |
| 56 | + |
| 57 | + export const skip: typeof test.cb; |
| 58 | + export const only: typeof test.cb; |
| 59 | +} |
| 60 | +export default test; |
| 61 | + |
| 62 | +export type ErrorValidator |
| 63 | + = (new (...args: any[]) => any) |
| 64 | + | RegExp |
| 65 | + | string |
| 66 | + | ((error: any) => boolean); |
| 67 | + |
| 68 | +export interface AssertContext { |
| 69 | + /** |
| 70 | + * Passing assertion. |
| 71 | + */ |
| 72 | + pass(message?: string): void; |
| 73 | + /** |
| 74 | + * Failing assertion. |
| 75 | + */ |
| 76 | + fail(message?: string): void; |
| 77 | + /** |
| 78 | + * Assert that value is truthy. |
| 79 | + */ |
| 80 | + ok(value: any, message?: string): void; |
| 81 | + /** |
| 82 | + * Assert that value is falsy. |
| 83 | + */ |
| 84 | + notOk(value: any, message?: string): void; |
| 85 | + /** |
| 86 | + * Assert that value is true. |
| 87 | + */ |
| 88 | + true(value: boolean, message?: string): void; |
| 89 | + /** |
| 90 | + * Assert that value is false. |
| 91 | + */ |
| 92 | + false(value: boolean, message?: string): void; |
| 93 | + /** |
| 94 | + * Assert that value is equal to expected. |
| 95 | + */ |
| 96 | + is<U>(value: U, expected: U, message?: string): void; |
| 97 | + /** |
| 98 | + * Assert that value is not equal to expected. |
| 99 | + */ |
| 100 | + not<U>(value: U, expected: U, message?: string): void; |
| 101 | + /** |
| 102 | + * Assert that value is deep equal to expected. |
| 103 | + */ |
| 104 | + same<U>(value: U, expected: U, message?: string): void; |
| 105 | + /** |
| 106 | + * Assert that value is not deep equal to expected. |
| 107 | + */ |
| 108 | + notSame<U>(value: U, expected: U, message?: string): void; |
| 109 | + /** |
| 110 | + * Assert that function throws an error or promise rejects. |
| 111 | + * @param error Can be a constructor, regex, error message or validation function. |
| 112 | + */ |
| 113 | + throws(value: (() => void) | Promise<{}>, error?: ErrorValidator, message?: string); |
| 114 | + /** |
| 115 | + * Assert that function doesn't throw an error or promise resolves. |
| 116 | + */ |
| 117 | + notThrows(value: (() => void) | Promise<{}>, message?: string); |
| 118 | + /** |
| 119 | + * Assert that contents matches regex. |
| 120 | + */ |
| 121 | + regex(contents: string, regex: RegExp, message?: string): void; |
| 122 | + /** |
| 123 | + * Assert that error is falsy. |
| 124 | + */ |
| 125 | + ifError(error: any, message?: string): void; |
| 126 | +} |
| 127 | +export interface TestContext extends AssertContext { |
| 128 | + /** |
| 129 | + * Plan how many assertion there are in the test. |
| 130 | + * The test will fail if the actual assertion count doesn't match planned assertions. |
| 131 | + */ |
| 132 | + plan(count: number): void; |
| 133 | + |
| 134 | + skip: AssertContext; |
| 135 | +} |
| 136 | +export interface CallbackTestContext extends TestContext { |
| 137 | + /** |
| 138 | + * End the test. |
| 139 | + */ |
| 140 | + end(): void; |
| 141 | +} |
0 commit comments