mocha.d.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // Type definitions for mocha 2.2.5
  2. // Project: http://mochajs.org/
  3. // Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>, otiai10 <https://github.com/otiai10>, jt000 <https://github.com/jt000>, Vadim Macagon <https://github.com/enlight>
  4. // Definitions: https://github.com/borisyankov/DefinitelyTyped
  5. interface MochaSetupOptions {
  6. //milliseconds to wait before considering a test slow
  7. slow?: number;
  8. // timeout in milliseconds
  9. timeout?: number;
  10. // ui name "bdd", "tdd", "exports" etc
  11. ui?: string;
  12. //array of accepted globals
  13. globals?: any[];
  14. // reporter instance (function or string), defaults to `mocha.reporters.Spec`
  15. reporter?: any;
  16. // bail on the first test failure
  17. bail?: boolean;
  18. // ignore global leaks
  19. ignoreLeaks?: boolean;
  20. // grep string or regexp to filter tests with
  21. grep?: any;
  22. }
  23. interface MochaDone {
  24. (error?: Error): void;
  25. }
  26. declare var mocha: Mocha;
  27. declare var describe: Mocha.IContextDefinition;
  28. declare var xdescribe: Mocha.IContextDefinition;
  29. // alias for `describe`
  30. declare var context: Mocha.IContextDefinition;
  31. // alias for `describe`
  32. declare var suite: Mocha.IContextDefinition;
  33. declare var it: Mocha.ITestDefinition;
  34. declare var xit: Mocha.ITestDefinition;
  35. // alias for `it`
  36. declare var test: Mocha.ITestDefinition;
  37. declare function before(action: () => void): void;
  38. declare function before(action: (done: MochaDone) => void): void;
  39. declare function setup(action: () => void): void;
  40. declare function setup(action: (done: MochaDone) => void): void;
  41. declare function after(action: () => void): void;
  42. declare function after(action: (done: MochaDone) => void): void;
  43. declare function teardown(action: () => void): void;
  44. declare function teardown(action: (done: MochaDone) => void): void;
  45. declare function beforeEach(action: () => void): void;
  46. declare function beforeEach(action: (done: MochaDone) => void): void;
  47. declare function suiteSetup(action: () => void): void;
  48. declare function suiteSetup(action: (done: MochaDone) => void): void;
  49. declare function afterEach(action: () => void): void;
  50. declare function afterEach(action: (done: MochaDone) => void): void;
  51. declare function suiteTeardown(action: () => void): void;
  52. declare function suiteTeardown(action: (done: MochaDone) => void): void;
  53. declare class Mocha {
  54. constructor(options?: {
  55. grep?: RegExp;
  56. ui?: string;
  57. reporter?: string;
  58. timeout?: number;
  59. bail?: boolean;
  60. });
  61. /** Setup mocha with the given options. */
  62. setup(options: MochaSetupOptions): Mocha;
  63. bail(value?: boolean): Mocha;
  64. addFile(file: string): Mocha;
  65. /** Sets reporter by name, defaults to "spec". */
  66. reporter(name: string): Mocha;
  67. /** Sets reporter constructor, defaults to mocha.reporters.Spec. */
  68. reporter(reporter: (runner: Mocha.IRunner, options: any) => any): Mocha;
  69. ui(value: string): Mocha;
  70. grep(value: string): Mocha;
  71. grep(value: RegExp): Mocha;
  72. invert(): Mocha;
  73. ignoreLeaks(value: boolean): Mocha;
  74. checkLeaks(): Mocha;
  75. /**
  76. * Function to allow assertion libraries to throw errors directly into mocha.
  77. * This is useful when running tests in a browser because window.onerror will
  78. * only receive the 'message' attribute of the Error.
  79. */
  80. throwError(error: Error): void;
  81. /** Enables growl support. */
  82. growl(): Mocha;
  83. globals(value: string): Mocha;
  84. globals(values: string[]): Mocha;
  85. useColors(value: boolean): Mocha;
  86. useInlineDiffs(value: boolean): Mocha;
  87. timeout(value: number): Mocha;
  88. slow(value: number): Mocha;
  89. enableTimeouts(value: boolean): Mocha;
  90. asyncOnly(value: boolean): Mocha;
  91. noHighlighting(value: boolean): Mocha;
  92. /** Runs tests and invokes `onComplete()` when finished. */
  93. run(onComplete?: (failures: number) => void): Mocha.IRunner;
  94. }
  95. // merge the Mocha class declaration with a module
  96. declare module Mocha {
  97. /** Partial interface for Mocha's `Runnable` class. */
  98. interface IRunnable {
  99. title: string;
  100. fn: Function;
  101. async: boolean;
  102. sync: boolean;
  103. timedOut: boolean;
  104. }
  105. /** Partial interface for Mocha's `Suite` class. */
  106. interface ISuite {
  107. parent: ISuite;
  108. title: string;
  109. fullTitle(): string;
  110. }
  111. /** Partial interface for Mocha's `Test` class. */
  112. interface ITest extends IRunnable {
  113. parent: ISuite;
  114. pending: boolean;
  115. fullTitle(): string;
  116. }
  117. /** Partial interface for Mocha's `Runner` class. */
  118. interface IRunner {}
  119. interface IContextDefinition {
  120. (description: string, spec: () => void): ISuite;
  121. only(description: string, spec: () => void): ISuite;
  122. skip(description: string, spec: () => void): void;
  123. timeout(ms: number): void;
  124. }
  125. interface ITestDefinition {
  126. (expectation: string, assertion?: () => void): ITest;
  127. (expectation: string, assertion?: (done: MochaDone) => void): ITest;
  128. only(expectation: string, assertion?: () => void): ITest;
  129. only(expectation: string, assertion?: (done: MochaDone) => void): ITest;
  130. skip(expectation: string, assertion?: () => void): void;
  131. skip(expectation: string, assertion?: (done: MochaDone) => void): void;
  132. timeout(ms: number): void;
  133. }
  134. export module reporters {
  135. export class Base {
  136. stats: {
  137. suites: number;
  138. tests: number;
  139. passes: number;
  140. pending: number;
  141. failures: number;
  142. };
  143. constructor(runner: IRunner);
  144. }
  145. export class Doc extends Base {}
  146. export class Dot extends Base {}
  147. export class HTML extends Base {}
  148. export class HTMLCov extends Base {}
  149. export class JSON extends Base {}
  150. export class JSONCov extends Base {}
  151. export class JSONStream extends Base {}
  152. export class Landing extends Base {}
  153. export class List extends Base {}
  154. export class Markdown extends Base {}
  155. export class Min extends Base {}
  156. export class Nyan extends Base {}
  157. export class Progress extends Base {
  158. /**
  159. * @param options.open String used to indicate the start of the progress bar.
  160. * @param options.complete String used to indicate a complete test on the progress bar.
  161. * @param options.incomplete String used to indicate an incomplete test on the progress bar.
  162. * @param options.close String used to indicate the end of the progress bar.
  163. */
  164. constructor(runner: IRunner, options?: {
  165. open?: string;
  166. complete?: string;
  167. incomplete?: string;
  168. close?: string;
  169. });
  170. }
  171. export class Spec extends Base {}
  172. export class TAP extends Base {}
  173. export class XUnit extends Base {
  174. constructor(runner: IRunner, options?: any);
  175. }
  176. }
  177. }
  178. declare module "mocha" {
  179. export = Mocha;
  180. }