UNPKG

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