UNPKG

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