index.d.ts 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 var specify: Mocha.ITestDefinition;
  40. declare function before(action: () => void): void;
  41. declare function before(action: (done: MochaDone) => void): void;
  42. declare function before(description: string, action: () => void): void;
  43. declare function before(description: string, action: (done: MochaDone) => void): void;
  44. declare function setup(action: () => void): void;
  45. declare function setup(action: (done: MochaDone) => void): void;
  46. declare function after(action: () => void): void;
  47. declare function after(action: (done: MochaDone) => void): void;
  48. declare function after(description: string, action: () => void): void;
  49. declare function after(description: string, action: (done: MochaDone) => void): void;
  50. declare function teardown(action: () => void): void;
  51. declare function teardown(action: (done: MochaDone) => void): void;
  52. declare function beforeEach(action: () => void): void;
  53. declare function beforeEach(action: (done: MochaDone) => void): void;
  54. declare function beforeEach(description: string, action: () => void): void;
  55. declare function beforeEach(description: string, action: (done: MochaDone) => void): void;
  56. declare function suiteSetup(action: () => void): void;
  57. declare function suiteSetup(action: (done: MochaDone) => void): void;
  58. declare function afterEach(action: () => void): void;
  59. declare function afterEach(action: (done: MochaDone) => void): void;
  60. declare function afterEach(description: string, action: () => void): void;
  61. declare function afterEach(description: string, action: (done: MochaDone) => void): void;
  62. declare function suiteTeardown(action: () => void): void;
  63. declare function suiteTeardown(action: (done: MochaDone) => void): void;
  64. declare class Mocha {
  65. constructor(options?: {
  66. grep?: RegExp;
  67. ui?: string;
  68. reporter?: string;
  69. timeout?: number;
  70. bail?: boolean;
  71. });
  72. /** Setup mocha with the given options. */
  73. setup(options: MochaSetupOptions): Mocha;
  74. bail(value?: boolean): Mocha;
  75. addFile(file: string): Mocha;
  76. /** Sets reporter by name, defaults to "spec". */
  77. reporter(name: string): Mocha;
  78. /** Sets reporter constructor, defaults to mocha.reporters.Spec. */
  79. reporter(reporter: (runner: Mocha.IRunner, options: any) => any): Mocha;
  80. ui(value: string): Mocha;
  81. grep(value: string): Mocha;
  82. grep(value: RegExp): Mocha;
  83. invert(): Mocha;
  84. ignoreLeaks(value: boolean): Mocha;
  85. checkLeaks(): Mocha;
  86. /**
  87. * Function to allow assertion libraries to throw errors directly into mocha.
  88. * This is useful when running tests in a browser because window.onerror will
  89. * only receive the 'message' attribute of the Error.
  90. */
  91. throwError(error: Error): void;
  92. /** Enables growl support. */
  93. growl(): Mocha;
  94. globals(value: string): Mocha;
  95. globals(values: string[]): Mocha;
  96. useColors(value: boolean): Mocha;
  97. useInlineDiffs(value: boolean): Mocha;
  98. timeout(value: number): Mocha;
  99. slow(value: number): Mocha;
  100. enableTimeouts(value: boolean): Mocha;
  101. asyncOnly(value: boolean): Mocha;
  102. noHighlighting(value: boolean): Mocha;
  103. /** Runs tests and invokes `onComplete()` when finished. */
  104. run(onComplete?: (failures: number) => void): Mocha.IRunner;
  105. }
  106. // merge the Mocha class declaration with a module
  107. declare namespace Mocha {
  108. /** Partial interface for Mocha's `Runnable` class. */
  109. interface IRunnable {
  110. title: string;
  111. fn: Function;
  112. async: boolean;
  113. sync: boolean;
  114. timedOut: boolean;
  115. }
  116. /** Partial interface for Mocha's `Suite` class. */
  117. interface ISuite {
  118. parent: ISuite;
  119. title: string;
  120. fullTitle(): string;
  121. }
  122. /** Partial interface for Mocha's `Test` class. */
  123. interface ITest extends IRunnable {
  124. parent: ISuite;
  125. pending: boolean;
  126. fullTitle(): string;
  127. }
  128. /** Partial interface for Mocha's `Runner` class. */
  129. interface IRunner {}
  130. interface IContextDefinition {
  131. (description: string, spec: () => void): ISuite;
  132. only(description: string, spec: () => void): ISuite;
  133. skip(description: string, spec: () => void): void;
  134. timeout(ms: number): void;
  135. }
  136. interface ITestDefinition {
  137. (expectation: string, assertion?: () => void): ITest;
  138. (expectation: string, assertion?: (done: MochaDone) => void): ITest;
  139. only(expectation: string, assertion?: () => void): ITest;
  140. only(expectation: string, assertion?: (done: MochaDone) => void): ITest;
  141. skip(expectation: string, assertion?: () => void): void;
  142. skip(expectation: string, assertion?: (done: MochaDone) => void): void;
  143. timeout(ms: number): void;
  144. }
  145. export module reporters {
  146. export class Base {
  147. stats: {
  148. suites: number;
  149. tests: number;
  150. passes: number;
  151. pending: number;
  152. failures: number;
  153. };
  154. constructor(runner: IRunner);
  155. }
  156. export class Doc extends Base {}
  157. export class Dot extends Base {}
  158. export class HTML extends Base {}
  159. export class HTMLCov extends Base {}
  160. export class JSON extends Base {}
  161. export class JSONCov extends Base {}
  162. export class JSONStream extends Base {}
  163. export class Landing extends Base {}
  164. export class List extends Base {}
  165. export class Markdown extends Base {}
  166. export class Min extends Base {}
  167. export class Nyan extends Base {}
  168. export class Progress extends Base {
  169. /**
  170. * @param options.open String used to indicate the start of the progress bar.
  171. * @param options.complete String used to indicate a complete test on the progress bar.
  172. * @param options.incomplete String used to indicate an incomplete test on the progress bar.
  173. * @param options.close String used to indicate the end of the progress bar.
  174. */
  175. constructor(runner: IRunner, options?: {
  176. open?: string;
  177. complete?: string;
  178. incomplete?: string;
  179. close?: string;
  180. });
  181. }
  182. export class Spec extends Base {}
  183. export class TAP extends Base {}
  184. export class XUnit extends Base {
  185. constructor(runner: IRunner, options?: any);
  186. }
  187. }
  188. }
  189. declare module "mocha" {
  190. export = Mocha;
  191. }