index.d.ts 7.7 KB

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