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