index.d.ts 32 KB

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