|  | 
|  | 1 | +/* @flow */ | 
|  | 2 | + | 
|  | 3 | +/** | 
|  | 4 | + * Misc Setup Types | 
|  | 5 | + */ | 
|  | 6 | + | 
|  | 7 | +type PromiseLike<R> = { | 
|  | 8 | +	then<U>( | 
|  | 9 | +		onFulfill?: (value: R) => Promise<U> | U, | 
|  | 10 | +		onReject?: (error: any) => Promise<U> | U | 
|  | 11 | +	): Promise<U>; | 
|  | 12 | +} | 
|  | 13 | + | 
|  | 14 | +type ObservableLike = { | 
|  | 15 | +	subscribe(observer: (value: {}) => void): void; | 
|  | 16 | +}; | 
|  | 17 | + | 
|  | 18 | +type SpecialReturnTypes = | 
|  | 19 | +	| PromiseLike<any> | 
|  | 20 | +	| Iterator<any> | 
|  | 21 | +	| ObservableLike; | 
|  | 22 | + | 
|  | 23 | +type Constructor = Class<{ | 
|  | 24 | +	constructor(...args: Array<any>): any | 
|  | 25 | +}>; | 
|  | 26 | + | 
|  | 27 | +type ErrorValidator = | 
|  | 28 | +	| Constructor | 
|  | 29 | +	| RegExp | 
|  | 30 | +	| string | 
|  | 31 | +	| ((error: any) => boolean); | 
|  | 32 | + | 
|  | 33 | +/** | 
|  | 34 | + * Asertion Types | 
|  | 35 | + */ | 
|  | 36 | + | 
|  | 37 | +type AssertContext = { | 
|  | 38 | +	// Passing assertion. | 
|  | 39 | +	pass(message?: string): void; | 
|  | 40 | +	// Failing assertion. | 
|  | 41 | +	fail(message?: string): void; | 
|  | 42 | +	// Assert that value is truthy. | 
|  | 43 | +	truthy(value: mixed, message?: string): void; | 
|  | 44 | +	// Assert that value is falsy. | 
|  | 45 | +	falsy(value: mixed, message?: string): void; | 
|  | 46 | +	// DEPRECATED, use `truthy`. Assert that value is truthy. | 
|  | 47 | +	ok(value: mixed, message?: string): void; | 
|  | 48 | +	// DEPRECATED, use `falsy`. Assert that value is falsy. | 
|  | 49 | +	notOk(value: mixed, message?: string): void; | 
|  | 50 | +	// Assert that value is true. | 
|  | 51 | +	true(value: boolean, message?: string): void; | 
|  | 52 | +	// Assert that value is false. | 
|  | 53 | +	false(value: boolean, message?: string): void; | 
|  | 54 | +	// Assert that value is equal to expected. | 
|  | 55 | +	is<U>(value: U, expected: U, message?: string): void; | 
|  | 56 | +	// Assert that value is not equal to expected. | 
|  | 57 | +	not<U>(value: U, expected: U, message?: string): void; | 
|  | 58 | +	// Assert that value is deep equal to expected. | 
|  | 59 | +	deepEqual<U>(value: U, expected: U, message?: string): void; | 
|  | 60 | +	// Assert that value is not deep equal to expected. | 
|  | 61 | +	notDeepEqual<U>(value: U, expected: U, message?: string): void; | 
|  | 62 | +	// Assert that function throws an error or promise rejects. | 
|  | 63 | +	// DEPRECATED, use `deepEqual`. Assert that value is deep equal to expected. | 
|  | 64 | +	// @param error Can be a constructor, regex, error message or validation function. | 
|  | 65 | +	same<U>(value: U, expected: U, message?: string): void; | 
|  | 66 | +	// DEPRECATED use `notDeepEqual`. Assert that value is not deep equal to expected. | 
|  | 67 | +	notSame<U>(value: U, expected: U, message?: string): void; | 
|  | 68 | +	// Assert that function throws an error or promise rejects. | 
|  | 69 | +	// @param error Can be a constructor, regex, error message or validation function. | 
|  | 70 | +	throws(value: PromiseLike<mixed>, error?: ErrorValidator, message?: string): Promise<mixed>; | 
|  | 71 | +	throws(value: () => void, error?: ErrorValidator, message?: string): mixed; | 
|  | 72 | +	// Assert that function doesn't throw an error or promise resolves. | 
|  | 73 | +	notThrows<U>(value: PromiseLike<U>, message?: string): Promise<U>; | 
|  | 74 | +	notThrows(value: () => void, message?: string): void; | 
|  | 75 | +	// Assert that contents matches regex. | 
|  | 76 | +	regex(contents: string, regex: RegExp, message?: string): void; | 
|  | 77 | +	// Assert that contents does not match regex. | 
|  | 78 | +	notRegex(contents: string, regex: RegExp, message?: string): void; | 
|  | 79 | +	// Assert that error is falsy. | 
|  | 80 | +	ifError(error: any, message?: string): void; | 
|  | 81 | +}; | 
|  | 82 | + | 
|  | 83 | +/** | 
|  | 84 | + * Context Types | 
|  | 85 | + */ | 
|  | 86 | + | 
|  | 87 | +type TestContext = AssertContext & { | 
|  | 88 | +	plan(count: number): void; | 
|  | 89 | +	skip: AssertContext; | 
|  | 90 | +}; | 
|  | 91 | +type CallbackTestContext           = TestContext         & { end(): void; }; | 
|  | 92 | +type ContextualTestContext         = TestContext         & { context: any; }; | 
|  | 93 | +type ContextualCallbackTestContext = CallbackTestContext & { context: any; }; | 
|  | 94 | + | 
|  | 95 | +/** | 
|  | 96 | + * Test Types | 
|  | 97 | + */ | 
|  | 98 | + | 
|  | 99 | +type Test                   = (t: TestContext)                   => SpecialReturnTypes | void; | 
|  | 100 | +type CallbackTest           = (t: CallbackTestContext)           => void; | 
|  | 101 | +type ContextualTest         = (t: ContextualTestContext)         => SpecialReturnTypes | void; | 
|  | 102 | +type ContextualCallbackTest = (t: ContextualCallbackTestContext) => void; | 
|  | 103 | + | 
|  | 104 | +/** | 
|  | 105 | + * Macro Types | 
|  | 106 | + */ | 
|  | 107 | + | 
|  | 108 | +type Macro<T> = { | 
|  | 109 | +	(t: T, ...args: Array<any>): void; | 
|  | 110 | +	title?: (providedTitle: string, ...args: Array<any>) => string; | 
|  | 111 | +}; | 
|  | 112 | + | 
|  | 113 | +type Macros<T> = | 
|  | 114 | +	| Macro<T> | 
|  | 115 | +	| Array<Macro<T>>; | 
|  | 116 | + | 
|  | 117 | +/** | 
|  | 118 | + * Method Types | 
|  | 119 | + */ | 
|  | 120 | + | 
|  | 121 | +type TestMethod = { | 
|  | 122 | +	(              implementation: Test): void; | 
|  | 123 | +	(name: string, implementation: Test): void; | 
|  | 124 | +	(              implementation: Macros<TestContext>, ...args: Array<any>): void; | 
|  | 125 | +	(name: string, implementation: Macros<TestContext>, ...args: Array<any>): void; | 
|  | 126 | + | 
|  | 127 | +	serial     : TestMethod; | 
|  | 128 | +	before     : TestMethod; | 
|  | 129 | +	after      : TestMethod; | 
|  | 130 | +	skip       : TestMethod; | 
|  | 131 | +	todo       : TestMethod; | 
|  | 132 | +	failing    : TestMethod; | 
|  | 133 | +	only       : TestMethod; | 
|  | 134 | +	beforeEach : TestMethod; | 
|  | 135 | +	afterEach  : TestMethod; | 
|  | 136 | +	cb         : CallbackTestMethod; | 
|  | 137 | +	always     : TestMethod; | 
|  | 138 | +}; | 
|  | 139 | + | 
|  | 140 | +type CallbackTestMethod = { | 
|  | 141 | +	(              implementation: CallbackTest): void; | 
|  | 142 | +	(name: string, implementation: CallbackTest): void; | 
|  | 143 | +	(              implementation: Macros<CallbackTestContext>, ...args: Array<any>): void; | 
|  | 144 | +	(name: string, implementation: Macros<CallbackTestContext>, ...args: Array<any>): void; | 
|  | 145 | + | 
|  | 146 | +	serial     : CallbackTestMethod; | 
|  | 147 | +	before     : CallbackTestMethod; | 
|  | 148 | +	after      : CallbackTestMethod; | 
|  | 149 | +	skip       : CallbackTestMethod; | 
|  | 150 | +	todo       : CallbackTestMethod; | 
|  | 151 | +	failing    : CallbackTestMethod; | 
|  | 152 | +	only       : CallbackTestMethod; | 
|  | 153 | +	beforeEach : CallbackTestMethod; | 
|  | 154 | +	afterEach  : CallbackTestMethod; | 
|  | 155 | +	cb         : CallbackTestMethod; | 
|  | 156 | +	always     : CallbackTestMethod; | 
|  | 157 | +}; | 
|  | 158 | + | 
|  | 159 | +type ContextualTestMethod = { | 
|  | 160 | +	(              implementation: ContextualTest): void; | 
|  | 161 | +	(name: string, implementation: ContextualTest): void; | 
|  | 162 | +	(              implementation: Macros<ContextualTestContext>, ...args: Array<any>): void; | 
|  | 163 | +	(name: string, implementation: Macros<ContextualTestContext>, ...args: Array<any>): void; | 
|  | 164 | + | 
|  | 165 | +	serial     : ContextualTestMethod; | 
|  | 166 | +	before     : ContextualTestMethod; | 
|  | 167 | +	after      : ContextualTestMethod; | 
|  | 168 | +	skip       : ContextualTestMethod; | 
|  | 169 | +	todo       : ContextualTestMethod; | 
|  | 170 | +	failing    : ContextualTestMethod; | 
|  | 171 | +	only       : ContextualTestMethod; | 
|  | 172 | +	beforeEach : ContextualTestMethod; | 
|  | 173 | +	afterEach  : ContextualTestMethod; | 
|  | 174 | +	cb         : ContextualCallbackTestMethod; | 
|  | 175 | +	always     : ContextualTestMethod; | 
|  | 176 | +}; | 
|  | 177 | + | 
|  | 178 | +type ContextualCallbackTestMethod = { | 
|  | 179 | +	(              implementation: ContextualCallbackTest): void; | 
|  | 180 | +	(name: string, implementation: ContextualCallbackTest): void; | 
|  | 181 | +	(              implementation: Macros<ContextualCallbackTestContext>, ...args: Array<any>): void; | 
|  | 182 | +	(name: string, implementation: Macros<ContextualCallbackTestContext>, ...args: Array<any>): void; | 
|  | 183 | + | 
|  | 184 | +	serial     : ContextualCallbackTestMethod; | 
|  | 185 | +	before     : ContextualCallbackTestMethod; | 
|  | 186 | +	after      : ContextualCallbackTestMethod; | 
|  | 187 | +	skip       : ContextualCallbackTestMethod; | 
|  | 188 | +	todo       : ContextualCallbackTestMethod; | 
|  | 189 | +	failing    : ContextualCallbackTestMethod; | 
|  | 190 | +	only       : ContextualCallbackTestMethod; | 
|  | 191 | +	beforeEach : ContextualCallbackTestMethod; | 
|  | 192 | +	afterEach  : ContextualCallbackTestMethod; | 
|  | 193 | +	cb         : ContextualCallbackTestMethod; | 
|  | 194 | +	always     : ContextualCallbackTestMethod; | 
|  | 195 | +}; | 
|  | 196 | + | 
|  | 197 | +/** | 
|  | 198 | + * Public API | 
|  | 199 | + */ | 
|  | 200 | + | 
|  | 201 | +declare module.exports: { | 
|  | 202 | +	(              run: ContextualTest): void; | 
|  | 203 | +	(name: string, run: ContextualTest): void; | 
|  | 204 | +	(              run: Macros<ContextualTestContext>, ...args: Array<any>): void; | 
|  | 205 | +	(name: string, run: Macros<ContextualTestContext>, ...args: Array<any>): void; | 
|  | 206 | + | 
|  | 207 | +	beforeEach : TestMethod; | 
|  | 208 | +	afterEach  : TestMethod; | 
|  | 209 | +	serial     : ContextualTestMethod; | 
|  | 210 | +	before     : ContextualTestMethod; | 
|  | 211 | +	after      : ContextualTestMethod; | 
|  | 212 | +	skip       : ContextualTestMethod; | 
|  | 213 | +	todo       : ContextualTestMethod; | 
|  | 214 | +	failing    : ContextualTestMethod; | 
|  | 215 | +	only       : ContextualTestMethod; | 
|  | 216 | +	cb         : ContextualCallbackTestMethod; | 
|  | 217 | +	always     : ContextualTestMethod; | 
|  | 218 | +}; | 
0 commit comments