index.d.ts 7.4 KB

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