UNPKG

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