index.js.flow 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. // @flow
  2. export interface PromiseLike<R> {
  3. then<U>(
  4. onFulfill: (value: R) => Promise<U> | U,
  5. onReject?: (error: any) => Promise<U> | U
  6. ): Promise<U>;
  7. }
  8. export interface ObservableLike {
  9. subscribe(observer: (value: any) => void): void;
  10. }
  11. export type Constructor = Class<{constructor(...args: Array<any>): any}>;
  12. /** Specify one or more expectations the thrown error must satisfy. */
  13. export type ThrowsExpectation = {
  14. /** The thrown error must have a code that equals the given string. */
  15. code?: string;
  16. /** The thrown error must be an instance of this constructor. */
  17. instanceOf?: Constructor;
  18. /** The thrown error must be strictly equal to this value. */
  19. is?: Error;
  20. /** The thrown error must have a message that equals the given string, or matches the regular expression. */
  21. message?: string | RegExp;
  22. /** The thrown error must have a name that equals the given string. */
  23. name?: string;
  24. };
  25. /** Options that can be passed to the `t.snapshot()` assertion. */
  26. export type SnapshotOptions = {
  27. /** If provided and not an empty string, used to select the snapshot to compare the `expected` value against. */
  28. id?: string;
  29. };
  30. export interface Assertions {
  31. /** Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */
  32. deepEqual: DeepEqualAssertion;
  33. /** Fail the test. */
  34. fail: FailAssertion;
  35. /** Assert that `actual` is strictly false. */
  36. false: FalseAssertion;
  37. /** Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy). */
  38. falsy: FalsyAssertion;
  39. /**
  40. * Assert that `actual` is [the same
  41. * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`.
  42. */
  43. is: IsAssertion;
  44. /**
  45. * Assert that `actual` is not [the same
  46. * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`.
  47. */
  48. not: NotAssertion;
  49. /** Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */
  50. notDeepEqual: NotDeepEqualAssertion;
  51. /** Assert that `string` does not match the regular expression. */
  52. notRegex: NotRegexAssertion;
  53. /** Assert that the function does not throw. */
  54. notThrows: NotThrowsAssertion;
  55. /** Count a passing assertion. */
  56. pass: PassAssertion;
  57. /** Assert that `string` matches the regular expression. */
  58. regex: RegexAssertion;
  59. /**
  60. * Assert that `expected` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to a
  61. * previously recorded [snapshot](https://github.com/concordancejs/concordance#serialization-details), or if
  62. * necessary record a new snapshot.
  63. */
  64. snapshot: SnapshotAssertion;
  65. /**
  66. * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value.
  67. */
  68. throws: ThrowsAssertion;
  69. /** Assert that `actual` is strictly true. */
  70. true: TrueAssertion;
  71. /** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). */
  72. truthy: TruthyAssertion;
  73. }
  74. export interface DeepEqualAssertion {
  75. /** Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */
  76. (actual: any, expected: any, message?: string): void;
  77. /** Skip this assertion. */
  78. skip(actual: any, expected: any, message?: string): void;
  79. }
  80. export interface FailAssertion {
  81. /** Fail the test. */
  82. (message?: string): void;
  83. /** Skip this assertion. */
  84. skip(message?: string): void;
  85. }
  86. export interface FalseAssertion {
  87. /** Assert that `actual` is strictly false. */
  88. (actual: any, message?: string): void;
  89. /** Skip this assertion. */
  90. skip(actual: any, message?: string): void;
  91. }
  92. export interface FalsyAssertion {
  93. /** Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy). */
  94. (actual: any, message?: string): void;
  95. /** Skip this assertion. */
  96. skip(actual: any, message?: string): void;
  97. }
  98. export interface IsAssertion {
  99. /**
  100. * Assert that `actual` is [the same
  101. * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`.
  102. */
  103. (actual: any, expected: any, message?: string): void;
  104. /** Skip this assertion. */
  105. skip(actual: any, expected: any, message?: string): void;
  106. }
  107. export interface NotAssertion {
  108. /**
  109. * Assert that `actual` is not [the same
  110. * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`.
  111. */
  112. (actual: any, expected: any, message?: string): void;
  113. /** Skip this assertion. */
  114. skip(actual: any, expected: any, message?: string): void;
  115. }
  116. export interface NotDeepEqualAssertion {
  117. /** Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */
  118. (actual: any, expected: any, message?: string): void;
  119. /** Skip this assertion. */
  120. skip(actual: any, expected: any, message?: string): void;
  121. }
  122. export interface NotRegexAssertion {
  123. /** Assert that `string` does not match the regular expression. */
  124. (string: string, regex: RegExp, message?: string): void;
  125. /** Skip this assertion. */
  126. skip(string: string, regex: RegExp, message?: string): void;
  127. }
  128. export interface NotThrowsAssertion {
  129. /** Assert that the function returns an observable that does not error. You must await the result. */
  130. (fn: () => ObservableLike, message?: string): Promise<void>;
  131. /** Assert that the function returns a promise that does not reject. You must await the result. */
  132. (fn: () => PromiseLike<any>, message?: string): Promise<void>;
  133. /** Assert that the function does not throw. */
  134. (fn: () => any, message?: string): void;
  135. /** Assert that the observable does not error. You must await the result. */
  136. (observable: ObservableLike, message?: string): Promise<void>;
  137. /** Assert that the promise does not reject. You must await the result. */
  138. (promise: PromiseLike<any>, message?: string): Promise<void>;
  139. /** Skip this assertion. */
  140. skip(nonThrower: any, message?: string): void;
  141. }
  142. export interface PassAssertion {
  143. /** Count a passing assertion. */
  144. (message?: string): void;
  145. /** Skip this assertion. */
  146. skip(message?: string): void;
  147. }
  148. export interface RegexAssertion {
  149. /** Assert that `string` matches the regular expression. */
  150. (string: string, regex: RegExp, message?: string): void;
  151. /** Skip this assertion. */
  152. skip(string: string, regex: RegExp, message?: string): void;
  153. }
  154. export interface SnapshotAssertion {
  155. /**
  156. * Assert that `expected` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to a
  157. * previously recorded [snapshot](https://github.com/concordancejs/concordance#serialization-details), or if
  158. * necessary record a new snapshot.
  159. */
  160. (expected: any, message?: string): void;
  161. /**
  162. * Assert that `expected` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to a
  163. * previously recorded [snapshot](https://github.com/concordancejs/concordance#serialization-details) (selected
  164. * through `options.id` if provided), or if necessary record a new snapshot.
  165. */
  166. (expected: any, options: SnapshotOptions, message?: string): void;
  167. /** Skip this assertion. */
  168. skip(expected: any, message?: string): void;
  169. /** Skip this assertion. */
  170. (expected: any, options: SnapshotOptions, message?: string): void;
  171. }
  172. export interface ThrowsAssertion {
  173. /**
  174. * Assert that the function returns an observable that errors with [an error](https://www.npmjs.com/package/is-error).
  175. * If so, returns the error value. You must await the result.
  176. */
  177. (fn: () => ObservableLike, expectations?: null, message?: string): Promise<any>;
  178. /**
  179. * Assert that the function returns an observable that errors with [an error](https://www.npmjs.com/package/is-error).
  180. * If so, returns the error value. You must await the result. The error must be an instance of the given constructor.
  181. */
  182. (fn: () => ObservableLike, constructor: Constructor, message?: string): Promise<any>;
  183. /**
  184. * Assert that the function returns an observable that errors with [an error](https://www.npmjs.com/package/is-error).
  185. * If so, returns the error value. You must await the result. The error must have a message that matches the regular
  186. * expression.
  187. */
  188. (fn: () => ObservableLike, regex: RegExp, message?: string): Promise<any>;
  189. /**
  190. * Assert that the function returns an observable that errors with [an error](https://www.npmjs.com/package/is-error).
  191. * If so, returns the error value. You must await the result. The error must have a message equal to `errorMessage`.
  192. */
  193. (fn: () => ObservableLike, errorMessage: string, message?: string): Promise<any>;
  194. /**
  195. * Assert that the function returns an observable that errors with [an error](https://www.npmjs.com/package/is-error).
  196. * If so, returns the error value. You must await the result. The error must satisfy all expectations.
  197. */
  198. (fn: () => ObservableLike, expectations: ThrowsExpectation, message?: string): Promise<any>;
  199. /**
  200. * Assert that the function returns a promise that rejects with [an error](https://www.npmjs.com/package/is-error).
  201. * If so, returns the rejection reason. You must await the result.
  202. */
  203. (fn: () => PromiseLike<any>, expectations?: null, message?: string): Promise<any>;
  204. /**
  205. * Assert that the function returns a promise that rejects with [an error](https://www.npmjs.com/package/is-error).
  206. * If so, returns the rejection reason. You must await the result. The error must be an instance of the given
  207. * constructor.
  208. */
  209. (fn: () => PromiseLike<any>, constructor: Constructor, message?: string): Promise<any>;
  210. /**
  211. * Assert that the function returns a promise that rejects with [an error](https://www.npmjs.com/package/is-error).
  212. * If so, returns the rejection reason. You must await the result. The error must have a message that matches the
  213. * regular expression.
  214. */
  215. (fn: () => PromiseLike<any>, regex: RegExp, message?: string): Promise<any>;
  216. /**
  217. * Assert that the function returns a promise that rejects with [an error](https://www.npmjs.com/package/is-error).
  218. * If so, returns the rejection reason. You must await the result. The error must have a message equal to
  219. * `errorMessage`.
  220. */
  221. (fn: () => PromiseLike<any>, errorMessage: string, message?: string): Promise<any>;
  222. /**
  223. * Assert that the function returns a promise that rejects with [an error](https://www.npmjs.com/package/is-error).
  224. * If so, returns the rejection reason. You must await the result. The error must satisfy all expectations.
  225. */
  226. (fn: () => PromiseLike<any>, expectations: ThrowsExpectation, message?: string): Promise<any>;
  227. /**
  228. * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value.
  229. */
  230. (fn: () => any, expectations?: null, message?: string): any;
  231. /**
  232. * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value.
  233. * The error must be an instance of the given constructor.
  234. */
  235. (fn: () => any, constructor: Constructor, message?: string): any;
  236. /**
  237. * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value.
  238. * The error must have a message that matches the regular expression.
  239. */
  240. (fn: () => any, regex: RegExp, message?: string): any;
  241. /**
  242. * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value.
  243. * The error must have a message equal to `errorMessage`.
  244. */
  245. (fn: () => any, errorMessage: string, message?: string): any;
  246. /**
  247. * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value.
  248. * The error must satisfy all expectations.
  249. */
  250. (fn: () => any, expectations: ThrowsExpectation, message?: string): any;
  251. /**
  252. * Assert that the observable errors with [an error](https://www.npmjs.com/package/is-error). If so, returns the error
  253. * value. You must await the result.
  254. */
  255. (promise: ObservableLike, expectations?: null, message?: string): Promise<any>;
  256. /**
  257. * Assert that the observable errors with [an error](https://www.npmjs.com/package/is-error). If so, returns the error
  258. * value. You must await the result. The error must be an instance of the given constructor.
  259. */
  260. (promise: ObservableLike, constructor: Constructor, message?: string): Promise<any>;
  261. /**
  262. * Assert that the observable errors with [an error](https://www.npmjs.com/package/is-error). If so, returns the error
  263. * value. You must await the result. The error must have a message that matches the regular expression.
  264. */
  265. (promise: ObservableLike, regex: RegExp, message?: string): Promise<any>;
  266. /**
  267. * Assert that the observable errors with [an error](https://www.npmjs.com/package/is-error). If so, returns the error
  268. * value. You must await the result. The error must have a message equal to `errorMessage`.
  269. */
  270. (promise: ObservableLike, errorMessage: string, message?: string): Promise<any>;
  271. /**
  272. * Assert that the observable errors with [an error](https://www.npmjs.com/package/is-error). If so, returns the error
  273. * value. You must await the result. The error must satisfy all expectations.
  274. */
  275. (promise: ObservableLike, expectations: ThrowsExpectation, message?: string): Promise<any>;
  276. /**
  277. * Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the
  278. * rejection reason. You must await the result.
  279. */
  280. (promise: PromiseLike<any>, expectations?: null, message?: string): Promise<any>;
  281. /**
  282. * Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the
  283. * rejection reason. You must await the result. The error must be an instance of the given constructor.
  284. */
  285. (promise: PromiseLike<any>, constructor: Constructor, message?: string): Promise<any>;
  286. /**
  287. * Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the
  288. * rejection reason. You must await the result. The error must have a message that matches the regular expression.
  289. */
  290. (promise: PromiseLike<any>, regex: RegExp, message?: string): Promise<any>;
  291. /**
  292. * Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the
  293. * rejection reason. You must await the result. The error must have a message equal to `errorMessage`.
  294. */
  295. (promise: PromiseLike<any>, errorMessage: string, message?: string): Promise<any>;
  296. /**
  297. * Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the
  298. * rejection reason. You must await the result. The error must satisfy all expectations.
  299. */
  300. (promise: PromiseLike<any>, expectations: ThrowsExpectation, message?: string): Promise<any>;
  301. /** Skip this assertion. */
  302. skip(thrower: any, expectations?: any, message?: string): void;
  303. }
  304. export interface TrueAssertion {
  305. /** Assert that `actual` is strictly true. */
  306. (actual: any, message?: string): void;
  307. /** Skip this assertion. */
  308. skip(actual: any, message?: string): void;
  309. }
  310. export interface TruthyAssertion {
  311. /** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). */
  312. (actual: any, message?: string): void;
  313. /** Skip this assertion. */
  314. skip(actual: any, message?: string): void;
  315. }
  316. /** The `t` value passed to test & hook implementations. */
  317. export interface ExecutionContext<Context = {}> extends Assertions {
  318. /** Test context, shared with hooks. */
  319. context: Context;
  320. /** Title of the test or hook. */
  321. +title: string;
  322. log: LogFn;
  323. plan: PlanFn;
  324. }
  325. export interface LogFn {
  326. /** Log one or more values. */
  327. (...values: Array<any>): void;
  328. /** Skip logging. */
  329. skip(...values: Array<any>): void;
  330. }
  331. export interface PlanFn {
  332. /**
  333. * Plan how many assertion there are in the test. The test will fail if the actual assertion count doesn't match the
  334. * number of planned assertions. See [assertion planning](https://github.com/avajs/ava#assertion-planning).
  335. */
  336. (count: number): void;
  337. /** Don't plan assertions. */
  338. skip(count: number): void;
  339. }
  340. /** The `t` value passed to implementations for tests & hooks declared with the `.cb` modifier. */
  341. export interface CbExecutionContext<Context = {}> extends ExecutionContext<Context> {
  342. /**
  343. * End the test. If `error` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy) the test or hook
  344. * will fail.
  345. */
  346. end(error?: any): void;
  347. }
  348. export type ImplementationResult = PromiseLike<void> | ObservableLike | Iterator<any> | void;
  349. export type Implementation<Context = {}> = (t: ExecutionContext<Context>) => ImplementationResult;
  350. export type CbImplementation<Context = {}> = (t: CbExecutionContext<Context>) => ImplementationResult;
  351. /** A reusable test or hook implementation. */
  352. export interface Macro<Context = {}> {
  353. (t: ExecutionContext<Context>, ...args: Array<any>): ImplementationResult;
  354. /**
  355. * Implement this function to generate a test (or hook) title whenever this macro is used. `providedTitle` contains
  356. * the title provided when the test or hook was declared. Also receives the remaining test arguments.
  357. */
  358. title?: (providedTitle: string, ...args: Array<any>) => string;
  359. }
  360. /** A reusable test or hook implementation, for tests & hooks declared with the `.cb` modifier. */
  361. export interface CbMacro<Context = {}> {
  362. (t: CbExecutionContext<Context>, ...args: Array<any>): ImplementationResult;
  363. title?: (providedTitle: string, ...args: Array<any>) => string;
  364. }
  365. export interface TestInterface<Context = {}> {
  366. /** Declare a concurrent test. */
  367. (title: string, implementation: Implementation<Context> | Macro<Context>): void;
  368. /** Declare a concurrent test that uses one or more macros. Additional arguments are passed to the macro. */
  369. (title: string, macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
  370. /**
  371. * Declare a concurrent test that uses one or more macros. Additional arguments are passed to the macro. The macro
  372. * is responsible for generating a unique test title.
  373. */
  374. (macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
  375. /** Declare a hook that is run once, after all tests have passed. */
  376. after: AfterInterface<Context>;
  377. /** Declare a hook that is run after each passing test. */
  378. afterEach: AfterInterface<Context>;
  379. /** Declare a hook that is run once, before all tests. */
  380. before: BeforeInterface<Context>;
  381. /** Declare a hook that is run before each test. */
  382. beforeEach: BeforeInterface<Context>;
  383. /** Declare a test that must call `t.end()` when it's done. */
  384. cb: CbInterface<Context>;
  385. /** Declare a test that is expected to fail. */
  386. failing: FailingInterface<Context>;
  387. /** Declare tests and hooks that are run serially. */
  388. serial: SerialInterface<Context>;
  389. only: OnlyInterface<Context>;
  390. skip: SkipInterface<Context>;
  391. todo: TodoDeclaration;
  392. }
  393. export interface AfterInterface<Context = {}> {
  394. /** Declare a hook that is run once, after all tests have passed. */
  395. (implementation: Implementation<Context> | Macro<Context>): void;
  396. /** Declare a hook that is run once, after all tests have passed. Additional argumens are passed to the macro. */
  397. (macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
  398. /** Declare a hook that is run once, after all tests have passed. */
  399. (title: string, implementation: Implementation<Context> | Macro<Context>): void;
  400. /** Declare a hook that is run once, after all tests have passed. Additional argumens are passed to the macro. */
  401. (title: string, macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
  402. /** Declare a hook that is run once, after all tests are done. */
  403. always: AlwaysInterface<Context>;
  404. /** Declare a hook that must call `t.end()` when it's done. */
  405. cb: HookCbInterface<Context>;
  406. skip: HookSkipInterface<Context>;
  407. }
  408. export interface AlwaysInterface<Context = {}> {
  409. /** Declare a hook that is run once, after all tests are done. */
  410. (implementation: Implementation<Context> | Macro<Context>): void;
  411. /** Declare a hook that is run once, after all tests are done. Additional argumens are passed to the macro. */
  412. (macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
  413. /** Declare a hook that is run once, after all tests are done. */
  414. (title: string, implementation: Implementation<Context> | Macro<Context>): void;
  415. /** Declare a hook that is run once, after all tests are done. Additional argumens are passed to the macro. */
  416. (title: string, macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
  417. /** Declare a hook that must call `t.end()` when it's done. */
  418. cb: HookCbInterface<Context>;
  419. skip: HookSkipInterface<Context>;
  420. }
  421. export interface BeforeInterface<Context = {}> {
  422. /** Declare a hook that is run once, before all tests. */
  423. (implementation: Implementation<Context> | Macro<Context>): void;
  424. /** Declare a hook that is run once, before all tests. Additional argumens are passed to the macro. */
  425. (macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
  426. /** Declare a hook that is run once, before all tests. */
  427. (title: string, implementation: Implementation<Context> | Macro<Context>): void;
  428. /** Declare a hook that is run once, before all tests. Additional argumens are passed to the macro. */
  429. (title: string, macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
  430. /** Declare a hook that must call `t.end()` when it's done. */
  431. cb: HookCbInterface<Context>;
  432. skip: HookSkipInterface<Context>;
  433. }
  434. export interface CbInterface<Context = {}> {
  435. /** Declare a test that must call `t.end()` when it's done. */
  436. (title: string, implementation: CbImplementation<Context> | CbMacro<Context>): void;
  437. /**
  438. * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done.
  439. * Additional arguments are passed to the macro.
  440. */
  441. (title: string, macro: CbMacro<Context> | CbMacro<Context>[], ...args: Array<any>): void;
  442. /**
  443. * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done.
  444. * Additional arguments are passed to the macro. The macro is responsible for generating a unique test title.
  445. */
  446. (macro: CbMacro<Context> | CbMacro<Context>[], ...args: Array<any>): void;
  447. /** Declare a test that is expected to fail. */
  448. failing: CbFailingInterface<Context>;
  449. only: CbOnlyInterface<Context>;
  450. skip: CbSkipInterface<Context>;
  451. }
  452. export interface CbFailingInterface<Context = {}> {
  453. /** Declare a test that must call `t.end()` when it's done. The test is expected to fail. */
  454. (title: string, implementation: CbImplementation<Context> | CbMacro<Context>): void;
  455. /**
  456. * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done.
  457. * Additional arguments are passed to the macro. The test is expected to fail.
  458. */
  459. (title: string, macro: CbMacro<Context> | CbMacro<Context>[], ...args: Array<any>): void;
  460. /**
  461. * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done.
  462. * Additional arguments are passed to the macro. The macro is responsible for generating a unique test title.
  463. * The test is expected to fail.
  464. */
  465. (macro: CbMacro<Context> | CbMacro<Context>[], ...args: Array<any>): void;
  466. only: CbOnlyInterface<Context>;
  467. skip: CbSkipInterface<Context>;
  468. }
  469. export interface CbOnlyInterface<Context = {}> {
  470. /**
  471. * Declare a test that must call `t.end()` when it's done. Only this test and others declared with `.only()` are run.
  472. */
  473. (title: string, implementation: CbImplementation<Context> | CbMacro<Context>): void;
  474. /**
  475. * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done.
  476. * Additional arguments are passed to the macro. Only this test and others declared with `.only()` are run.
  477. */
  478. (title: string, macro: CbMacro<Context> | CbMacro<Context>[], ...args: Array<any>): void;
  479. /**
  480. * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done.
  481. * Additional arguments are passed to the macro. The macro is responsible for generating a unique test title.
  482. * Only this test and others declared with `.only()` are run.
  483. */
  484. (macro: CbMacro<Context> | CbMacro<Context>[], ...args: Array<any>): void;
  485. }
  486. export interface CbSkipInterface<Context = {}> {
  487. /** Skip this test. */
  488. (title: string, implementation: CbImplementation<Context> | CbMacro<Context>): void;
  489. /** Skip this test. */
  490. (title: string, macro: CbMacro<Context> | CbMacro<Context>[], ...args: Array<any>): void;
  491. /** Skip this test. */
  492. (macro: CbMacro<Context> | CbMacro<Context>[], ...args: Array<any>): void;
  493. }
  494. export interface FailingInterface<Context = {}> {
  495. /** Declare a concurrent test. The test is expected to fail. */
  496. (title: string, implementation: Implementation<Context> | Macro<Context>): void;
  497. /**
  498. * Declare a concurrent test that uses one or more macros. Additional arguments are passed to the macro.
  499. * The test is expected to fail.
  500. */
  501. (title: string, macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
  502. /**
  503. * Declare a concurrent test that uses one or more macros. Additional arguments are passed to the macro. The macro
  504. * is responsible for generating a unique test title. The test is expected to fail.
  505. */
  506. (macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
  507. only: OnlyInterface<Context>;
  508. skip: SkipInterface<Context>;
  509. }
  510. export interface HookCbInterface<Context = {}> {
  511. /** Declare a hook that must call `t.end()` when it's done. */
  512. (implementation: CbImplementation<Context> | CbMacro<Context>): void;
  513. /**
  514. * Declare a hook that uses one or more macros. The macros must call `t.end()` when they're done.
  515. * Additional arguments are passed to the macro.
  516. */
  517. (macro: CbMacro<Context> | CbMacro<Context>[], ...args: Array<any>): void;
  518. /** Declare a hook that must call `t.end()` when it's done. */
  519. (title: string, implementation: CbImplementation<Context> | CbMacro<Context>): void;
  520. /**
  521. * Declare a hook that uses one or more macros. The macros must call `t.end()` when they're done.
  522. * Additional arguments are passed to the macro.
  523. */
  524. (title: string, macro: CbMacro<Context> | CbMacro<Context>[], ...args: Array<any>): void;
  525. skip: HookCbSkipInterface<Context>;
  526. }
  527. export interface HookCbSkipInterface<Context = {}> {
  528. /** Skip this hook. */
  529. (implementation: CbImplementation<Context> | CbMacro<Context>): void;
  530. /** Skip this hook. */
  531. (macro: CbMacro<Context> | CbMacro<Context>[], ...args: Array<any>): void;
  532. /** Skip this hook. */
  533. (title: string, implementation: CbImplementation<Context> | CbMacro<Context>): void;
  534. /** Skip this hook. */
  535. (title: string, macro: CbMacro<Context> | CbMacro<Context>[], ...args: Array<any>): void;
  536. }
  537. export interface HookSkipInterface<Context = {}> {
  538. /** Skip this hook. */
  539. (implementation: Implementation<Context> | Macro<Context>): void;
  540. /** Skip this hook. */
  541. (macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
  542. /** Skip this hook. */
  543. (title: string, implementation: Implementation<Context> | Macro<Context>): void;
  544. /** Skip this hook. */
  545. (title: string, macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
  546. }
  547. export interface OnlyInterface<Context = {}> {
  548. /** Declare a test. Only this test and others declared with `.only()` are run. */
  549. (title: string, implementation: Implementation<Context> | Macro<Context>): void;
  550. /**
  551. * Declare a test that uses one or more macros. Additional arguments are passed to the macro.
  552. * Only this test and others declared with `.only()` are run.
  553. */
  554. (title: string, macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
  555. /**
  556. * Declare a test that uses one or more macros. Additional arguments are passed to the macro. The macro
  557. * is responsible for generating a unique test title. Only this test and others declared with `.only()` are run.
  558. */
  559. (macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
  560. }
  561. export interface SerialInterface<Context = {}> {
  562. /** Declare a serial test. */
  563. (title: string, implementation: Implementation<Context> | Macro<Context>): void;
  564. /** Declare a serial test that uses one or more macros. Additional arguments are passed to the macro. */
  565. (title: string, macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
  566. /**
  567. * Declare a serial test that uses one or more macros. Additional arguments are passed to the macro. The macro
  568. * is responsible for generating a unique test title.
  569. */
  570. (macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
  571. /** Declare a serial hook that is run once, after all tests have passed. */
  572. after: AfterInterface<Context>;
  573. /** Declare a serial hook that is run after each passing test. */
  574. afterEach: AfterInterface<Context>;
  575. /** Declare a serial hook that is run once, before all tests. */
  576. before: BeforeInterface<Context>;
  577. /** Declare a serial hook that is run before each test. */
  578. beforeEach: BeforeInterface<Context>;
  579. /** Declare a serial test that must call `t.end()` when it's done. */
  580. cb: CbInterface<Context>;
  581. /** Declare a serial test that is expected to fail. */
  582. failing: FailingInterface<Context>;
  583. only: OnlyInterface<Context>;
  584. skip: SkipInterface<Context>;
  585. todo: TodoDeclaration;
  586. }
  587. export interface SkipInterface<Context = {}> {
  588. /** Skip this test. */
  589. (title: string, implementation: Implementation<Context> | Macro<Context>): void;
  590. /** Skip this test. */
  591. (title: string, macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
  592. /** Skip this test. */
  593. (macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
  594. }
  595. export interface TodoDeclaration {
  596. /** Declare a test that should be implemented later. */
  597. (title: string): void;
  598. }
  599. /** Call to declare a test, or chain to declare hooks or test modifiers */
  600. declare export default TestInterface<>;
  601. /** Call to declare a test, or chain to declare hooks or test modifiers */
  602. declare export var test: TestInterface<>;
  603. /** Call to declare a hook that is run after each passing test, or chain to declare modifiers. */
  604. declare export var after: AfterInterface<>;
  605. /** Call to declare a hook that is run once, before all tests, or chain to declare modifiers. */
  606. declare export var afterEach: AfterInterface<>;
  607. /** Call to declare a hook that is run before each test, or chain to declare modifiers. */
  608. declare export var before: BeforeInterface<>;
  609. /** Call to declare a test that must invoke `t.end()` when it's done, or chain to declare modifiers. */
  610. declare export var beforeEach: BeforeInterface<>;
  611. /** Call to declare a test that must invoke `t.end()` when it's done, or chain to declare modifiers. */
  612. declare export var cb: CbInterface<>;
  613. /** Call to declare a test that is expected to fail, or chain to declare modifiers. */
  614. declare export var failing: FailingInterface<>;
  615. /** Call to declare a test that is run exclusively, along with other tests declared with `.only()`. */
  616. declare export var only: OnlyInterface<>;
  617. /** Call to declare a serial test, or chain to declare serial hooks or test modifiers. */
  618. declare export var serial: SerialInterface<>;
  619. /** Skip this test. */
  620. declare export var skip: SkipInterface<>;
  621. /** Declare a test that should be implemented later. */
  622. declare export var todo: TodoDeclaration;