UNPKG

89.8 kBTypeScriptView Raw
1// Type definitions for mocha 8.2
2// Project: https://mochajs.org
3// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid>
4// otiai10 <https://github.com/otiai10>
5// Vadim Macagon <https://github.com/enlight>
6// Andrew Bradley <https://github.com/cspotcode>
7// Dmitrii Sorin <https://github.com/1999>
8// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
9// TypeScript Version: 2.1
10
11/**
12 * Mocha API
13 *
14 * @see https://mochajs.org/api/mocha
15 */
16declare class Mocha {
17 private _growl;
18 private _reporter;
19 private _ui;
20
21 constructor(options?: Mocha.MochaOptions);
22
23 suite: Mocha.Suite;
24 files: string[];
25 options: Mocha.MochaInstanceOptions;
26
27 /**
28 * Add test `file`.
29 *
30 * @see https://mochajs.org/api/mocha#addFile
31 */
32 addFile(file: string): this;
33
34 /**
35 * Enable or disable bailing on the first failure.
36 *
37 * @see https://mochajs.org/api/mocha#bail
38 */
39 bail(bail?: boolean): this;
40
41 /**
42 * Manually dispose this mocha instance. Mark this instance as `disposed` and unable to run more tests.
43 * It also removes function references to tests functions and hooks, so variables trapped in closures can be cleaned by the garbage collector.
44 *
45 * @see https://mochajs.org/api/mocha#dispose
46 */
47 dispose(): void;
48
49 /**
50 * Set reporter to one of the built-in reporters.
51 *
52 * @see https://mochajs.org/api/mocha#reporter
53 */
54 reporter(reporter: Mocha.Reporter, reporterOptions?: any): this;
55
56 /**
57 * Set reporter to the provided constructor, one of the built-in reporters, or loads a reporter
58 * from a module path. Defaults to `"spec"`.
59 *
60 * @see https://mochajs.org/api/mocha#reporter
61 */
62 reporter(reporter?: string | Mocha.ReporterConstructor, reporterOptions?: any): this;
63
64 /**
65 * Set test UI to one of the built-in test interfaces.
66 *
67 * @see https://mochajs.org/api/mocha#ui
68 */
69 ui(name: Mocha.Interface): this;
70
71 /**
72 * Set test UI to one of the built-in test interfaces or loads a test interface from a module
73 * path. Defaults to `"bdd"`.
74 *
75 * @see https://mochajs.org/api/mocha#ui
76 */
77 ui(name?: string): this;
78
79 /**
80 * Escape string and add it to grep as a RegExp.
81 *
82 * @see https://mochajs.org/api/mocha#fgrep
83 */
84 fgrep(str: string): this;
85
86 /**
87 * Add regexp to grep, if `re` is a string it is escaped.
88 *
89 * @see https://mochajs.org/api/mocha#grep
90 */
91 grep(re: string | RegExp): this;
92
93 /**
94 * Invert `.grep()` matches.
95 *
96 * @see https://mochajs.org/api/mocha#invert
97 */
98 invert(): this;
99
100 /**
101 * Enable global leak checking.
102 *
103 * @see https://mochajs.org/api/mocha#checkLeaks
104 */
105 checkLeaks(): this;
106
107 /**
108 * Display long stack-trace on failing
109 *
110 * @see https://mochajs.org/api/mocha#fullTrace
111 */
112 fullTrace(): this;
113
114 /**
115 * Enable growl support.
116 *
117 * @see https://mochajs.org/api/mocha#growl
118 */
119 growl(): this;
120
121 /**
122 * Ignore `globals` array or string.
123 *
124 * @see https://mochajs.org/api/mocha#globals
125 */
126 globals(globals: string | ReadonlyArray<string>): this;
127
128 /**
129 * Set the timeout in milliseconds.
130 *
131 * @see https://mochajs.org/api/mocha#timeout
132 */
133 timeout(timeout: string | number): this;
134
135 /**
136 * Set the number of times to retry failed tests.
137 *
138 * @see https://mochajs.org/api/mocha#retries
139 */
140 retries(n: number): this;
141
142 /**
143 * Set slowness threshold in milliseconds.
144 *
145 * @see https://mochajs.org/api/mocha#slow
146 */
147 slow(slow: string | number): this;
148
149 /**
150 * Makes all tests async (accepting a callback)
151 *
152 * @see https://mochajs.org/api/mocha#asyncOnly.
153 */
154 asyncOnly(): this;
155
156 /**
157 * Disable syntax highlighting (in browser).
158 *
159 * @see https://mochajs.org/api/mocha#noHighlighting
160 */
161 noHighlighting(): this;
162
163 /**
164 * Enable uncaught errors to propagate (in browser).
165 *
166 * @see https://mochajs.org/api/mocha#allowUncaught
167 */
168 allowUncaught(): boolean;
169
170 /**
171 * Delay root suite execution.
172 *
173 * @see https://mochajs.org/api/mocha#delay
174 */
175 delay(): boolean;
176
177 /**
178 * Tests marked only fail the suite
179 *
180 * @see https://mochajs.org/api/mocha#forbidOnly
181 */
182 forbidOnly(): boolean;
183
184 /**
185 * Pending tests and tests marked skip fail the suite
186 *
187 * @see https://mochajs.org/api/mocha#forbidPending
188 */
189 forbidPending(): boolean;
190
191 /**
192 * Run tests and invoke `fn()` when complete.
193 *
194 * Note that `run` relies on Node's `require` to execute
195 * the test interface functions and will be subject to the
196 * cache - if the files are already in the `require` cache,
197 * they will effectively be skipped. Therefore, to run tests
198 * multiple times or to run tests in files that are already
199 * in the `require` cache, make sure to clear them from the
200 * cache first in whichever manner best suits your needs.
201 *
202 * @see https://mochajs.org/api/mocha#run
203 */
204 run(fn?: (failures: number) => void): Mocha.Runner;
205
206 /**
207 * Loads ESM (and CJS) test files asynchronously.
208 *
209 * @see https://mochajs.org/api/mocha#loadFilesAsync
210 */
211 loadFilesAsync(): Promise<void>;
212
213 /**
214 * Load registered files.
215 *
216 * @see https://mochajs.org/api/mocha#loadFiles
217 */
218 protected loadFiles(fn?: () => void): void;
219
220 /**
221 * Unloads `files` from Node's `require` cache.
222 *
223 * This allows required files to be "freshly" reloaded, providing the ability
224 * to reuse a Mocha instance programmatically.
225 * Note: does not clear ESM module files from the cache
226 */
227 unloadFiles(): this;
228
229 /**
230 * Toggles parallel mode.
231 *
232 * Must be run before calling `run`. Changes the `Runner` class to
233 * use; also enables lazy file loading if not already done so.
234 *
235 * @see https://mochajs.org/api/mocha#parallelMode
236 */
237 parallelMode(enabled?: boolean): this;
238
239 /**
240 * Assigns hooks to the root suite.
241 *
242 * @see https://mochajs.org/api/mocha#rootHooks
243 */
244 rootHooks(hooks: Mocha.RootHookObject): this;
245
246 /**
247 * Configures one or more global setup fixtures.
248 * If given no parameters, unsets any previously-set fixtures.
249 *
250 * @see https://mochajs.org/api/mocha#globalSetup
251 */
252 globalSetup: Mocha.HookFunction;
253
254 /**
255 * Configures one or more global teardown fixtures.
256 * If given no parameters, unsets any previously-set fixtures.
257 *
258 * @see https://mochajs.org/api/mocha#globalTeardown
259 */
260 globalTeardown: Mocha.HookFunction;
261
262 /**
263 * Returns `true` if one or more global setup fixtures have been supplied
264 *
265 * @see https://mochajs.org/api/mocha#hasGlobalSetupFixtures
266 */
267 hasGlobalSetupFixtures(): boolean;
268
269 /**
270 * Returns `true` if one or more global teardown fixtures have been supplied
271 *
272 * @see https://mochajs.org/api/mocha#hasGlobalTeardownFixtures
273 */
274 hasGlobalTeardownFixtures(): boolean;
275
276 /**
277 * Toggle execution of any global setup fixture(s)
278 *
279 * @see https://mochajs.org/api/mocha#enableGlobalSetup
280 */
281 enableGlobalSetup(enabled: boolean): this;
282
283 /**
284 * Toggle execution of any global teardown fixture(s)
285 *
286 * @see https://mochajs.org/api/mocha#enableGlobalTeardown
287 */
288 enableGlobalTeardown(enabled: boolean): this;
289}
290
291declare namespace Mocha {
292 namespace utils {
293 /**
294 * Compute a slug from the given `str`.
295 *
296 * @see https://mochajs.org/api/module-utils.html#.slug
297 */
298 function slug(str: string): string;
299
300 /**
301 * Strip the function definition from `str`, and re-indent for pre whitespace.
302 *
303 * @see https://mochajs.org/api/module-utils.html#.clean
304 */
305 function clean(str: string): string;
306
307 /**
308 * Highlight the given string of `js`.
309 */
310 function highlight(js: string): string;
311
312 /**
313 * Takes some variable and asks `Object.prototype.toString()` what it thinks it is.
314 */
315 function type(value: any): string;
316
317 /**
318 * Stringify `value`. Different behavior depending on type of value:
319 *
320 * - If `value` is undefined or null, return `'[undefined]'` or `'[null]'`, respectively.
321 * - If `value` is not an object, function or array, return result of `value.toString()` wrapped in double-quotes.
322 * - If `value` is an *empty* object, function, or array, returns `'{}'`, `'[Function]'`, or `'[]'` respectively.
323 * - If `value` has properties, call canonicalize} on it, then return result of `JSON.stringify()`
324 *
325 * @see https://mochajs.org/api/module-utils.html#.stringify
326 */
327 function stringify(value: any): string;
328
329 /**
330 * Return a new Thing that has the keys in sorted order. Recursive.
331 *
332 * If the Thing...
333 * - has already been seen, return string `'[Circular]'`
334 * - is `undefined`, return string `'[undefined]'`
335 * - is `null`, return value `null`
336 * - is some other primitive, return the value
337 * - is not a primitive or an `Array`, `Object`, or `Function`, return the value of the Thing's `toString()` method
338 * - is a non-empty `Array`, `Object`, or `Function`, return the result of calling this function again.
339 * - is an empty `Array`, `Object`, or `Function`, returns `'[]'`, `'{}'`, or `'[Function]'` respectively.
340 *
341 * @see https://mochajs.org/api/module-utils.html#.canonicalize
342 */
343 function canonicalize(value: any, stack: any[], typeHint: string): any;
344
345 /**
346 * Lookup file names at the given `path`.
347 *
348 * @see https://mochajs.org/api/Mocha.utils.html#.exports.lookupFiles
349 */
350 function lookupFiles(filepath: string, extensions?: string[], recursive?: boolean): string[];
351
352 /**
353 * Generate an undefined error with a message warning the user.
354 *
355 * @see https://mochajs.org/api/module-utils.html#.undefinedError
356 */
357 function undefinedError(): Error;
358
359 /**
360 * Generate an undefined error if `err` is not defined.
361 *
362 * @see https://mochajs.org/api/module-utils.html#.getError
363 */
364 function getError(err: Error | undefined): Error;
365
366 /**
367 * When invoking this function you get a filter function that get the Error.stack as an
368 * input, and return a prettify output. (i.e: strip Mocha and internal node functions from
369 * stack trace).
370 *
371 * @see https://mochajs.org/api/module-utils.html#.stackTraceFilter
372 */
373 function stackTraceFilter(): (stack: string) => string;
374 }
375
376 namespace interfaces {
377 function bdd(suite: Suite): void;
378 function tdd(suite: Suite): void;
379 function qunit(suite: Suite): void;
380 function exports(suite: Suite): void;
381 }
382
383 // #region Test interface augmentations
384
385 interface HookFunction {
386 /**
387 * [bdd, qunit, tdd] Describe a "hook" to execute the given callback `fn`. The name of the
388 * function is used as the name of the hook.
389 *
390 * - _Only available when invoked via the mocha CLI._
391 */
392 (fn: Func): void;
393
394 /**
395 * [bdd, qunit, tdd] Describe a "hook" to execute the given callback `fn`. The name of the
396 * function is used as the name of the hook.
397 *
398 * - _Only available when invoked via the mocha CLI._
399 */
400 (fn: AsyncFunc): void;
401
402 /**
403 * [bdd, qunit, tdd] Describe a "hook" to execute the given `title` and callback `fn`.
404 *
405 * - _Only available when invoked via the mocha CLI._
406 */
407 (name: string, fn?: Func): void;
408
409 /**
410 * [bdd, qunit, tdd] Describe a "hook" to execute the given `title` and callback `fn`.
411 *
412 * - _Only available when invoked via the mocha CLI._
413 */
414 (name: string, fn?: AsyncFunc): void;
415 }
416
417 interface SuiteFunction {
418 /**
419 * [bdd, tdd] Describe a "suite" with the given `title` and callback `fn` containing
420 * nested suites.
421 *
422 * - _Only available when invoked via the mocha CLI._
423 */
424 (title: string, fn: (this: Suite) => void): Suite;
425
426 /**
427 * [qunit] Describe a "suite" with the given `title`.
428 *
429 * - _Only available when invoked via the mocha CLI._
430 */
431 (title: string): Suite;
432
433 /**
434 * [bdd, tdd, qunit] Indicates this suite should be executed exclusively.
435 *
436 * - _Only available when invoked via the mocha CLI._
437 */
438 only: ExclusiveSuiteFunction;
439
440 /**
441 * [bdd, tdd] Indicates this suite should not be executed.
442 *
443 * - _Only available when invoked via the mocha CLI._
444 */
445 skip: PendingSuiteFunction;
446 }
447
448 interface ExclusiveSuiteFunction {
449 /**
450 * [bdd, tdd] Describe a "suite" with the given `title` and callback `fn` containing
451 * nested suites. Indicates this suite should be executed exclusively.
452 *
453 * - _Only available when invoked via the mocha CLI._
454 */
455 (title: string, fn: (this: Suite) => void): Suite;
456
457 /**
458 * [qunit] Describe a "suite" with the given `title`. Indicates this suite should be executed
459 * exclusively.
460 *
461 * - _Only available when invoked via the mocha CLI._
462 */
463 (title: string): Suite;
464 }
465
466 /**
467 * [bdd, tdd] Describe a "suite" with the given `title` and callback `fn` containing
468 * nested suites. Indicates this suite should not be executed.
469 *
470 * - _Only available when invoked via the mocha CLI._
471 *
472 * @returns [bdd] `Suite`
473 * @returns [tdd] `void`
474 */
475 interface PendingSuiteFunction {
476 (title: string, fn: (this: Suite) => void): Suite | void;
477 }
478
479 interface TestFunction {
480 /**
481 * Describe a specification or test-case with the given callback `fn` acting as a thunk.
482 * The name of the function is used as the name of the test.
483 *
484 * - _Only available when invoked via the mocha CLI._
485 */
486 (fn: Func): Test;
487
488 /**
489 * Describe a specification or test-case with the given callback `fn` acting as a thunk.
490 * The name of the function is used as the name of the test.
491 *
492 * - _Only available when invoked via the mocha CLI._
493 */
494 (fn: AsyncFunc): Test;
495
496 /**
497 * Describe a specification or test-case with the given `title` and callback `fn` acting
498 * as a thunk.
499 *
500 * - _Only available when invoked via the mocha CLI._
501 */
502 (title: string, fn?: Func): Test;
503
504 /**
505 * Describe a specification or test-case with the given `title` and callback `fn` acting
506 * as a thunk.
507 *
508 * - _Only available when invoked via the mocha CLI._
509 */
510 (title: string, fn?: AsyncFunc): Test;
511
512 /**
513 * Indicates this test should be executed exclusively.
514 *
515 * - _Only available when invoked via the mocha CLI._
516 */
517 only: ExclusiveTestFunction;
518
519 /**
520 * Indicates this test should not be executed.
521 *
522 * - _Only available when invoked via the mocha CLI._
523 */
524 skip: PendingTestFunction;
525
526 /**
527 * Number of attempts to retry.
528 *
529 * - _Only available when invoked via the mocha CLI._
530 */
531 retries(n: number): void;
532 }
533
534 interface ExclusiveTestFunction {
535 /**
536 * [bdd, tdd, qunit] Describe a specification or test-case with the given callback `fn`
537 * acting as a thunk. The name of the function is used as the name of the test. Indicates
538 * this test should be executed exclusively.
539 *
540 * - _Only available when invoked via the mocha CLI._
541 */
542 (fn: Func): Test;
543
544 /**
545 * [bdd, tdd, qunit] Describe a specification or test-case with the given callback `fn`
546 * acting as a thunk. The name of the function is used as the name of the test. Indicates
547 * this test should be executed exclusively.
548 *
549 * - _Only available when invoked via the mocha CLI._
550 */
551 (fn: AsyncFunc): Test;
552
553 /**
554 * [bdd, tdd, qunit] Describe a specification or test-case with the given `title` and
555 * callback `fn` acting as a thunk. Indicates this test should be executed exclusively.
556 *
557 * - _Only available when invoked via the mocha CLI._
558 */
559 (title: string, fn?: Func): Test;
560
561 /**
562 * [bdd, tdd, qunit] Describe a specification or test-case with the given `title` and
563 * callback `fn` acting as a thunk. Indicates this test should be executed exclusively.
564 *
565 * - _Only available when invoked via the mocha CLI._
566 */
567 (title: string, fn?: AsyncFunc): Test;
568 }
569
570 interface PendingTestFunction {
571 /**
572 * [bdd, tdd, qunit] Describe a specification or test-case with the given callback `fn`
573 * acting as a thunk. The name of the function is used as the name of the test. Indicates
574 * this test should not be executed.
575 *
576 * - _Only available when invoked via the mocha CLI._
577 */
578 (fn: Func): Test;
579
580 /**
581 * [bdd, tdd, qunit] Describe a specification or test-case with the given callback `fn`
582 * acting as a thunk. The name of the function is used as the name of the test. Indicates
583 * this test should not be executed.
584 *
585 * - _Only available when invoked via the mocha CLI._
586 */
587 (fn: AsyncFunc): Test;
588
589 /**
590 * [bdd, tdd, qunit] Describe a specification or test-case with the given `title` and
591 * callback `fn` acting as a thunk. Indicates this test should not be executed.
592 *
593 * - _Only available when invoked via the mocha CLI._
594 */
595 (title: string, fn?: Func): Test;
596
597 /**
598 * [bdd, tdd, qunit] Describe a specification or test-case with the given `title` and
599 * callback `fn` acting as a thunk. Indicates this test should not be executed.
600 *
601 * - _Only available when invoked via the mocha CLI._
602 */
603 (title: string, fn?: AsyncFunc): Test;
604 }
605
606 /**
607 * Execute after each test case.
608 *
609 * - _Only available when invoked via the mocha CLI._
610 *
611 * @see https://mochajs.org/api/global.html#afterEach
612 */
613 let afterEach: HookFunction;
614
615 /**
616 * Execute after running tests.
617 *
618 * - _Only available when invoked via the mocha CLI._
619 *
620 * @see https://mochajs.org/api/global.html#after
621 */
622 let after: HookFunction;
623
624 /**
625 * Execute before each test case.
626 *
627 * - _Only available when invoked via the mocha CLI._
628 *
629 * @see https://mochajs.org/api/global.html#beforeEach
630 */
631 let beforeEach: HookFunction;
632
633 /**
634 * Execute before running tests.
635 *
636 * - _Only available when invoked via the mocha CLI._
637 *
638 * @see https://mochajs.org/api/global.html#before
639 */
640 let before: HookFunction;
641
642 /**
643 * Describe a "suite" containing nested suites and tests.
644 *
645 * - _Only available when invoked via the mocha CLI._
646 */
647 let describe: SuiteFunction;
648
649 /**
650 * Describes a test case.
651 *
652 * - _Only available when invoked via the mocha CLI._
653 */
654 let it: TestFunction;
655
656 /**
657 * Describes a pending test case.
658 *
659 * - _Only available when invoked via the mocha CLI._
660 */
661 let xit: PendingTestFunction;
662
663 /**
664 * Execute before each test case.
665 *
666 * - _Only available when invoked via the mocha CLI._
667 *
668 * @see https://mochajs.org/api/global.html#beforeEach
669 */
670 let setup: HookFunction;
671
672 /**
673 * Execute before running tests.
674 *
675 * - _Only available when invoked via the mocha CLI._
676 *
677 * @see https://mochajs.org/api/global.html#before
678 */
679 let suiteSetup: HookFunction;
680
681 /**
682 * Execute after running tests.
683 *
684 * - _Only available when invoked via the mocha CLI._
685 *
686 * @see https://mochajs.org/api/global.html#after
687 */
688 let suiteTeardown: HookFunction;
689
690 /**
691 * Describe a "suite" containing nested suites and tests.
692 *
693 * - _Only available when invoked via the mocha CLI._
694 */
695 let suite: SuiteFunction;
696
697 /**
698 * Execute after each test case.
699 *
700 * - _Only available when invoked via the mocha CLI._
701 *
702 * @see https://mochajs.org/api/global.html#afterEach
703 */
704 let teardown: HookFunction;
705
706 /**
707 * Describes a test case.
708 *
709 * - _Only available when invoked via the mocha CLI._
710 */
711 let test: TestFunction;
712
713 /**
714 * Triggers root suite execution.
715 *
716 * - _Only available if flag --delay is passed into Mocha._
717 * - _Only available when invoked via the mocha CLI._
718 *
719 * @see https://mochajs.org/api/global.html#runWithSuite
720 */
721 function run(): void;
722
723 // #endregion Test interface augmentations
724
725 namespace reporters {
726 /**
727 * Initialize a new `Base` reporter.
728 *
729 * All other reporters generally inherit from this reporter, providing stats such as test duration,
730 * number of tests passed / failed, etc.
731 *
732 * @see https://mochajs.org/api/Mocha.reporters.Base.html
733 */
734 class Base {
735 constructor(runner: Runner, options?: MochaOptions);
736
737 /**
738 * Test run statistics
739 */
740 stats: Stats;
741
742 /**
743 * Test failures
744 */
745 failures: Test[];
746
747 /**
748 * The configured runner
749 */
750 runner: Runner;
751
752 /**
753 * Output common epilogue used by many of the bundled reporters.
754 *
755 * @see https://mochajs.org/api/Mocha.reporters.Base.html#.Base#epilogue
756 */
757 epilogue(): void;
758
759 done?(failures: number, fn?: (failures: number) => void): void;
760 }
761
762 namespace Base {
763 /**
764 * Enables coloring by default
765 *
766 * @see https://mochajs.org/api/module-base#.useColors
767 */
768 let useColors: boolean;
769
770 /**
771 * Inline diffs instead of +/-
772 *
773 * @see https://mochajs.org/api/module-base#.inlineDiffs
774 */
775 let inlineDiffs: boolean;
776
777 /**
778 * Default color map
779 *
780 * @see https://mochajs.org/api/module-base#.colors
781 */
782 const colors: ColorMap;
783
784 /**
785 * Default color map
786 *
787 * @see https://mochajs.org/api/module-base#.colors
788 */
789 interface ColorMap {
790 // added by Base
791 pass: number;
792 fail: number;
793 "bright pass": number;
794 "bright fail": number;
795 "bright yellow": number;
796 pending: number;
797 suite: number;
798 "error title": number;
799 "error message": number;
800 "error stack": number;
801 checkmark: number;
802 fast: number;
803 medium: number;
804 slow: number;
805 green: number;
806 light: number;
807 "diff gutter": number;
808 "diff added": number;
809 "diff removed": number;
810
811 // added by Progress
812 progress: number;
813
814 // added by Landing
815 plane: number;
816 "plane crash": number;
817 runway: number;
818
819 [key: string]: number;
820 }
821
822 /**
823 * Default symbol map
824 *
825 * @see https://mochajs.org/api/module-base#.symbols
826 */
827 const symbols: SymbolMap;
828
829 /**
830 * Default symbol map
831 *
832 * @see https://mochajs.org/api/module-base#.symbols
833 */
834 interface SymbolMap {
835 ok: string;
836 err: string;
837 dot: string;
838 comma: string;
839 bang: string;
840 [key: string]: string;
841 }
842
843 /**
844 * Color `str` with the given `type` (from `colors`)
845 *
846 * @see https://mochajs.org/api/module-base#.color
847 */
848 function color(type: string, str: string): string;
849
850 /**
851 * Expose terminal window size
852 *
853 * @see https://mochajs.org/api/module-base#.window
854 */
855 const window: {
856 width: number;
857 };
858
859 /**
860 * ANSI TTY control sequences common among reporters.
861 *
862 * @see https://mochajs.org/api/module-base#.cursor
863 */
864 namespace cursor {
865 /**
866 * Hides the cursor
867 */
868 function hide(): void;
869
870 /**
871 * Shows the cursor
872 */
873 function show(): void;
874
875 /**
876 * Deletes the current line
877 */
878 function deleteLine(): void;
879
880 /**
881 * Moves to the beginning of the line
882 */
883 function beginningOfLine(): void;
884
885 /**
886 * Clears the line and moves to the beginning of the line.
887 */
888 function CR(): void;
889 }
890
891 /**
892 * Returns a diff between two strings with colored ANSI output.
893 *
894 * @see https://mochajs.org/api/module-base#.generateDiff
895 */
896 function generateDiff(actual: string, expected: string): string;
897
898 /**
899 * Output the given `failures` as a list.
900 *
901 * @see https://mochajs.org/api/Mocha.reporters.Base.html#.exports.list1
902 */
903 function list(failures: Test[]): void;
904 }
905
906 /**
907 * Initialize a new `Dot` matrix test reporter.
908 *
909 * @see https://mochajs.org/api/Mocha.reporters.Dot.html
910 */
911 class Dot extends Base {
912 }
913
914 /**
915 * Initialize a new `Doc` reporter.
916 *
917 * @see https://mochajs.org/api/Mocha.reporters.Doc.html
918 */
919 class Doc extends Base {
920 }
921
922 /**
923 * Initialize a new `TAP` test reporter.
924 *
925 * @see https://mochajs.org/api/Mocha.reporters.TAP.html
926 */
927 class TAP extends Base {
928 }
929
930 /**
931 * Initialize a new `JSON` reporter
932 *
933 * @see https://mochajs.org/api/Mocha.reporters.JSON.html
934 */
935 class JSON extends Base {
936 }
937
938 /**
939 * Initialize a new `HTML` reporter.
940 *
941 * - _This reporter cannot be used on the console._
942 *
943 * @see https://mochajs.org/api/Mocha.reporters.HTML.html
944 */
945 class HTML extends Base {
946 /**
947 * Provide suite URL.
948 *
949 * @see https://mochajs.org/api/Mocha.reporters.HTML.html#suiteURL
950 */
951 suiteURL(suite: Suite): string;
952
953 /**
954 * Provide test URL.
955 *
956 * @see https://mochajs.org/api/Mocha.reporters.HTML.html#testURL
957 */
958 testURL(test: Test): string;
959
960 /**
961 * Adds code toggle functionality for the provided test's list element.
962 *
963 * @see https://mochajs.org/api/Mocha.reporters.HTML.html#addCodeToggle
964 */
965 addCodeToggle(el: HTMLLIElement, contents: string): void;
966 }
967
968 /**
969 * Initialize a new `List` test reporter.
970 *
971 * @see https://mochajs.org/api/Mocha.reporters.List.html
972 */
973 class List extends Base {
974 }
975
976 /**
977 * Initialize a new `Min` minimal test reporter (best used with --watch).
978 *
979 * @see https://mochajs.org/api/Mocha.reporters.Min.html
980 */
981 class Min extends Base {
982 }
983
984 /**
985 * Initialize a new `Spec` test reporter.
986 *
987 * @see https://mochajs.org/api/Mocha.reporters.Spec.html
988 */
989 class Spec extends Base {
990 }
991
992 /**
993 * Initialize a new `NyanCat` test reporter.
994 *
995 * @see https://mochajs.org/api/Mocha.reporters.Nyan.html
996 */
997 class Nyan extends Base {
998 private colorIndex;
999 private numberOfLines;
1000 private rainbowColors;
1001 private scoreboardWidth;
1002 private tick;
1003 private trajectories;
1004 private trajectoryWidthMax;
1005 private draw;
1006 private drawScoreboard;
1007 private appendRainbow;
1008 private drawRainbow;
1009 private drawNyanCat;
1010 private face;
1011 private cursorUp;
1012 private cursorDown;
1013 private generateColors;
1014 private rainbowify;
1015 }
1016
1017 /**
1018 * Initialize a new `XUnit` test reporter.
1019 *
1020 * @see https://mochajs.org/api/Mocha.reporters.XUnit.html
1021 */
1022 class XUnit extends Base {
1023 constructor(runner: Runner, options?: XUnit.MochaOptions);
1024
1025 /**
1026 * Override done to close the stream (if it's a file).
1027 *
1028 * @see https://mochajs.org/api/Mocha.reporters.XUnit.html#done
1029 */
1030 done(failures: number, fn: (failures: number) => void): void;
1031
1032 /**
1033 * Write out the given line.
1034 *
1035 * @see https://mochajs.org/api/Mocha.reporters.XUnit.html#write
1036 */
1037 write(line: string): void;
1038
1039 /**
1040 * Output tag for the given `test.`
1041 *
1042 * @see https://mochajs.org/api/Mocha.reporters.XUnit.html#test
1043 */
1044 test(test: Test): void;
1045 }
1046
1047 namespace XUnit {
1048 interface MochaOptions extends Mocha.MochaOptions {
1049 reporterOptions?: ReporterOptions;
1050 }
1051
1052 interface ReporterOptions {
1053 output?: string;
1054 suiteName?: string;
1055 }
1056 }
1057
1058 /**
1059 * Initialize a new `Markdown` test reporter.
1060 *
1061 * @see https://mochajs.org/api/Mocha.reporters.Markdown.html
1062 */
1063 class Markdown extends Base {
1064 }
1065
1066 /**
1067 * Initialize a new `Progress` bar test reporter.
1068 *
1069 * @see https://mochajs.org/api/Mocha.reporters.Progress.html
1070 */
1071 class Progress extends Base {
1072 constructor(runner: Runner, options?: Progress.MochaOptions);
1073 }
1074
1075 namespace Progress {
1076 interface MochaOptions extends Mocha.MochaOptions {
1077 reporterOptions?: ReporterOptions;
1078 }
1079
1080 interface ReporterOptions {
1081 open?: string;
1082 complete?: string;
1083 incomplete?: string;
1084 close?: string;
1085 verbose?: boolean;
1086 }
1087 }
1088
1089 /**
1090 * Initialize a new `Landing` reporter.
1091 *
1092 * @see https://mochajs.org/api/Mocha.reporters.Landing.html
1093 */
1094 class Landing extends Base {
1095 }
1096
1097 /**
1098 * Initialize a new `JSONStream` test reporter.
1099 *
1100 * @see https://mochajs.org/api/Mocha.reporters.JSONStream.html
1101 */
1102 class JSONStream extends Base {
1103 }
1104
1105 // value-only aliases
1106 const base: typeof Base;
1107 const dot: typeof Dot;
1108 const doc: typeof Doc;
1109 const tap: typeof TAP;
1110 const json: typeof JSON;
1111 const html: typeof HTML;
1112 const list: typeof List;
1113 const spec: typeof Spec;
1114 const nyan: typeof Nyan;
1115 const xunit: typeof XUnit;
1116 const markdown: typeof Markdown;
1117 const progress: typeof Progress;
1118 const landing: typeof Landing;
1119 // NOTE: not possible to type this correctly:
1120 // const "json-stream": typeof JSONStream;
1121 }
1122
1123 /**
1124 * Initialize a new `Runnable` with the given `title` and callback `fn`.
1125 *
1126 * @see https://mochajs.org/api/Runnable.html
1127 */
1128 class Runnable {
1129 private _slow;
1130 private _retries;
1131 private _currentRetry;
1132 private _timeout;
1133 private _timeoutError;
1134
1135 constructor(title: string, fn?: Func | AsyncFunc);
1136
1137 title: string;
1138 fn: Func | AsyncFunc | undefined;
1139 body: string;
1140 async: boolean;
1141 sync: boolean;
1142 timedOut: boolean;
1143 pending: boolean;
1144 duration?: number;
1145 parent?: Suite;
1146 state?: "failed" | "passed";
1147 timer?: any;
1148 ctx?: Context;
1149 callback?: Done;
1150 allowUncaught?: boolean;
1151 file?: string;
1152
1153 /**
1154 * Get test timeout.
1155 *
1156 * @see https://mochajs.org/api/Runnable.html#timeout
1157 */
1158 timeout(): number;
1159
1160 /**
1161 * Set test timeout.
1162 *
1163 * @see https://mochajs.org/api/Runnable.html#timeout
1164 */
1165 timeout(ms: string | number): this;
1166
1167 /**
1168 * Get test slowness threshold.
1169 *
1170 * @see https://mochajs.org/api/Runnable.html#slow
1171 */
1172 slow(): number;
1173
1174 /**
1175 * Set test slowness threshold.
1176 *
1177 * @see https://mochajs.org/api/Runnable.html#slow
1178 */
1179 slow(ms: string | number): this;
1180
1181 /**
1182 * Halt and mark as pending.
1183 */
1184 skip(): never;
1185
1186 /**
1187 * Check if this runnable or its parent suite is marked as pending.
1188 *
1189 * @see https://mochajs.org/api/Runnable.html#isPending
1190 */
1191 isPending(): boolean;
1192
1193 /**
1194 * Return `true` if this Runnable has failed.
1195 */
1196 isFailed(): boolean;
1197
1198 /**
1199 * Return `true` if this Runnable has passed.
1200 */
1201 isPassed(): boolean;
1202
1203 /**
1204 * Set or get number of retries.
1205 *
1206 * @see https://mochajs.org/api/Runnable.html#retries
1207 */
1208 retries(): number;
1209
1210 /**
1211 * Set or get number of retries.
1212 *
1213 * @see https://mochajs.org/api/Runnable.html#retries
1214 */
1215 retries(n: number): void;
1216
1217 /**
1218 * Set or get current retry
1219 *
1220 * @see https://mochajs.org/api/Runnable.html#currentRetry
1221 */
1222 protected currentRetry(): number;
1223
1224 /**
1225 * Set or get current retry
1226 *
1227 * @see https://mochajs.org/api/Runnable.html#currentRetry
1228 */
1229 protected currentRetry(n: number): void;
1230
1231 /**
1232 * Return the full title generated by recursively concatenating the parent's full title.
1233 */
1234 fullTitle(): string;
1235
1236 /**
1237 * Return the title path generated by concatenating the parent's title path with the title.
1238 */
1239 titlePath(): string[];
1240
1241 /**
1242 * Clear the timeout.
1243 *
1244 * @see https://mochajs.org/api/Runnable.html#clearTimeout
1245 */
1246 clearTimeout(): void;
1247
1248 /**
1249 * Inspect the runnable void of private properties.
1250 *
1251 * @see https://mochajs.org/api/Runnable.html#inspect
1252 */
1253 inspect(): string;
1254
1255 /**
1256 * Reset the timeout.
1257 *
1258 * @see https://mochajs.org/api/Runnable.html#resetTimeout
1259 */
1260 resetTimeout(): void;
1261
1262 /**
1263 * Get a list of whitelisted globals for this test run.
1264 *
1265 * @see https://mochajs.org/api/Runnable.html#globals
1266 */
1267 globals(): string[];
1268
1269 /**
1270 * Set a list of whitelisted globals for this test run.
1271 *
1272 * @see https://mochajs.org/api/Runnable.html#globals
1273 */
1274 globals(globals: ReadonlyArray<string>): void;
1275
1276 /**
1277 * Run the test and invoke `fn(err)`.
1278 *
1279 * @see https://mochajs.org/api/Runnable.html#run
1280 */
1281 run(fn: Done): void;
1282 }
1283
1284 // #region Runnable "error" event
1285 interface Runnable extends NodeJS.EventEmitter {
1286 on(event: "error", listener: (error: any) => void): this;
1287 once(event: "error", listener: (error: any) => void): this;
1288 addListener(event: "error", listener: (error: any) => void): this;
1289 removeListener(event: "error", listener: (error: any) => void): this;
1290 prependListener(event: "error", listener: (error: any) => void): this;
1291 prependOnceListener(event: "error", listener: (error: any) => void): this;
1292 emit(name: "error", error: any): boolean;
1293 }
1294 // #endregion Runnable "error" event
1295 // #region Runnable untyped events
1296 interface Runnable extends NodeJS.EventEmitter {
1297 on(event: string, listener: (...args: any[]) => void): this;
1298 once(event: string, listener: (...args: any[]) => void): this;
1299 addListener(event: string, listener: (...args: any[]) => void): this;
1300 removeListener(event: string, listener: (...args: any[]) => void): this;
1301 prependListener(event: string, listener: (...args: any[]) => void): this;
1302 prependOnceListener(event: string, listener: (...args: any[]) => void): this;
1303 emit(name: string, ...args: any[]): boolean;
1304 }
1305 // #endregion Runnable untyped events
1306
1307 /**
1308 * Test context
1309 *
1310 * @see https://mochajs.org/api/module-Context.html#~Context
1311 */
1312 class Context {
1313 private _runnable;
1314
1315 test?: Runnable;
1316 currentTest?: Test;
1317
1318 /**
1319 * Get the context `Runnable`.
1320 */
1321 runnable(): Runnable;
1322
1323 /**
1324 * Set the context `Runnable`.
1325 */
1326 runnable(runnable: Runnable): this;
1327
1328 /**
1329 * Get test timeout.
1330 */
1331 timeout(): number;
1332
1333 /**
1334 * Set test timeout.
1335 */
1336 timeout(ms: string | number): this;
1337
1338 /**
1339 * Get test slowness threshold.
1340 */
1341 slow(): number;
1342
1343 /**
1344 * Set test slowness threshold.
1345 */
1346 slow(ms: string | number): this;
1347
1348 /**
1349 * Mark a test as skipped.
1350 */
1351 skip(): never;
1352
1353 /**
1354 * Get the number of allowed retries on failed tests.
1355 */
1356 retries(): number;
1357
1358 /**
1359 * Set the number of allowed retries on failed tests.
1360 */
1361 retries(n: number): this;
1362
1363 [key: string]: any;
1364 }
1365
1366 interface RunnerConstants {
1367 readonly EVENT_HOOK_BEGIN: 'hook';
1368 readonly EVENT_HOOK_END: 'hook end';
1369 readonly EVENT_RUN_BEGIN: 'start';
1370 readonly EVENT_DELAY_BEGIN: 'waiting';
1371 readonly EVENT_DELAY_END: 'ready';
1372 readonly EVENT_RUN_END: 'end';
1373 readonly EVENT_SUITE_BEGIN: 'suite';
1374 readonly EVENT_SUITE_END: 'suite end';
1375 readonly EVENT_TEST_BEGIN: 'test';
1376 readonly EVENT_TEST_END: 'test end';
1377 readonly EVENT_TEST_FAIL: 'fail';
1378 readonly EVENT_TEST_PASS: 'pass';
1379 readonly EVENT_TEST_PENDING: 'pending';
1380 readonly EVENT_TEST_RETRY: 'retry';
1381 readonly STATE_IDLE: 'idle';
1382 readonly STATE_RUNNING: 'running';
1383 readonly STATE_STOPPED: 'stopped';
1384 }
1385
1386 /**
1387 * Initialize a `Runner` for the given `suite`.
1388 *
1389 * @see https://mochajs.org/api/Mocha.Runner.html
1390 */
1391 class Runner {
1392 private _globals;
1393 private _abort;
1394 private _delay;
1395 private _defaultGrep;
1396 private next;
1397 private hookErr;
1398 private prevGlobalsLength;
1399 private nextSuite;
1400
1401 static readonly constants: RunnerConstants;
1402
1403 constructor(suite: Suite, delay: boolean);
1404
1405 suite: Suite;
1406 started: boolean;
1407 total: number;
1408 failures: number;
1409 asyncOnly?: boolean;
1410 allowUncaught?: boolean;
1411 fullStackTrace?: boolean;
1412 forbidOnly?: boolean;
1413 forbidPending?: boolean;
1414 checkLeaks?: boolean;
1415 test?: Test;
1416 currentRunnable?: Runnable;
1417 stats?: Stats; // added by reporters
1418
1419 /**
1420 * Removes all event handlers set during a run on this instance.
1421 * Remark: this does *not* clean/dispose the tests or suites themselves.
1422 *
1423 * @see https://mochajs.org/api/runner#dispose
1424 */
1425 dispose(): void;
1426
1427 /**
1428 * Run tests with full titles matching `re`. Updates runner.total
1429 * with number of tests matched.
1430 *
1431 * @see https://mochajs.org/api/Mocha.Runner.html#.Runner#grep
1432 */
1433 grep(re: RegExp, invert: boolean): this;
1434
1435 /**
1436 * Returns the number of tests matching the grep search for the
1437 * given suite.
1438 *
1439 * @see https://mochajs.org/api/Mocha.Runner.html#.Runner#grepTotal
1440 */
1441 grepTotal(suite: Suite): number;
1442
1443 /**
1444 * Gets the allowed globals.
1445 *
1446 * @see https://mochajs.org/api/Mocha.Runner.html#.Runner#globals
1447 */
1448 globals(): string[];
1449
1450 /**
1451 * Allow the given `arr` of globals.
1452 *
1453 * @see https://mochajs.org/api/Mocha.Runner.html#.Runner#globals
1454 */
1455 globals(arr: ReadonlyArray<string>): this;
1456
1457 /**
1458 * Run the root suite and invoke `fn(failures)` on completion.
1459 *
1460 * @see https://mochajs.org/api/Mocha.Runner.html#.Runner#run
1461 */
1462 run(fn?: (failures: number) => void): this;
1463
1464 /**
1465 * Cleanly abort execution.
1466 *
1467 * @see https://mochajs.org/api/Mocha.Runner.html#.Runner#abort
1468 */
1469 abort(): this;
1470
1471 /**
1472 * Handle uncaught exceptions.
1473 *
1474 * @see https://mochajs.org/api/Mocha.Runner.html#uncaught
1475 */
1476 uncaught(err: any): void;
1477
1478 /**
1479 * Wrapper for setImmediate, process.nextTick, or browser polyfill.
1480 */
1481 protected static immediately(callback: Function): void;
1482
1483 /**
1484 * Return a list of global properties.
1485 *
1486 * @see https://mochajs.org/api/Mocha.Runner.html#globalProps
1487 */
1488 protected globalProps(): string[];
1489
1490 /**
1491 * Check for global variable leaks.
1492 *
1493 * @see https://mochajs.org/api/Mocha.Runner.html#checkGlobals
1494 */
1495 protected checkGlobals(test: Test): void;
1496
1497 /**
1498 * Fail the given `test`.
1499 *
1500 * @see https://mochajs.org/api/Mocha.Runner.html#fail
1501 */
1502 protected fail(test: Test, err: any): void;
1503
1504 /**
1505 * Fail the given `hook` with `err`.
1506 *
1507 * Hook failures work in the following pattern:
1508 * - If bail, then exit
1509 * - Failed `before` hook skips all tests in a suite and subsuites,
1510 * but jumps to corresponding `after` hook
1511 * - Failed `before each` hook skips remaining tests in a
1512 * suite and jumps to corresponding `after each` hook,
1513 * which is run only once
1514 * - Failed `after` hook does not alter
1515 * execution order
1516 * - Failed `after each` hook skips remaining tests in a
1517 * suite and subsuites, but executes other `after each`
1518 * hooks
1519 *
1520 * @see https://mochajs.org/api/Mocha.Runner.html#failHook
1521 */
1522 protected failHook(hook: Hook, err: any): void;
1523
1524 /**
1525 * Run hook `name` callbacks and then invoke `fn()`.
1526 *
1527 * @see https://mochajs.org/api/Mocha.Runner.html#hook
1528 */
1529 protected hook(name: string, fn: () => void): void;
1530
1531 /**
1532 * Run hook `name` for the given array of `suites`
1533 * in order, and callback `fn(err, errSuite)`.
1534 *
1535 * @see https://mochajs.org/api/Mocha.Runner.html#hooks
1536 */
1537 protected hooks(name: string, suites: Suite[], fn: (err?: any, errSuite?: Suite) => void): void;
1538
1539 /**
1540 * Run hooks from the top level down.
1541 *
1542 * @see https://mochajs.org/api/Mocha.Runner.html#hookUp
1543 */
1544 protected hookUp(name: string, fn: (err?: any, errSuite?: Suite) => void): void;
1545
1546 /**
1547 * Run hooks from the bottom up.
1548 *
1549 * @see https://mochajs.org/api/Mocha.Runner.html#hookDown
1550 */
1551 protected hookDown(name: string, fn: (err?: any, errSuite?: Suite) => void): void;
1552
1553 /**
1554 * Return an array of parent Suites from closest to furthest.
1555 *
1556 * @see https://mochajs.org/api/Mocha.Runner.html#parents
1557 */
1558 protected parents(): Suite[];
1559
1560 /**
1561 * Run the current test and callback `fn(err)`.
1562 *
1563 * @see https://mochajs.org/api/Mocha.Runner.html#runTest
1564 */
1565 protected runTest(fn: Done): any;
1566
1567 /**
1568 * Run tests in the given `suite` and invoke the callback `fn()` when complete.
1569 *
1570 * @see https://mochajs.org/api/Mocha.Runner.html#runTests
1571 */
1572 protected runTests(suite: Suite, fn: (errSuite?: Suite) => void): void;
1573
1574 /**
1575 * Run the given `suite` and invoke the callback `fn()` when complete.
1576 *
1577 * @see https://mochajs.org/api/Mocha.Runner.html#runSuite
1578 */
1579 protected runSuite(suite: Suite, fn: (errSuite?: Suite) => void): void;
1580 }
1581
1582 // #region Runner "waiting" event
1583 interface Runner {
1584 on(event: "waiting", listener: (rootSuite: Suite) => void): this;
1585 once(event: "waiting", listener: (rootSuite: Suite) => void): this;
1586 addListener(event: "waiting", listener: (rootSuite: Suite) => void): this;
1587 removeListener(event: "waiting", listener: (rootSuite: Suite) => void): this;
1588 prependListener(event: "waiting", listener: (rootSuite: Suite) => void): this;
1589 prependOnceListener(event: "waiting", listener: (rootSuite: Suite) => void): this;
1590 emit(name: "waiting", rootSuite: Suite): boolean;
1591 }
1592 // #endregion Runner "waiting" event
1593 // #region Runner "start" event
1594 interface Runner extends NodeJS.EventEmitter {
1595 on(event: "start", listener: () => void): this;
1596 once(event: "start", listener: () => void): this;
1597 addListener(event: "start", listener: () => void): this;
1598 removeListener(event: "start", listener: () => void): this;
1599 prependListener(event: "start", listener: () => void): this;
1600 prependOnceListener(event: "start", listener: () => void): this;
1601 emit(name: "start"): boolean;
1602 }
1603 // #endregion Runner "start" event
1604 // #region Runner "end" event
1605 interface Runner extends NodeJS.EventEmitter {
1606 on(event: "end", listener: () => void): this;
1607 once(event: "end", listener: () => void): this;
1608 addListener(event: "end", listener: () => void): this;
1609 removeListener(event: "end", listener: () => void): this;
1610 prependListener(event: "end", listener: () => void): this;
1611 prependOnceListener(event: "end", listener: () => void): this;
1612 emit(name: "end"): boolean;
1613 }
1614 // #endregion Runner "end" event
1615 // #region Runner "suite" event
1616 interface Runner extends NodeJS.EventEmitter {
1617 on(event: "suite", listener: (suite: Suite) => void): this;
1618 once(event: "suite", listener: (suite: Suite) => void): this;
1619 addListener(event: "suite", listener: (suite: Suite) => void): this;
1620 removeListener(event: "suite", listener: (suite: Suite) => void): this;
1621 prependListener(event: "suite", listener: (suite: Suite) => void): this;
1622 prependOnceListener(event: "suite", listener: (suite: Suite) => void): this;
1623 emit(name: "suite", suite: Suite): boolean;
1624 }
1625 // #endregion Runner "suite" event
1626 // #region Runner "suite end" event
1627 interface Runner extends NodeJS.EventEmitter {
1628 on(event: "suite end", listener: (suite: Suite) => void): this;
1629 once(event: "suite end", listener: (suite: Suite) => void): this;
1630 addListener(event: "suite end", listener: (suite: Suite) => void): this;
1631 removeListener(event: "suite end", listener: (suite: Suite) => void): this;
1632 prependListener(event: "suite end", listener: (suite: Suite) => void): this;
1633 prependOnceListener(event: "suite end", listener: (suite: Suite) => void): this;
1634 emit(name: "suite end", suite: Suite): boolean;
1635 }
1636 // #endregion Runner "suite end" event
1637 // #region Runner "test" event
1638 interface Runner extends NodeJS.EventEmitter {
1639 on(event: "test", listener: (test: Test) => void): this;
1640 once(event: "test", listener: (test: Test) => void): this;
1641 addListener(event: "test", listener: (test: Test) => void): this;
1642 removeListener(event: "test", listener: (test: Test) => void): this;
1643 prependListener(event: "test", listener: (test: Test) => void): this;
1644 prependOnceListener(event: "test", listener: (test: Test) => void): this;
1645 emit(name: "test", test: Test): boolean;
1646 }
1647 // #endregion Runner "test" event
1648 // #region Runner "test end" event
1649 interface Runner extends NodeJS.EventEmitter {
1650 on(event: "test end", listener: (test: Test) => void): this;
1651 once(event: "test end", listener: (test: Test) => void): this;
1652 addListener(event: "test end", listener: (test: Test) => void): this;
1653 removeListener(event: "test end", listener: (test: Test) => void): this;
1654 prependListener(event: "test end", listener: (test: Test) => void): this;
1655 prependOnceListener(event: "test end", listener: (test: Test) => void): this;
1656 emit(name: "test end", test: Test): boolean;
1657 }
1658 // #endregion Runner "test end" event
1659 // #region Runner "hook" event
1660 interface Runner extends NodeJS.EventEmitter {
1661 on(event: "hook", listener: (hook: Hook) => void): this;
1662 once(event: "hook", listener: (hook: Hook) => void): this;
1663 addListener(event: "hook", listener: (hook: Hook) => void): this;
1664 removeListener(event: "hook", listener: (hook: Hook) => void): this;
1665 prependListener(event: "hook", listener: (hook: Hook) => void): this;
1666 prependOnceListener(event: "hook", listener: (hook: Hook) => void): this;
1667 emit(name: "hook", hook: Hook): boolean;
1668 }
1669 // #endregion Runner "hook" event
1670 // #region Runner "hook end" event
1671 interface Runner extends NodeJS.EventEmitter {
1672 on(event: "hook end", listener: (hook: Hook) => void): this;
1673 once(event: "hook end", listener: (hook: Hook) => void): this;
1674 addListener(event: "hook end", listener: (hook: Hook) => void): this;
1675 removeListener(event: "hook end", listener: (hook: Hook) => void): this;
1676 prependListener(event: "hook end", listener: (hook: Hook) => void): this;
1677 prependOnceListener(event: "hook end", listener: (hook: Hook) => void): this;
1678 emit(name: "hook end", hook: Hook): boolean;
1679 }
1680 // #endregion Runner "hook end" event
1681 // #region Runner "pass" event
1682 interface Runner extends NodeJS.EventEmitter {
1683 on(event: "pass", listener: (test: Test) => void): this;
1684 once(event: "pass", listener: (test: Test) => void): this;
1685 addListener(event: "pass", listener: (test: Test) => void): this;
1686 removeListener(event: "pass", listener: (test: Test) => void): this;
1687 prependListener(event: "pass", listener: (test: Test) => void): this;
1688 prependOnceListener(event: "pass", listener: (test: Test) => void): this;
1689 emit(name: "pass", test: Test): boolean;
1690 }
1691 // #endregion Runner "pass" event
1692 // #region Runner "fail" event
1693 interface Runner extends NodeJS.EventEmitter {
1694 on(event: "fail", listener: (test: Test, err: any) => void): this;
1695 once(event: "fail", listener: (test: Test, err: any) => void): this;
1696 addListener(event: "fail", listener: (test: Test, err: any) => void): this;
1697 removeListener(event: "fail", listener: (test: Test, err: any) => void): this;
1698 prependListener(event: "fail", listener: (test: Test, err: any) => void): this;
1699 prependOnceListener(event: "fail", listener: (test: Test, err: any) => void): this;
1700 emit(name: "fail", test: Test, err: any): boolean;
1701 }
1702 // #endregion Runner "fail" event
1703 // #region Runner "pending" event
1704 interface Runner extends NodeJS.EventEmitter {
1705 on(event: "pending", listener: (test: Test) => void): this;
1706 once(event: "pending", listener: (test: Test) => void): this;
1707 addListener(event: "pending", listener: (test: Test) => void): this;
1708 removeListener(event: "pending", listener: (test: Test) => void): this;
1709 prependListener(event: "pending", listener: (test: Test) => void): this;
1710 prependOnceListener(event: "pending", listener: (test: Test) => void): this;
1711 emit(name: "pending", test: Test): boolean;
1712 }
1713 // #endregion Runner "pending" event
1714 // #region Runner untyped events
1715 interface Runner extends NodeJS.EventEmitter {
1716 on(event: string, listener: (...args: any[]) => void): this;
1717 once(event: string, listener: (...args: any[]) => void): this;
1718 addListener(event: string, listener: (...args: any[]) => void): this;
1719 removeListener(event: string, listener: (...args: any[]) => void): this;
1720 prependListener(event: string, listener: (...args: any[]) => void): this;
1721 prependOnceListener(event: string, listener: (...args: any[]) => void): this;
1722 emit(name: string, ...args: any[]): boolean;
1723 }
1724 // #endregion Runner untyped events
1725
1726 interface SuiteConstants {
1727 readonly EVENT_FILE_POST_REQUIRE: 'post-require';
1728 readonly EVENT_FILE_PRE_REQUIRE: 'pre-require';
1729 readonly EVENT_FILE_REQUIRE: 'require';
1730 readonly EVENT_ROOT_SUITE_RUN: 'run';
1731
1732 readonly HOOK_TYPE_AFTER_ALL: 'afterAll';
1733 readonly HOOK_TYPE_AFTER_EACH: 'afterEach';
1734 readonly HOOK_TYPE_BEFORE_ALL: 'beforeAll';
1735 readonly HOOK_TYPE_BEFORE_EACH: 'beforeEach';
1736
1737 readonly EVENT_SUITE_ADD_HOOK_AFTER_ALL: 'afterAll';
1738 readonly EVENT_SUITE_ADD_HOOK_AFTER_EACH: 'afterEach';
1739 readonly EVENT_SUITE_ADD_HOOK_BEFORE_ALL: 'beforeAll';
1740 readonly EVENT_SUITE_ADD_HOOK_BEFORE_EACH: 'beforeEach';
1741 readonly EVENT_SUITE_ADD_SUITE: 'suite';
1742 readonly EVENT_SUITE_ADD_TEST: 'test';
1743 }
1744
1745 /**
1746 * Initialize a new `Suite` with the given `title` and `ctx`.
1747 *
1748 * @see https://mochajs.org/api/Mocha.Suite.html
1749 */
1750 class Suite {
1751 private _beforeEach;
1752 private _beforeAll;
1753 private _afterEach;
1754 private _afterAll;
1755 private _timeout;
1756 private _slow;
1757 private _bail;
1758 private _retries;
1759 private _onlyTests;
1760 private _onlySuites;
1761
1762 static readonly constants: SuiteConstants;
1763
1764 constructor(title: string, parentContext?: Context);
1765
1766 ctx: Context;
1767 suites: Suite[];
1768 tests: Test[];
1769 pending: boolean;
1770 file?: string;
1771 root: boolean;
1772 delayed: boolean;
1773 parent: Suite | undefined;
1774 title: string;
1775
1776 /**
1777 * Create a new `Suite` with the given `title` and parent `Suite`. When a suite
1778 * with the same title is already present, that suite is returned to provide
1779 * nicer reporter and more flexible meta-testing.
1780 *
1781 * @see https://mochajs.org/api/mocha#.exports.create
1782 */
1783 static create(parent: Suite, title: string): Suite;
1784
1785 /**
1786 * Return a clone of this `Suite`.
1787 *
1788 * @see https://mochajs.org/api/Mocha.Suite.html#clone
1789 */
1790 clone(): Suite;
1791
1792 /**
1793 * Get timeout `ms`.
1794 *
1795 * @see https://mochajs.org/api/Mocha.Suite.html#timeout
1796 */
1797 timeout(): number;
1798
1799 /**
1800 * Set timeout `ms` or short-hand such as "2s".
1801 *
1802 * @see https://mochajs.org/api/Mocha.Suite.html#timeout
1803 */
1804 timeout(ms: string | number): this;
1805
1806 /**
1807 * Get number of times to retry a failed test.
1808 *
1809 * @see https://mochajs.org/api/Mocha.Suite.html#retries
1810 */
1811 retries(): number;
1812
1813 /**
1814 * Set number of times to retry a failed test.
1815 *
1816 * @see https://mochajs.org/api/Mocha.Suite.html#retries
1817 */
1818 retries(n: string | number): this;
1819
1820 /**
1821 * Get slow `ms`.
1822 *
1823 * @see https://mochajs.org/api/Mocha.Suite.html#slow
1824 */
1825 slow(): number;
1826
1827 /**
1828 * Set slow `ms` or short-hand such as "2s".
1829 *
1830 * @see https://mochajs.org/api/Mocha.Suite.html#slow
1831 */
1832 slow(ms: string | number): this;
1833
1834 /**
1835 * Get whether to bail after first error.
1836 *
1837 * @see https://mochajs.org/api/Mocha.Suite.html#bail
1838 */
1839 bail(): boolean;
1840
1841 /**
1842 * Set whether to bail after first error.
1843 *
1844 * @see https://mochajs.org/api/Mocha.Suite.html#bail
1845 */
1846 bail(bail: boolean): this;
1847
1848 /**
1849 * Check if this suite or its parent suite is marked as pending.
1850 *
1851 * @see https://mochajs.org/api/Mocha.Suite.html#isPending
1852 */
1853 isPending(): boolean;
1854
1855 /**
1856 * Run `fn(test[, done])` before running tests.
1857 *
1858 * @see https://mochajs.org/api/Mocha.Suite.html#beforeAll
1859 */
1860 beforeAll(fn?: Func): this;
1861
1862 /**
1863 * Run `fn(test[, done])` before running tests.
1864 *
1865 * @see https://mochajs.org/api/Mocha.Suite.html#beforeAll
1866 */
1867 beforeAll(fn?: AsyncFunc): this;
1868
1869 /**
1870 * Run `fn(test[, done])` before running tests.
1871 *
1872 * @see https://mochajs.org/api/Mocha.Suite.html#beforeAll
1873 */
1874 beforeAll(title: string, fn?: Func): this;
1875
1876 /**
1877 * Run `fn(test[, done])` before running tests.
1878 *
1879 * @see https://mochajs.org/api/Mocha.Suite.html#beforeAll
1880 */
1881 beforeAll(title: string, fn?: AsyncFunc): this;
1882
1883 /**
1884 * Run `fn(test[, done])` after running tests.
1885 *
1886 * @see https://mochajs.org/api/Mocha.Suite.html#afterAll
1887 */
1888 afterAll(fn?: Func): this;
1889
1890 /**
1891 * Run `fn(test[, done])` after running tests.
1892 *
1893 * @see https://mochajs.org/api/Mocha.Suite.html#afterAll
1894 */
1895 afterAll(fn?: AsyncFunc): this;
1896
1897 /**
1898 * Run `fn(test[, done])` after running tests.
1899 *
1900 * @see https://mochajs.org/api/Mocha.Suite.html#afterAll
1901 */
1902 afterAll(title: string, fn?: Func): this;
1903
1904 /**
1905 * Run `fn(test[, done])` after running tests.
1906 *
1907 * @see https://mochajs.org/api/Mocha.Suite.html#afterAll
1908 */
1909 afterAll(title: string, fn?: AsyncFunc): this;
1910
1911 /**
1912 * Run `fn(test[, done])` before each test case.
1913 *
1914 * @see https://mochajs.org/api/Mocha.Suite.html#beforeEach
1915 */
1916 beforeEach(fn?: Func): this;
1917
1918 /**
1919 * Run `fn(test[, done])` before each test case.
1920 *
1921 * @see https://mochajs.org/api/Mocha.Suite.html#beforeEach
1922 */
1923 beforeEach(fn?: AsyncFunc): this;
1924
1925 /**
1926 * Run `fn(test[, done])` before each test case.
1927 *
1928 * @see https://mochajs.org/api/Mocha.Suite.html#beforeEach
1929 */
1930 beforeEach(title: string, fn?: Func): this;
1931
1932 /**
1933 * Run `fn(test[, done])` before each test case.
1934 *
1935 * @see https://mochajs.org/api/Mocha.Suite.html#beforeEach
1936 */
1937 beforeEach(title: string, fn?: AsyncFunc): this;
1938
1939 /**
1940 * Run `fn(test[, done])` after each test case.
1941 *
1942 * @see https://mochajs.org/api/Mocha.Suite.html#afterEach
1943 */
1944 afterEach(fn?: Func): this;
1945
1946 /**
1947 * Run `fn(test[, done])` after each test case.
1948 *
1949 * @see https://mochajs.org/api/Mocha.Suite.html#afterEach
1950 */
1951 afterEach(fn?: AsyncFunc): this;
1952
1953 /**
1954 * Run `fn(test[, done])` after each test case.
1955 *
1956 * @see https://mochajs.org/api/Mocha.Suite.html#afterEach
1957 */
1958 afterEach(title: string, fn?: Func): this;
1959
1960 /**
1961 * Run `fn(test[, done])` after each test case.
1962 *
1963 * @see https://mochajs.org/api/Mocha.Suite.html#afterEach
1964 */
1965 afterEach(title: string, fn?: AsyncFunc): this;
1966
1967 /**
1968 * Add a test `suite`.
1969 *
1970 * @see https://mochajs.org/api/Mocha.Suite.html#addSuite
1971 */
1972 addSuite(suite: Suite): this;
1973
1974 /**
1975 * Add a `test` to this suite.
1976 *
1977 * @see https://mochajs.org/api/Mocha.Suite.html#addTest
1978 */
1979 addTest(test: Test): this;
1980
1981 /**
1982 * Cleans all references from this suite and all child suites.
1983 *
1984 * https://mochajs.org/api/suite#dispose
1985 */
1986 dispose(): void;
1987
1988 /**
1989 * Return the full title generated by recursively concatenating the parent's
1990 * full title.
1991 *
1992 * @see https://mochajs.org/api/Mocha.Suite.html#.Suite#fullTitle
1993 */
1994 fullTitle(): string;
1995
1996 /**
1997 * Return the title path generated by recursively concatenating the parent's
1998 * title path.
1999 *
2000 * @see https://mochajs.org/api/Mocha.Suite.html#.Suite#titlePath
2001 */
2002 titlePath(): string[];
2003
2004 /**
2005 * Return the total number of tests.
2006 *
2007 * @see https://mochajs.org/api/Mocha.Suite.html#.Suite#total
2008 */
2009 total(): number;
2010
2011 /**
2012 * Iterates through each suite recursively to find all tests. Applies a
2013 * function in the format `fn(test)`.
2014 *
2015 * @see https://mochajs.org/api/Mocha.Suite.html#eachTest
2016 */
2017 eachTest(fn: (test: Test) => void): this;
2018
2019 /**
2020 * This will run the root suite if we happen to be running in delayed mode.
2021 *
2022 * @see https://mochajs.org/api/Mocha.Suite.html#run
2023 */
2024 run(): void;
2025
2026 /**
2027 * Generic hook-creator.
2028 */
2029 protected _createHook(title: string, fn?: Func | AsyncFunc): Hook;
2030 }
2031
2032 // #region Suite "beforeAll" event
2033 interface Suite extends NodeJS.EventEmitter {
2034 on(event: "beforeAll", listener: (hook: Hook) => void): this;
2035 once(event: "beforeAll", listener: (hook: Hook) => void): this;
2036 addListener(event: "beforeAll", listener: (hook: Hook) => void): this;
2037 removeListener(event: "beforeAll", listener: (hook: Hook) => void): this;
2038 prependListener(event: "beforeAll", listener: (hook: Hook) => void): this;
2039 prependOnceListener(event: "beforeAll", listener: (hook: Hook) => void): this;
2040 emit(name: "beforeAll", hook: Hook): boolean;
2041 }
2042 // #endregion Suite "beforeAll" event
2043 // #region Suite "afterAll" event
2044 interface Suite extends NodeJS.EventEmitter {
2045 on(event: "afterAll", listener: (hook: Hook) => void): this;
2046 once(event: "afterAll", listener: (hook: Hook) => void): this;
2047 addListener(event: "afterAll", listener: (hook: Hook) => void): this;
2048 removeListener(event: "afterAll", listener: (hook: Hook) => void): this;
2049 prependListener(event: "afterAll", listener: (hook: Hook) => void): this;
2050 prependOnceListener(event: "afterAll", listener: (hook: Hook) => void): this;
2051 emit(name: "afterAll", hook: Hook): boolean;
2052 }
2053 // #endregion Suite "afterAll" event
2054 // #region Suite "beforeEach" event
2055 interface Suite extends NodeJS.EventEmitter {
2056 on(event: "beforeEach", listener: (hook: Hook) => void): this;
2057 once(event: "beforeEach", listener: (hook: Hook) => void): this;
2058 addListener(event: "beforeEach", listener: (hook: Hook) => void): this;
2059 removeListener(event: "beforeEach", listener: (hook: Hook) => void): this;
2060 prependListener(event: "beforeEach", listener: (hook: Hook) => void): this;
2061 prependOnceListener(event: "beforeEach", listener: (hook: Hook) => void): this;
2062 emit(name: "beforeEach", hook: Hook): boolean;
2063 }
2064 // #endregion Suite "beforeEach" event
2065 // #region Suite "afterEach" event
2066 interface Suite extends NodeJS.EventEmitter {
2067 on(event: "afterEach", listener: (hook: Hook) => void): this;
2068 once(event: "afterEach", listener: (hook: Hook) => void): this;
2069 addListener(event: "afterEach", listener: (hook: Hook) => void): this;
2070 removeListener(event: "afterEach", listener: (hook: Hook) => void): this;
2071 prependListener(event: "afterEach", listener: (hook: Hook) => void): this;
2072 prependOnceListener(event: "afterEach", listener: (hook: Hook) => void): this;
2073 emit(name: "afterEach", hook: Hook): boolean;
2074 }
2075 // #endregion Suite "afterEach" event
2076 // #region Suite "suite" event
2077 interface Suite extends NodeJS.EventEmitter {
2078 on(event: "suite", listener: (suite: Suite) => void): this;
2079 once(event: "suite", listener: (suite: Suite) => void): this;
2080 addListener(event: "suite", listener: (suite: Suite) => void): this;
2081 removeListener(event: "suite", listener: (suite: Suite) => void): this;
2082 prependListener(event: "suite", listener: (suite: Suite) => void): this;
2083 prependOnceListener(event: "suite", listener: (suite: Suite) => void): this;
2084 emit(name: "suite", suite: Suite): boolean;
2085 }
2086 // #endregion Suite "suite" event
2087 // #region Suite "test" event
2088 interface Suite {
2089 on(event: "test", listener: (test: Test) => void): this;
2090 once(event: "test", listener: (test: Test) => void): this;
2091 addListener(event: "test", listener: (test: Test) => void): this;
2092 removeListener(event: "test", listener: (test: Test) => void): this;
2093 prependListener(event: "test", listener: (test: Test) => void): this;
2094 prependOnceListener(event: "test", listener: (test: Test) => void): this;
2095 emit(name: "test", test: Test): boolean;
2096 }
2097 // #endregion Suite "test" event
2098 // #region Suite "run" event
2099 interface Suite extends NodeJS.EventEmitter {
2100 on(event: "run", listener: () => void): this;
2101 once(event: "run", listener: () => void): this;
2102 addListener(event: "run", listener: () => void): this;
2103 removeListener(event: "run", listener: () => void): this;
2104 prependListener(event: "run", listener: () => void): this;
2105 prependOnceListener(event: "run", listener: () => void): this;
2106 emit(name: "run"): boolean;
2107 }
2108 // #endregion Suite "run" event
2109 // #region Suite "pre-require" event
2110 interface Suite extends NodeJS.EventEmitter {
2111 on(event: "pre-require", listener: (context: MochaGlobals, file: string, mocha: Mocha) => void): this;
2112 once(event: "pre-require", listener: (context: MochaGlobals, file: string, mocha: Mocha) => void): this;
2113 addListener(event: "pre-require", listener: (context: MochaGlobals, file: string, mocha: Mocha) => void): this;
2114 removeListener(event: "pre-require", listener: (context: MochaGlobals, file: string, mocha: Mocha) => void): this;
2115 prependListener(event: "pre-require", listener: (context: MochaGlobals, file: string, mocha: Mocha) => void): this;
2116 prependOnceListener(event: "pre-require", listener: (context: MochaGlobals, file: string, mocha: Mocha) => void): this;
2117 emit(name: "pre-require", context: MochaGlobals, file: string, mocha: Mocha): boolean;
2118 }
2119 // #endregion Suite "pre-require" event
2120 // #region Suite "require" event
2121 interface Suite extends NodeJS.EventEmitter {
2122 on(event: "require", listener: (module: any, file: string, mocha: Mocha) => void): this;
2123 once(event: "require", listener: (module: any, file: string, mocha: Mocha) => void): this;
2124 addListener(event: "require", listener: (module: any, file: string, mocha: Mocha) => void): this;
2125 removeListener(event: "require", listener: (module: any, file: string, mocha: Mocha) => void): this;
2126 prependListener(event: "require", listener: (module: any, file: string, mocha: Mocha) => void): this;
2127 prependOnceListener(event: "require", listener: (module: any, file: string, mocha: Mocha) => void): this;
2128 emit(name: "require", module: any, file: string, mocha: Mocha): boolean;
2129 }
2130 // #endregion Suite "require" event
2131 // #region Suite "post-require" event
2132 interface Suite extends NodeJS.EventEmitter {
2133 on(event: "post-require", listener: (context: MochaGlobals, file: string, mocha: Mocha) => void): this;
2134 once(event: "post-require", listener: (context: MochaGlobals, file: string, mocha: Mocha) => void): this;
2135 addListener(event: "post-require", listener: (context: MochaGlobals, file: string, mocha: Mocha) => void): this;
2136 removeListener(event: "post-require", listener: (context: MochaGlobals, file: string, mocha: Mocha) => void): this;
2137 prependListener(event: "post-require", listener: (context: MochaGlobals, file: string, mocha: Mocha) => void): this;
2138 prependOnceListener(event: "post-require", listener: (context: MochaGlobals, file: string, mocha: Mocha) => void): this;
2139 emit(name: "post-require", context: MochaGlobals, file: string, mocha: Mocha): boolean;
2140 }
2141 // #endregion Suite "post-require" event
2142 // #region Suite untyped events
2143 interface Suite extends NodeJS.EventEmitter {
2144 on(event: string, listener: (...args: any[]) => void): this;
2145 once(event: string, listener: (...args: any[]) => void): this;
2146 addListener(event: string, listener: (...args: any[]) => void): this;
2147 removeListener(event: string, listener: (...args: any[]) => void): this;
2148 prependListener(event: string, listener: (...args: any[]) => void): this;
2149 prependOnceListener(event: string, listener: (...args: any[]) => void): this;
2150 emit(name: string, ...args: any[]): boolean;
2151 }
2152 // #endregion Runner untyped events
2153
2154 /**
2155 * Initialize a new `Hook` with the given `title` and callback `fn`
2156 *
2157 * @see https://mochajs.org/api/Hook.html
2158 */
2159 class Hook extends Runnable {
2160 private _error;
2161
2162 type: "hook";
2163 originalTitle?: string; // added by Runner
2164
2165 /**
2166 * Get the test `err`.
2167 *
2168 * @see https://mochajs.org/api/Hook.html#error
2169 */
2170 error(): any;
2171
2172 /**
2173 * Set the test `err`.
2174 *
2175 * @see https://mochajs.org/api/Hook.html#error
2176 */
2177 error(err: any): void;
2178 }
2179
2180 /**
2181 * An alternative way to define root hooks that works with parallel runs.
2182 *
2183 * Root hooks work with any interface, but the property names do not change.
2184 * In other words, if you are using the tdd interface, suiteSetup maps to beforeAll, and setup maps to beforeEach.
2185 *
2186 * As with other hooks, `this` refers to to the current context object.
2187 *
2188 * @see https://mochajs.org/#root-hook-plugins
2189 */
2190 interface RootHookObject {
2191 /**
2192 * In serial mode, run after all tests end, once only.
2193 * In parallel mode, run after all tests end, for each file.
2194 */
2195 afterAll?: Func | AsyncFunc | Func[] | AsyncFunc[];
2196 /**
2197 * In serial mode (Mocha's default), before all tests begin, once only.
2198 * In parallel mode, run before all tests begin, for each file.
2199 */
2200 beforeAll?: Func | AsyncFunc | Func[] | AsyncFunc[];
2201 /**
2202 * In both modes, run after every test.
2203 */
2204 afterEach?: Func | AsyncFunc | Func[] | AsyncFunc[];
2205 /**
2206 * In both modes, run before each test.
2207 */
2208 beforeEach?: Func | AsyncFunc | Func[] | AsyncFunc[];
2209 }
2210
2211 /**
2212 * Initialize a new `Test` with the given `title` and callback `fn`.
2213 *
2214 * @see https://mochajs.org/api/Test.html
2215 */
2216 class Test extends Runnable {
2217 type: "test";
2218 speed?: "slow" | "medium" | "fast"; // added by reporters
2219 err?: Error; // added by reporters
2220 clone(): Test;
2221 }
2222
2223 /**
2224 * Test statistics
2225 */
2226 interface Stats {
2227 suites: number;
2228 tests: number;
2229 passes: number;
2230 pending: number;
2231 failures: number;
2232 start?: Date;
2233 end?: Date;
2234 duration?: number;
2235 }
2236
2237 type TestInterface = (suite: Suite) => void;
2238
2239 interface ReporterConstructor {
2240 new (runner: Runner, options: MochaOptions): reporters.Base;
2241 }
2242
2243 type Done = (err?: any) => void;
2244
2245 /**
2246 * Callback function used for tests and hooks.
2247 */
2248 type Func = (this: Context, done: Done) => void;
2249
2250 /**
2251 * Async callback function used for tests and hooks.
2252 */
2253 type AsyncFunc = (this: Context) => PromiseLike<any>;
2254
2255 /**
2256 * Options to pass to Mocha.
2257 */
2258 interface MochaOptions {
2259 /** Test interfaces ("bdd", "tdd", "exports", etc.). */
2260 ui?: Interface;
2261
2262 /**
2263 * Reporter constructor, built-in reporter name, or reporter module path. Defaults to
2264 * `"spec"`.
2265 */
2266 reporter?: string | ReporterConstructor;
2267
2268 /** Options to pass to the reporter. */
2269 reporterOptions?: any;
2270
2271 /** Array of accepted globals. */
2272 globals?: string[];
2273
2274 /** timeout in milliseconds or time string like '1s'. */
2275 timeout?: number | string;
2276
2277 /** number of times to retry failed tests. */
2278 retries?: number;
2279
2280 /** bail on the first test failure. */
2281 bail?: boolean;
2282
2283 /** milliseconds to wait before considering a test slow. */
2284 slow?: number;
2285
2286 /** check for global variable leaks. */
2287 checkLeaks?: boolean;
2288
2289 /** display the full stack trace on failure. */
2290 fullStackTrace?: boolean;
2291
2292 /** string or regexp to filter tests with. */
2293 grep?: string | RegExp;
2294
2295 /** Enable growl support. */
2296 growl?: boolean;
2297
2298 /** Color TTY output from reporter */
2299 color?: boolean;
2300
2301 /** Use inline diffs rather than +/-. */
2302 inlineDiffs?: boolean;
2303
2304 /** Do not show diffs at all. */
2305 hideDiff?: boolean;
2306
2307 /** Run job in parallel */
2308 parallel?: boolean;
2309
2310 /** Max number of worker processes for parallel runs */
2311 jobs?: number;
2312
2313 /** Assigns hooks to the root suite */
2314 rootHooks?: RootHookObject;
2315
2316 asyncOnly?: boolean;
2317 delay?: boolean;
2318 forbidOnly?: boolean;
2319 forbidPending?: boolean;
2320 noHighlighting?: boolean;
2321 allowUncaught?: boolean;
2322 fullTrace?: boolean;
2323 }
2324
2325 interface MochaInstanceOptions extends MochaOptions {
2326 files?: string[];
2327 }
2328
2329 /**
2330 * Variables added to the global scope by Mocha when run in the CLI.
2331 */
2332 interface MochaGlobals {
2333 /**
2334 * Execute before running tests.
2335 *
2336 * - _Only available when invoked via the mocha CLI._
2337 *
2338 * @see https://mochajs.org/api/global.html#before
2339 */
2340 before: HookFunction;
2341
2342 /**
2343 * Execute after running tests.
2344 *
2345 * - _Only available when invoked via the mocha CLI._
2346 *
2347 * @see https://mochajs.org/api/global.html#after
2348 */
2349 after: HookFunction;
2350
2351 /**
2352 * Execute before each test case.
2353 *
2354 * - _Only available when invoked via the mocha CLI._
2355 *
2356 * @see https://mochajs.org/api/global.html#beforeEach
2357 */
2358 beforeEach: HookFunction;
2359
2360 /**
2361 * Execute after each test case.
2362 *
2363 * - _Only available when invoked via the mocha CLI._
2364 *
2365 * @see https://mochajs.org/api/global.html#afterEach
2366 */
2367 afterEach: HookFunction;
2368
2369 /**
2370 * Describe a "suite" containing nested suites and tests.
2371 *
2372 * - _Only available when invoked via the mocha CLI._
2373 */
2374 describe: SuiteFunction;
2375
2376 /**
2377 * Describe a "suite" containing nested suites and tests.
2378 *
2379 * - _Only available when invoked via the mocha CLI._
2380 */
2381 context: SuiteFunction;
2382
2383 /**
2384 * Pending suite.
2385 *
2386 * - _Only available when invoked via the mocha CLI._
2387 */
2388 xdescribe: PendingSuiteFunction;
2389
2390 /**
2391 * Pending suite.
2392 *
2393 * - _Only available when invoked via the mocha CLI._
2394 */
2395 xcontext: PendingSuiteFunction;
2396
2397 /**
2398 * Describes a test case.
2399 *
2400 * - _Only available when invoked via the mocha CLI._
2401 */
2402 it: TestFunction;
2403
2404 /**
2405 * Describes a test case.
2406 *
2407 * - _Only available when invoked via the mocha CLI._
2408 */
2409 specify: TestFunction;
2410
2411 /**
2412 * Describes a pending test case.
2413 *
2414 * - _Only available when invoked via the mocha CLI._
2415 */
2416 xit: PendingTestFunction;
2417
2418 /**
2419 * Describes a pending test case.
2420 *
2421 * - _Only available when invoked via the mocha CLI._
2422 */
2423 xspecify: PendingTestFunction;
2424
2425 /**
2426 * Execute before running tests.
2427 *
2428 * - _Only available when invoked via the mocha CLI._
2429 *
2430 * @see https://mochajs.org/api/global.html#before
2431 */
2432 suiteSetup: HookFunction;
2433
2434 /**
2435 * Execute after running tests.
2436 *
2437 * - _Only available when invoked via the mocha CLI._
2438 *
2439 * @see https://mochajs.org/api/global.html#after
2440 */
2441 suiteTeardown: HookFunction;
2442
2443 /**
2444 * Execute before each test case.
2445 *
2446 * - _Only available when invoked via the mocha CLI._
2447 *
2448 * @see https://mochajs.org/api/global.html#beforeEach
2449 */
2450 setup: HookFunction;
2451
2452 /**
2453 * Execute after each test case.
2454 *
2455 * - _Only available when invoked via the mocha CLI._
2456 *
2457 * @see https://mochajs.org/api/global.html#afterEach
2458 */
2459 teardown: HookFunction;
2460
2461 /**
2462 * Describe a "suite" containing nested suites and tests.
2463 *
2464 * - _Only available when invoked via the mocha CLI._
2465 */
2466 suite: SuiteFunction;
2467
2468 /**
2469 * Describes a test case.
2470 *
2471 * - _Only available when invoked via the mocha CLI._
2472 */
2473 test: TestFunction;
2474
2475 run: typeof run;
2476 }
2477
2478 /**
2479 * Third-party declarations that want to add new entries to the `Reporter` union can
2480 * contribute names here.
2481 */
2482 interface ReporterContributions {
2483 Base: never;
2484 base: never;
2485 Dot: never;
2486 dot: never;
2487 TAP: never;
2488 tap: never;
2489 JSON: never;
2490 json: never;
2491 HTML: never;
2492 html: never;
2493 List: never;
2494 list: never;
2495 Min: never;
2496 min: never;
2497 Spec: never;
2498 spec: never;
2499 Nyan: never;
2500 nyan: never;
2501 XUnit: never;
2502 xunit: never;
2503 Markdown: never;
2504 markdown: never;
2505 Progress: never;
2506 progress: never;
2507 Landing: never;
2508 landing: never;
2509 JSONStream: never;
2510 "json-stream": never;
2511 }
2512
2513 type Reporter = keyof ReporterContributions;
2514
2515 /**
2516 * Third-party declarations that want to add new entries to the `Interface` union can
2517 * contribute names here.
2518 */
2519 interface InterfaceContributions {
2520 bdd: never;
2521 tdd: never;
2522 qunit: never;
2523 exports: never;
2524 }
2525
2526 type Interface = keyof InterfaceContributions;
2527}
2528
2529// #region Test interface augmentations
2530
2531/**
2532 * Triggers root suite execution.
2533 *
2534 * - _Only available if flag --delay is passed into Mocha._
2535 * - _Only available when invoked via the mocha CLI._
2536 *
2537 * @see https://mochajs.org/api/global.html#runWithSuite
2538 */
2539declare function run(): void;
2540
2541/**
2542 * Execute before running tests.
2543 *
2544 * - _Only available when invoked via the mocha CLI._
2545 *
2546 * @see https://mochajs.org/api/global.html#before
2547 */
2548declare var before: Mocha.HookFunction;
2549
2550/**
2551 * Execute before running tests.
2552 *
2553 * - _Only available when invoked via the mocha CLI._
2554 *
2555 * @see https://mochajs.org/api/global.html#before
2556 */
2557declare var suiteSetup: Mocha.HookFunction;
2558
2559/**
2560 * Execute after running tests.
2561 *
2562 * - _Only available when invoked via the mocha CLI._
2563 *
2564 * @see https://mochajs.org/api/global.html#after
2565 */
2566declare var after: Mocha.HookFunction;
2567
2568/**
2569 * Execute after running tests.
2570 *
2571 * - _Only available when invoked via the mocha CLI._
2572 *
2573 * @see https://mochajs.org/api/global.html#after
2574 */
2575declare var suiteTeardown: Mocha.HookFunction;
2576
2577/**
2578 * Execute before each test case.
2579 *
2580 * - _Only available when invoked via the mocha CLI._
2581 *
2582 * @see https://mochajs.org/api/global.html#beforeEach
2583 */
2584declare var beforeEach: Mocha.HookFunction;
2585
2586/**
2587 * Execute before each test case.
2588 *
2589 * - _Only available when invoked via the mocha CLI._
2590 *
2591 * @see https://mochajs.org/api/global.html#beforeEach
2592 */
2593declare var setup: Mocha.HookFunction;
2594
2595/**
2596 * Execute after each test case.
2597 *
2598 * - _Only available when invoked via the mocha CLI._
2599 *
2600 * @see https://mochajs.org/api/global.html#afterEach
2601 */
2602declare var afterEach: Mocha.HookFunction;
2603
2604/**
2605 * Execute after each test case.
2606 *
2607 * - _Only available when invoked via the mocha CLI._
2608 *
2609 * @see https://mochajs.org/api/global.html#afterEach
2610 */
2611declare var teardown: Mocha.HookFunction;
2612
2613/**
2614 * Describe a "suite" containing nested suites and tests.
2615 *
2616 * - _Only available when invoked via the mocha CLI._
2617 */
2618declare var describe: Mocha.SuiteFunction;
2619
2620/**
2621 * Describe a "suite" containing nested suites and tests.
2622 *
2623 * - _Only available when invoked via the mocha CLI._
2624 */
2625declare var context: Mocha.SuiteFunction;
2626
2627/**
2628 * Describe a "suite" containing nested suites and tests.
2629 *
2630 * - _Only available when invoked via the mocha CLI._
2631 */
2632declare var suite: Mocha.SuiteFunction;
2633
2634/**
2635 * Pending suite.
2636 *
2637 * - _Only available when invoked via the mocha CLI._
2638 */
2639declare var xdescribe: Mocha.PendingSuiteFunction;
2640
2641/**
2642 * Pending suite.
2643 *
2644 * - _Only available when invoked via the mocha CLI._
2645 */
2646declare var xcontext: Mocha.PendingSuiteFunction;
2647
2648/**
2649 * Describes a test case.
2650 *
2651 * - _Only available when invoked via the mocha CLI._
2652 */
2653declare var it: Mocha.TestFunction;
2654
2655/**
2656 * Describes a test case.
2657 *
2658 * - _Only available when invoked via the mocha CLI._
2659 */
2660declare var specify: Mocha.TestFunction;
2661
2662/**
2663 * Describes a test case.
2664 *
2665 * - _Only available when invoked via the mocha CLI._
2666 */
2667declare var test: Mocha.TestFunction;
2668
2669/**
2670 * Describes a pending test case.
2671 *
2672 * - _Only available when invoked via the mocha CLI._
2673 */
2674declare var xit: Mocha.PendingTestFunction;
2675
2676/**
2677 * Describes a pending test case.
2678 *
2679 * - _Only available when invoked via the mocha CLI._
2680 */
2681declare var xspecify: Mocha.PendingTestFunction;
2682
2683// #endregion Test interface augmentations
2684
2685// #region Reporter augmentations
2686
2687// Forward declaration for `HTMLLIElement` from lib.dom.d.ts.
2688// Required by Mocha.reporters.HTML.
2689// NOTE: Mocha *must not* have a direct dependency on DOM types.
2690// tslint:disable-next-line no-empty-interface
2691interface HTMLLIElement { }
2692
2693// Augments the DOM `Window` object when lib.dom.d.ts is loaded.
2694// tslint:disable-next-line no-empty-interface
2695interface Window extends Mocha.MochaGlobals { }
2696
2697declare namespace NodeJS {
2698 // Forward declaration for `NodeJS.EventEmitter` from node.d.ts.
2699 // Required by Mocha.Runnable, Mocha.Runner, and Mocha.Suite.
2700 // NOTE: Mocha *must not* have a direct dependency on @types/node.
2701 // tslint:disable-next-line no-empty-interface
2702 interface EventEmitter { }
2703
2704 // Augments NodeJS's `global` object when node.d.ts is loaded
2705 // tslint:disable-next-line no-empty-interface
2706 interface Global extends Mocha.MochaGlobals { }
2707}
2708
2709// #endregion Reporter augmentations
2710
2711// #region Browser augmentations
2712
2713/**
2714 * Mocha global.
2715 *
2716 * - _Only supported in the browser._
2717 */
2718declare const mocha: BrowserMocha;
2719
2720interface BrowserMocha extends Mocha {
2721 /**
2722 * Function to allow assertion libraries to throw errors directly into mocha.
2723 * This is useful when running tests in a browser because window.onerror will
2724 * only receive the 'message' attribute of the Error.
2725 *
2726 * - _Only supported in the browser._
2727 */
2728 throwError(err: any): never;
2729
2730 /**
2731 * Setup mocha with the given settings options.
2732 *
2733 * - _Only supported in the browser._
2734 */
2735 setup(opts?: Mocha.Interface | Mocha.MochaOptions): this;
2736}
2737
2738// #endregion Browser augmentations
2739
2740declare module "mocha" {
2741 export = Mocha;
2742}
2743
2744declare module "mocha/lib/stats-collector" {
2745 export = createStatsCollector;
2746
2747 /**
2748 * Provides stats such as test duration, number of tests passed / failed etc., by listening for events emitted by `runner`.
2749 */
2750 function createStatsCollector(runner: Mocha.Runner): void;
2751 }
2752
2753declare module "mocha/lib/interfaces/common" {
2754 export = common;
2755
2756 function common(suites: Mocha.Suite[], context: Mocha.MochaGlobals, mocha: Mocha): common.CommonFunctions;
2757
2758 namespace common {
2759 interface CommonFunctions {
2760 /**
2761 * This is only present if flag --delay is passed into Mocha. It triggers
2762 * root suite execution.
2763 */
2764 runWithSuite(suite: Mocha.Suite): () => void;
2765
2766 /**
2767 * Execute before running tests.
2768 */
2769 before(fn?: Mocha.Func | Mocha.AsyncFunc): void;
2770
2771 /**
2772 * Execute before running tests.
2773 */
2774 before(name: string, fn?: Mocha.Func | Mocha.AsyncFunc): void;
2775
2776 /**
2777 * Execute after running tests.
2778 */
2779 after(fn?: Mocha.Func | Mocha.AsyncFunc): void;
2780
2781 /**
2782 * Execute after running tests.
2783 */
2784 after(name: string, fn?: Mocha.Func | Mocha.AsyncFunc): void;
2785
2786 /**
2787 * Execute before each test case.
2788 */
2789 beforeEach(fn?: Mocha.Func | Mocha.AsyncFunc): void;
2790
2791 /**
2792 * Execute before each test case.
2793 */
2794 beforeEach(name: string, fn?: Mocha.Func | Mocha.AsyncFunc): void;
2795
2796 /**
2797 * Execute after each test case.
2798 */
2799 afterEach(fn?: Mocha.Func | Mocha.AsyncFunc): void;
2800
2801 /**
2802 * Execute after each test case.
2803 */
2804 afterEach(name: string, fn?: Mocha.Func | Mocha.AsyncFunc): void;
2805
2806 suite: SuiteFunctions;
2807 test: TestFunctions;
2808 }
2809
2810 interface CreateOptions {
2811 /** Title of suite */
2812 title: string;
2813
2814 /** Suite function */
2815 fn?: (this: Mocha.Suite) => void;
2816
2817 /** Is suite pending? */
2818 pending?: boolean;
2819
2820 /** Filepath where this Suite resides */
2821 file?: string;
2822
2823 /** Is suite exclusive? */
2824 isOnly?: boolean;
2825 }
2826
2827 interface SuiteFunctions {
2828 /**
2829 * Create an exclusive Suite; convenience function
2830 */
2831 only(opts: CreateOptions): Mocha.Suite;
2832
2833 /**
2834 * Create a Suite, but skip it; convenience function
2835 */
2836 skip(opts: CreateOptions): Mocha.Suite;
2837
2838 /**
2839 * Creates a suite.
2840 */
2841 create(opts: CreateOptions): Mocha.Suite;
2842 }
2843
2844 interface TestFunctions {
2845 /**
2846 * Exclusive test-case.
2847 */
2848 only(mocha: Mocha, test: Mocha.Test): Mocha.Test;
2849
2850 /**
2851 * Pending test case.
2852 */
2853 skip(title: string): void;
2854
2855 /**
2856 * Number of retry attempts
2857 */
2858 retries(n: number): void;
2859 }
2860 }
2861}