mocha.d.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. /** Enables growl support. */
  76. growl(): Mocha;
  77. globals(value: string): Mocha;
  78. globals(values: string[]): Mocha;
  79. useColors(value: boolean): Mocha;
  80. useInlineDiffs(value: boolean): Mocha;
  81. timeout(value: number): Mocha;
  82. slow(value: number): Mocha;
  83. enableTimeouts(value: boolean): Mocha;
  84. asyncOnly(value: boolean): Mocha;
  85. noHighlighting(value: boolean): Mocha;
  86. /** Runs tests and invokes `onComplete()` when finished. */
  87. run(onComplete?: (failures: number) => void): Mocha.IRunner;
  88. }
  89. // merge the Mocha class declaration with a module
  90. declare module Mocha {
  91. /** Partial interface for Mocha's `Runnable` class. */
  92. interface IRunnable {
  93. title: string;
  94. fn: Function;
  95. async: boolean;
  96. sync: boolean;
  97. timedOut: boolean;
  98. }
  99. /** Partial interface for Mocha's `Suite` class. */
  100. interface ISuite {
  101. parent: ISuite;
  102. title: string;
  103. fullTitle(): string;
  104. }
  105. /** Partial interface for Mocha's `Test` class. */
  106. interface ITest extends IRunnable {
  107. parent: ISuite;
  108. pending: boolean;
  109. fullTitle(): string;
  110. }
  111. /** Partial interface for Mocha's `Runner` class. */
  112. interface IRunner {}
  113. interface IContextDefinition {
  114. (description: string, spec: () => void): ISuite;
  115. only(description: string, spec: () => void): ISuite;
  116. skip(description: string, spec: () => void): void;
  117. timeout(ms: number): void;
  118. }
  119. interface ITestDefinition {
  120. (expectation: string, assertion?: () => void): ITest;
  121. (expectation: string, assertion?: (done: MochaDone) => void): ITest;
  122. only(expectation: string, assertion?: () => void): ITest;
  123. only(expectation: string, assertion?: (done: MochaDone) => void): ITest;
  124. skip(expectation: string, assertion?: () => void): void;
  125. skip(expectation: string, assertion?: (done: MochaDone) => void): void;
  126. timeout(ms: number): void;
  127. }
  128. export module reporters {
  129. export class Base {
  130. stats: {
  131. suites: number;
  132. tests: number;
  133. passes: number;
  134. pending: number;
  135. failures: number;
  136. };
  137. constructor(runner: IRunner);
  138. }
  139. export class Doc extends Base {}
  140. export class Dot extends Base {}
  141. export class HTML extends Base {}
  142. export class HTMLCov extends Base {}
  143. export class JSON extends Base {}
  144. export class JSONCov extends Base {}
  145. export class JSONStream extends Base {}
  146. export class Landing extends Base {}
  147. export class List extends Base {}
  148. export class Markdown extends Base {}
  149. export class Min extends Base {}
  150. export class Nyan extends Base {}
  151. export class Progress extends Base {
  152. /**
  153. * @param options.open String used to indicate the start of the progress bar.
  154. * @param options.complete String used to indicate a complete test on the progress bar.
  155. * @param options.incomplete String used to indicate an incomplete test on the progress bar.
  156. * @param options.close String used to indicate the end of the progress bar.
  157. */
  158. constructor(runner: IRunner, options?: {
  159. open?: string;
  160. complete?: string;
  161. incomplete?: string;
  162. close?: string;
  163. });
  164. }
  165. export class Spec extends Base {}
  166. export class TAP extends Base {}
  167. export class XUnit extends Base {
  168. constructor(runner: IRunner, options?: any);
  169. }
  170. }
  171. }
  172. declare module "mocha" {
  173. export = Mocha;
  174. }