UNPKG

92.3 kBTypeScriptView Raw
1// Type definitions for mocha 9.1
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// nicojs <https://github.com/nicojs>
10// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
11// TypeScript Version: 2.1
12
13/**
14 * Mocha API
15 *
16 * @see https://mochajs.org/api/mocha
17 */
18declare class Mocha {
19 private _growl;
20 private _reporter;
21 private _ui;
22
23 constructor(options?: Mocha.MochaOptions);
24
25 suite: Mocha.Suite;
26 files: string[];
27 options: Mocha.MochaInstanceOptions;
28
29 /**
30 * Add test `file`.
31 *
32 * @see https://mochajs.org/api/mocha#addFile
33 */
34 addFile(file: string): this;
35
36 /**
37 * Enable or disable bailing on the first failure.
38 *
39 * @see https://mochajs.org/api/mocha#bail
40 */
41 bail(bail?: boolean): this;
42
43 /**
44 * Enables or disables whether or not to dispose after each test run.
45 * Disable this to ensure you can run the test suite multiple times.
46 * If disabled, be sure to dispose mocha when you're done to prevent memory leaks.
47 *
48 * @see https://mochajs.org/api/mocha#cleanReferencesAfterRun
49 */
50 cleanReferencesAfterRun(clean?: boolean): this;
51
52 /**
53 * Manually dispose this mocha instance. Mark this instance as `disposed` and unable to run more tests.
54 * It also removes function references to tests functions and hooks, so variables trapped in closures can be cleaned by the garbage collector.
55 *
56 * @see https://mochajs.org/api/mocha#dispose
57 */
58 dispose(): void;
59
60 /**
61 * Set reporter to one of the built-in reporters.
62 *
63 * @see https://mochajs.org/api/mocha#reporter
64 */
65 reporter(reporter: Mocha.Reporter, reporterOptions?: any): this;
66
67 /**
68 * Set reporter to the provided constructor, one of the built-in reporters, or loads a reporter
69 * from a module path. Defaults to `"spec"`.
70 *
71 * @see https://mochajs.org/api/mocha#reporter
72 */
73 reporter(reporter?: string | Mocha.ReporterConstructor, reporterOptions?: any): this;
74
75 /**
76 * Set test UI to one of the built-in test interfaces.
77 *
78 * @see https://mochajs.org/api/mocha#ui
79 */
80 ui(name: Mocha.Interface): this;
81
82 /**
83 * Set test UI to one of the built-in test interfaces or loads a test interface from a module
84 * path. Defaults to `"bdd"`.
85 *
86 * @see https://mochajs.org/api/mocha#ui
87 */
88 ui(name?: string): this;
89
90 /**
91 * Escape string and add it to grep as a RegExp.
92 *
93 * @see https://mochajs.org/api/mocha#fgrep
94 */
95 fgrep(str: string): this;
96
97 /**
98 * Add regexp to grep, if `re` is a string it is escaped.
99 *
100 * @see https://mochajs.org/api/mocha#grep
101 */
102 grep(re: string | RegExp): this;
103
104 /**
105 * Whether to activate dry-run mode.
106 *
107 * @param dryRun Whether to activate dry-run mode. Defaults to `true`.
108 */
109 dryRun(dryRun?: boolean): this;
110
111 /**
112 * Invert `.grep()` matches.
113 *
114 * @see https://mochajs.org/api/mocha#invert
115 */
116 invert(): this;
117
118 /**
119 * Enable global leak checking.
120 *
121 * @see https://mochajs.org/api/mocha#checkLeaks
122 */
123 checkLeaks(): this;
124
125 /**
126 * Display long stack-trace on failing
127 *
128 * @see https://mochajs.org/api/mocha#fullTrace
129 */
130 fullTrace(): this;
131
132 /**
133 * Enable growl support.
134 *
135 * @see https://mochajs.org/api/mocha#growl
136 */
137 growl(): this;
138
139 /**
140 * Ignore `globals` array or string.
141 *
142 * @see https://mochajs.org/api/mocha#globals
143 */
144 globals(globals: string | ReadonlyArray<string>): this;
145
146 /**
147 * Set the timeout in milliseconds.
148 *
149 * @see https://mochajs.org/api/mocha#timeout
150 */
151 timeout(timeout: string | number): this;
152
153 /**
154 * Set the number of times to retry failed tests.
155 *
156 * @see https://mochajs.org/api/mocha#retries
157 */
158 retries(n: number): this;
159
160 /**
161 * Set slowness threshold in milliseconds.
162 *
163 * @see https://mochajs.org/api/mocha#slow
164 */
165 slow(slow: string | number): this;
166
167 /**
168 * Makes all tests async (accepting a callback)
169 *
170 * @see https://mochajs.org/api/mocha#asyncOnly.
171 */
172 asyncOnly(): this;
173
174 /**
175 * Disable syntax highlighting (in browser).
176 *
177 * @see https://mochajs.org/api/mocha#noHighlighting
178 */
179 noHighlighting(): this;
180
181 /**
182 * Enable uncaught errors to propagate (in browser).
183 *
184 * @see https://mochajs.org/api/mocha#allowUncaught
185 */
186 allowUncaught(): boolean;
187
188 /**
189 * Delay root suite execution.
190 *
191 * @see https://mochajs.org/api/mocha#delay
192 */
193 delay(): boolean;
194
195 /**
196 * Tests marked only fail the suite
197 *
198 * @see https://mochajs.org/api/mocha#forbidOnly
199 */
200 forbidOnly(): boolean;
201
202 /**
203 * Pending tests and tests marked skip fail the suite
204 *
205 * @see https://mochajs.org/api/mocha#forbidPending
206 */
207 forbidPending(): boolean;
208
209 /**
210 * Run tests and invoke `fn()` when complete.
211 *
212 * Note that `run` relies on Node's `require` to execute
213 * the test interface functions and will be subject to the
214 * cache - if the files are already in the `require` cache,
215 * they will effectively be skipped. Therefore, to run tests
216 * multiple times or to run tests in files that are already
217 * in the `require` cache, make sure to clear them from the
218 * cache first in whichever manner best suits your needs.
219 *
220 * @see https://mochajs.org/api/mocha#run
221 */
222 run(fn?: (failures: number) => void): Mocha.Runner;
223
224 /**
225 * Loads ESM (and CJS) test files asynchronously.
226 *
227 * @see https://mochajs.org/api/mocha#loadFilesAsync
228 */
229 loadFilesAsync(): Promise<void>;
230
231 /**
232 * Load registered files.
233 *
234 * @see https://mochajs.org/api/mocha#loadFiles
235 */
236 protected loadFiles(fn?: () => void): void;
237
238 /**
239 * Unloads `files` from Node's `require` cache.
240 *
241 * This allows required files to be "freshly" reloaded, providing the ability
242 * to reuse a Mocha instance programmatically.
243 * Note: does not clear ESM module files from the cache
244 */
245 unloadFiles(): this;
246
247 /**
248 * Toggles parallel mode.
249 *
250 * Must be run before calling `run`. Changes the `Runner` class to
251 * use; also enables lazy file loading if not already done so.
252 *
253 * @see https://mochajs.org/api/mocha#parallelMode
254 */
255 parallelMode(enabled?: boolean): this;
256
257 /**
258 * Assigns hooks to the root suite.
259 *
260 * @see https://mochajs.org/api/mocha#rootHooks
261 */
262 rootHooks(hooks: Mocha.RootHookObject): this;
263
264 /**
265 * Configures one or more global setup fixtures.
266 * If given no parameters, unsets any previously-set fixtures.
267 *
268 * @see https://mochajs.org/api/mocha#globalSetup
269 */
270 globalSetup: Mocha.HookFunction;
271
272 /**
273 * Configures one or more global teardown fixtures.
274 * If given no parameters, unsets any previously-set fixtures.
275 *
276 * @see https://mochajs.org/api/mocha#globalTeardown
277 */
278 globalTeardown: Mocha.HookFunction;
279
280 /**
281 * Returns `true` if one or more global setup fixtures have been supplied
282 *
283 * @see https://mochajs.org/api/mocha#hasGlobalSetupFixtures
284 */
285 hasGlobalSetupFixtures(): boolean;
286
287 /**
288 * Returns `true` if one or more global teardown fixtures have been supplied
289 *
290 * @see https://mochajs.org/api/mocha#hasGlobalTeardownFixtures
291 */
292 hasGlobalTeardownFixtures(): boolean;
293
294 /**
295 * Toggle execution of any global setup fixture(s)
296 *
297 * @see https://mochajs.org/api/mocha#enableGlobalSetup
298 */
299 enableGlobalSetup(enabled: boolean): this;
300
301 /**
302 * Toggle execution of any global teardown fixture(s)
303 *
304 * @see https://mochajs.org/api/mocha#enableGlobalTeardown
305 */
306 enableGlobalTeardown(enabled: boolean): this;
307}
308
309declare namespace Mocha {
310 namespace utils {
311 /**
312 * Compute a slug from the given `str`.
313 *
314 * @see https://mochajs.org/api/module-utils.html#.slug
315 */
316 function slug(str: string): string;
317
318 /**
319 * Strip the function definition from `str`, and re-indent for pre whitespace.
320 *
321 * @see https://mochajs.org/api/module-utils.html#.clean
322 */
323 function clean(str: string): string;
324
325 /**
326 * Highlight the given string of `js`.
327 */
328 function highlight(js: string): string;
329
330 /**
331 * Takes some variable and asks `Object.prototype.toString()` what it thinks it is.
332 */
333 function type(value: any): string;
334
335 /**
336 * Stringify `value`. Different behavior depending on type of value:
337 *
338 * - If `value` is undefined or null, return `'[undefined]'` or `'[null]'`, respectively.
339 * - If `value` is not an object, function or array, return result of `value.toString()` wrapped in double-quotes.
340 * - If `value` is an *empty* object, function, or array, returns `'{}'`, `'[Function]'`, or `'[]'` respectively.
341 * - If `value` has properties, call canonicalize} on it, then return result of `JSON.stringify()`
342 *
343 * @see https://mochajs.org/api/module-utils.html#.stringify
344 */
345 function stringify(value: any): string;
346
347 /**
348 * Return a new Thing that has the keys in sorted order. Recursive.
349 *
350 * If the Thing...
351 * - has already been seen, return string `'[Circular]'`
352 * - is `undefined`, return string `'[undefined]'`
353 * - is `null`, return value `null`
354 * - is some other primitive, return the value
355 * - is not a primitive or an `Array`, `Object`, or `Function`, return the value of the Thing's `toString()` method
356 * - is a non-empty `Array`, `Object`, or `Function`, return the result of calling this function again.
357 * - is an empty `Array`, `Object`, or `Function`, returns `'[]'`, `'{}'`, or `'[Function]'` respectively.
358 *
359 * @see https://mochajs.org/api/module-utils.html#.canonicalize
360 */
361 function canonicalize(value: any, stack: any[], typeHint: string): any;
362
363 /**
364 * Generate an undefined error with a message warning the user.
365 *
366 * @see https://mochajs.org/api/module-utils.html#.undefinedError
367 */
368 function undefinedError(): Error;
369
370 /**
371 * Generate an undefined error if `err` is not defined.
372 *
373 * @see https://mochajs.org/api/module-utils.html#.getError
374 */
375 function getError(err: Error | undefined): Error;
376
377 /**
378 * When invoking this function you get a filter function that get the Error.stack as an
379 * input, and return a prettify output. (i.e: strip Mocha and internal node functions from
380 * stack trace).
381 *
382 * @see https://mochajs.org/api/module-utils.html#.stackTraceFilter
383 */
384 function stackTraceFilter(): (stack: string) => string;
385 }
386
387 namespace interfaces {
388 function bdd(suite: Suite): void;
389 function tdd(suite: Suite): void;
390 function qunit(suite: Suite): void;
391 function exports(suite: Suite): void;
392 }
393
394 // #region Test interface augmentations
395
396 interface HookFunction {
397 /**
398 * [bdd, qunit, tdd] Describe a "hook" to execute the given callback `fn`. The name of the
399 * function is used as the name of the hook.
400 *
401 * - _Only available when invoked via the mocha CLI._
402 */
403 (fn: Func): void;
404
405 /**
406 * [bdd, qunit, tdd] Describe a "hook" to execute the given callback `fn`. The name of the
407 * function is used as the name of the hook.
408 *
409 * - _Only available when invoked via the mocha CLI._
410 */
411 (fn: AsyncFunc): void;
412
413 /**
414 * [bdd, qunit, tdd] Describe a "hook" to execute the given `title` and callback `fn`.
415 *
416 * - _Only available when invoked via the mocha CLI._
417 */
418 (name: string, fn?: Func): void;
419
420 /**
421 * [bdd, qunit, tdd] Describe a "hook" to execute the given `title` and callback `fn`.
422 *
423 * - _Only available when invoked via the mocha CLI._
424 */
425 (name: string, fn?: AsyncFunc): void;
426 }
427
428 interface SuiteFunction {
429 /**
430 * [bdd, tdd] Describe a "suite" with the given `title` and callback `fn` containing
431 * nested suites.
432 *
433 * - _Only available when invoked via the mocha CLI._
434 */
435 (title: string, fn: (this: Suite) => void): Suite;
436
437 /**
438 * [qunit] Describe a "suite" with the given `title`.
439 *
440 * - _Only available when invoked via the mocha CLI._
441 */
442 (title: string): Suite;
443
444 /**
445 * [bdd, tdd, qunit] Indicates this suite should be executed exclusively.
446 *
447 * - _Only available when invoked via the mocha CLI._
448 */
449 only: ExclusiveSuiteFunction;
450
451 /**
452 * [bdd, tdd] Indicates this suite should not be executed.
453 *
454 * - _Only available when invoked via the mocha CLI._
455 */
456 skip: PendingSuiteFunction;
457 }
458
459 interface ExclusiveSuiteFunction {
460 /**
461 * [bdd, tdd] Describe a "suite" with the given `title` and callback `fn` containing
462 * nested suites. Indicates this suite should be executed exclusively.
463 *
464 * - _Only available when invoked via the mocha CLI._
465 */
466 (title: string, fn: (this: Suite) => void): Suite;
467
468 /**
469 * [qunit] Describe a "suite" with the given `title`. Indicates this suite should be executed
470 * exclusively.
471 *
472 * - _Only available when invoked via the mocha CLI._
473 */
474 (title: string): Suite;
475 }
476
477 /**
478 * [bdd, tdd] Describe a "suite" with the given `title` and callback `fn` containing
479 * nested suites. Indicates this suite should not be executed.
480 *
481 * - _Only available when invoked via the mocha CLI._
482 *
483 * @returns [bdd] `Suite`
484 * @returns [tdd] `void`
485 */
486 interface PendingSuiteFunction {
487 (title: string, fn: (this: Suite) => void): Suite | void;
488 }
489
490 interface TestFunction {
491 /**
492 * Describe a specification or test-case with the given callback `fn` acting as a thunk.
493 * The name of the function is used as the name of the test.
494 *
495 * - _Only available when invoked via the mocha CLI._
496 */
497 (fn: Func): Test;
498
499 /**
500 * Describe a specification or test-case with the given callback `fn` acting as a thunk.
501 * The name of the function is used as the name of the test.
502 *
503 * - _Only available when invoked via the mocha CLI._
504 */
505 (fn: AsyncFunc): Test;
506
507 /**
508 * Describe a specification or test-case with the given `title` and callback `fn` acting
509 * as a thunk.
510 *
511 * - _Only available when invoked via the mocha CLI._
512 */
513 (title: string, fn?: Func): Test;
514
515 /**
516 * Describe a specification or test-case with the given `title` and callback `fn` acting
517 * as a thunk.
518 *
519 * - _Only available when invoked via the mocha CLI._
520 */
521 (title: string, fn?: AsyncFunc): Test;
522
523 /**
524 * Indicates this test should be executed exclusively.
525 *
526 * - _Only available when invoked via the mocha CLI._
527 */
528 only: ExclusiveTestFunction;
529
530 /**
531 * Indicates this test should not be executed.
532 *
533 * - _Only available when invoked via the mocha CLI._
534 */
535 skip: PendingTestFunction;
536
537 /**
538 * Number of attempts to retry.
539 *
540 * - _Only available when invoked via the mocha CLI._
541 */
542 retries(n: number): void;
543 }
544
545 interface ExclusiveTestFunction {
546 /**
547 * [bdd, tdd, qunit] Describe a specification or test-case with the given callback `fn`
548 * acting as a thunk. The name of the function is used as the name of the test. Indicates
549 * this test should be executed exclusively.
550 *
551 * - _Only available when invoked via the mocha CLI._
552 */
553 (fn: Func): Test;
554
555 /**
556 * [bdd, tdd, qunit] Describe a specification or test-case with the given callback `fn`
557 * acting as a thunk. The name of the function is used as the name of the test. Indicates
558 * this test should be executed exclusively.
559 *
560 * - _Only available when invoked via the mocha CLI._
561 */
562 (fn: AsyncFunc): Test;
563
564 /**
565 * [bdd, tdd, qunit] Describe a specification or test-case with the given `title` and
566 * callback `fn` acting as a thunk. Indicates this test should be executed exclusively.
567 *
568 * - _Only available when invoked via the mocha CLI._
569 */
570 (title: string, fn?: Func): Test;
571
572 /**
573 * [bdd, tdd, qunit] Describe a specification or test-case with the given `title` and
574 * callback `fn` acting as a thunk. Indicates this test should be executed exclusively.
575 *
576 * - _Only available when invoked via the mocha CLI._
577 */
578 (title: string, fn?: AsyncFunc): Test;
579 }
580
581 interface PendingTestFunction {
582 /**
583 * [bdd, tdd, qunit] Describe a specification or test-case with the given callback `fn`
584 * acting as a thunk. The name of the function is used as the name of the test. Indicates
585 * this test should not be executed.
586 *
587 * - _Only available when invoked via the mocha CLI._
588 */
589 (fn: Func): Test;
590
591 /**
592 * [bdd, tdd, qunit] Describe a specification or test-case with the given callback `fn`
593 * acting as a thunk. The name of the function is used as the name of the test. Indicates
594 * this test should not be executed.
595 *
596 * - _Only available when invoked via the mocha CLI._
597 */
598 (fn: AsyncFunc): Test;
599
600 /**
601 * [bdd, tdd, qunit] Describe a specification or test-case with the given `title` and
602 * callback `fn` acting as a thunk. Indicates this test should not be executed.
603 *
604 * - _Only available when invoked via the mocha CLI._
605 */
606 (title: string, fn?: Func): Test;
607
608 /**
609 * [bdd, tdd, qunit] Describe a specification or test-case with the given `title` and
610 * callback `fn` acting as a thunk. Indicates this test should not be executed.
611 *
612 * - _Only available when invoked via the mocha CLI._
613 */
614 (title: string, fn?: AsyncFunc): Test;
615 }
616
617 /**
618 * Execute after each test case.
619 *
620 * - _Only available when invoked via the mocha CLI._
621 *
622 * @see https://mochajs.org/api/global.html#afterEach
623 */
624 let afterEach: HookFunction;
625
626 /**
627 * Execute after running tests.
628 *
629 * - _Only available when invoked via the mocha CLI._
630 *
631 * @see https://mochajs.org/api/global.html#after
632 */
633 let after: HookFunction;
634
635 /**
636 * Execute before each test case.
637 *
638 * - _Only available when invoked via the mocha CLI._
639 *
640 * @see https://mochajs.org/api/global.html#beforeEach
641 */
642 let beforeEach: HookFunction;
643
644 /**
645 * Execute before running tests.
646 *
647 * - _Only available when invoked via the mocha CLI._
648 *
649 * @see https://mochajs.org/api/global.html#before
650 */
651 let before: HookFunction;
652
653 /**
654 * Describe a "suite" containing nested suites and tests.
655 *
656 * - _Only available when invoked via the mocha CLI._
657 */
658 let describe: SuiteFunction;
659
660 /**
661 * Describes a test case.
662 *
663 * - _Only available when invoked via the mocha CLI._
664 */
665 let it: TestFunction;
666
667 /**
668 * Describes a pending test case.
669 *
670 * - _Only available when invoked via the mocha CLI._
671 */
672 let xit: PendingTestFunction;
673
674 /**
675 * Execute before each test case.
676 *
677 * - _Only available when invoked via the mocha CLI._
678 *
679 * @see https://mochajs.org/api/global.html#beforeEach
680 */
681 let setup: HookFunction;
682
683 /**
684 * Execute before running tests.
685 *
686 * - _Only available when invoked via the mocha CLI._
687 *
688 * @see https://mochajs.org/api/global.html#before
689 */
690 let suiteSetup: HookFunction;
691
692 /**
693 * Execute after running tests.
694 *
695 * - _Only available when invoked via the mocha CLI._
696 *
697 * @see https://mochajs.org/api/global.html#after
698 */
699 let suiteTeardown: HookFunction;
700
701 /**
702 * Describe a "suite" containing nested suites and tests.
703 *
704 * - _Only available when invoked via the mocha CLI._
705 */
706 let suite: SuiteFunction;
707
708 /**
709 * Execute after each test case.
710 *
711 * - _Only available when invoked via the mocha CLI._
712 *
713 * @see https://mochajs.org/api/global.html#afterEach
714 */
715 let teardown: HookFunction;
716
717 /**
718 * Describes a test case.
719 *
720 * - _Only available when invoked via the mocha CLI._
721 */
722 let test: TestFunction;
723
724 /**
725 * Triggers root suite execution.
726 *
727 * - _Only available if flag --delay is passed into Mocha._
728 * - _Only available when invoked via the mocha CLI._
729 *
730 * @see https://mochajs.org/api/global.html#runWithSuite
731 */
732 function run(): void;
733
734 // #endregion Test interface augmentations
735
736 namespace reporters {
737 /**
738 * Initialize a new `Base` reporter.
739 *
740 * All other reporters generally inherit from this reporter, providing stats such as test duration,
741 * number of tests passed / failed, etc.
742 *
743 * @see https://mochajs.org/api/Mocha.reporters.Base.html
744 */
745 class Base {
746 constructor(runner: Runner, options?: MochaOptions);
747
748 /**
749 * Test run statistics
750 */
751 stats: Stats;
752
753 /**
754 * Test failures
755 */
756 failures: Test[];
757
758 /**
759 * The configured runner
760 */
761 runner: Runner;
762
763 /**
764 * Output common epilogue used by many of the bundled reporters.
765 *
766 * @see https://mochajs.org/api/Mocha.reporters.Base.html#.Base#epilogue
767 */
768 epilogue(): void;
769
770 done?(failures: number, fn?: (failures: number) => void): void;
771 }
772
773 namespace Base {
774 /**
775 * Enables coloring by default
776 *
777 * @see https://mochajs.org/api/module-base#.useColors
778 */
779 let useColors: boolean;
780
781 /**
782 * Inline diffs instead of +/-
783 *
784 * @see https://mochajs.org/api/module-base#.inlineDiffs
785 */
786 let inlineDiffs: boolean;
787
788 /**
789 * Default color map
790 *
791 * @see https://mochajs.org/api/module-base#.colors
792 */
793 const colors: ColorMap;
794
795 /**
796 * Default color map
797 *
798 * @see https://mochajs.org/api/module-base#.colors
799 */
800 interface ColorMap {
801 // added by Base
802 pass: number;
803 fail: number;
804 'bright pass': number;
805 'bright fail': number;
806 'bright yellow': number;
807 pending: number;
808 suite: number;
809 'error title': number;
810 'error message': number;
811 'error stack': number;
812 checkmark: number;
813 fast: number;
814 medium: number;
815 slow: number;
816 green: number;
817 light: number;
818 'diff gutter': number;
819 'diff added': number;
820 'diff removed': number;
821
822 // added by Progress
823 progress: number;
824
825 // added by Landing
826 plane: number;
827 'plane crash': number;
828 runway: number;
829
830 [key: string]: number;
831 }
832
833 /**
834 * Default symbol map
835 *
836 * @see https://mochajs.org/api/module-base#.symbols
837 */
838 const symbols: SymbolMap;
839
840 /**
841 * Default symbol map
842 *
843 * @see https://mochajs.org/api/module-base#.symbols
844 */
845 interface SymbolMap {
846 ok: string;
847 err: string;
848 dot: string;
849 comma: string;
850 bang: string;
851 [key: string]: string;
852 }
853
854 /**
855 * Color `str` with the given `type` (from `colors`)
856 *
857 * @see https://mochajs.org/api/module-base#.color
858 */
859 function color(type: string, str: string): string;
860
861 /**
862 * Expose terminal window size
863 *
864 * @see https://mochajs.org/api/module-base#.window
865 */
866 const window: {
867 width: number;
868 };
869
870 /**
871 * ANSI TTY control sequences common among reporters.
872 *
873 * @see https://mochajs.org/api/module-base#.cursor
874 */
875 namespace cursor {
876 /**
877 * Hides the cursor
878 */
879 function hide(): void;
880
881 /**
882 * Shows the cursor
883 */
884 function show(): void;
885
886 /**
887 * Deletes the current line
888 */
889 function deleteLine(): void;
890
891 /**
892 * Moves to the beginning of the line
893 */
894 function beginningOfLine(): void;
895
896 /**
897 * Clears the line and moves to the beginning of the line.
898 */
899 function CR(): void;
900 }
901
902 /**
903 * Returns a diff between two strings with colored ANSI output.
904 *
905 * @see https://mochajs.org/api/module-base#.generateDiff
906 */
907 function generateDiff(actual: string, expected: string): string;
908
909 /**
910 * Output the given `failures` as a list.
911 *
912 * @see https://mochajs.org/api/Mocha.reporters.Base.html#.exports.list1
913 */
914 function list(failures: Test[]): void;
915 }
916
917 /**
918 * Initialize a new `Dot` matrix test reporter.
919 *
920 * @see https://mochajs.org/api/Mocha.reporters.Dot.html
921 */
922 class Dot extends Base {}
923
924 /**
925 * Initialize a new `Doc` reporter.
926 *
927 * @see https://mochajs.org/api/Mocha.reporters.Doc.html
928 */
929 class Doc extends Base {}
930
931 /**
932 * Initialize a new `TAP` test reporter.
933 *
934 * @see https://mochajs.org/api/Mocha.reporters.TAP.html
935 */
936 class TAP extends Base {}
937
938 /**
939 * Initialize a new `JSON` reporter
940 *
941 * @see https://mochajs.org/api/Mocha.reporters.JSON.html
942 */
943 class JSON extends Base {}
944
945 /**
946 * Initialize a new `HTML` reporter.
947 *
948 * - _This reporter cannot be used on the console._
949 *
950 * @see https://mochajs.org/api/Mocha.reporters.HTML.html
951 */
952 class HTML extends Base {
953 /**
954 * Provide suite URL.
955 *
956 * @see https://mochajs.org/api/Mocha.reporters.HTML.html#suiteURL
957 */
958 suiteURL(suite: Suite): string;
959
960 /**
961 * Provide test URL.
962 *
963 * @see https://mochajs.org/api/Mocha.reporters.HTML.html#testURL
964 */
965 testURL(test: Test): string;
966
967 /**
968 * Adds code toggle functionality for the provided test's list element.
969 *
970 * @see https://mochajs.org/api/Mocha.reporters.HTML.html#addCodeToggle
971 */
972 addCodeToggle(el: HTMLLIElement, contents: string): void;
973 }
974
975 /**
976 * Initialize a new `List` test reporter.
977 *
978 * @see https://mochajs.org/api/Mocha.reporters.List.html
979 */
980 class List extends Base {}
981
982 /**
983 * Initialize a new `Min` minimal test reporter (best used with --watch).
984 *
985 * @see https://mochajs.org/api/Mocha.reporters.Min.html
986 */
987 class Min extends Base {}
988
989 /**
990 * Initialize a new `Spec` test reporter.
991 *
992 * @see https://mochajs.org/api/Mocha.reporters.Spec.html
993 */
994 class Spec extends Base {}
995
996 /**
997 * Initialize a new `NyanCat` test reporter.
998 *
999 * @see https://mochajs.org/api/Mocha.reporters.Nyan.html
1000 */
1001 class Nyan extends Base {
1002 private colorIndex;
1003 private numberOfLines;
1004 private rainbowColors;
1005 private scoreboardWidth;
1006 private tick;
1007 private trajectories;
1008 private trajectoryWidthMax;
1009 private draw;
1010 private drawScoreboard;
1011 private appendRainbow;
1012 private drawRainbow;
1013 private drawNyanCat;
1014 private face;
1015 private cursorUp;
1016 private cursorDown;
1017 private generateColors;
1018 private rainbowify;
1019 }
1020
1021 /**
1022 * Initialize a new `XUnit` test reporter.
1023 *
1024 * @see https://mochajs.org/api/Mocha.reporters.XUnit.html
1025 */
1026 class XUnit extends Base {
1027 constructor(runner: Runner, options?: XUnit.MochaOptions);
1028
1029 /**
1030 * Override done to close the stream (if it's a file).
1031 *
1032 * @see https://mochajs.org/api/Mocha.reporters.XUnit.html#done
1033 */
1034 done(failures: number, fn: (failures: number) => void): void;
1035
1036 /**
1037 * Write out the given line.
1038 *
1039 * @see https://mochajs.org/api/Mocha.reporters.XUnit.html#write
1040 */
1041 write(line: string): void;
1042
1043 /**
1044 * Output tag for the given `test.`
1045 *
1046 * @see https://mochajs.org/api/Mocha.reporters.XUnit.html#test
1047 */
1048 test(test: Test): void;
1049 }
1050
1051 namespace XUnit {
1052 interface MochaOptions extends Mocha.MochaOptions {
1053 reporterOptions?: ReporterOptions | undefined;
1054 }
1055
1056 interface ReporterOptions {
1057 output?: string | undefined;
1058 suiteName?: string | undefined;
1059 }
1060 }
1061
1062 /**
1063 * Initialize a new `Markdown` test reporter.
1064 *
1065 * @see https://mochajs.org/api/Mocha.reporters.Markdown.html
1066 */
1067 class Markdown extends Base {}
1068
1069 /**
1070 * Initialize a new `Progress` bar test reporter.
1071 *
1072 * @see https://mochajs.org/api/Mocha.reporters.Progress.html
1073 */
1074 class Progress extends Base {
1075 constructor(runner: Runner, options?: Progress.MochaOptions);
1076 }
1077
1078 namespace Progress {
1079 interface MochaOptions extends Mocha.MochaOptions {
1080 reporterOptions?: ReporterOptions | undefined;
1081 }
1082
1083 interface ReporterOptions {
1084 open?: string | undefined;
1085 complete?: string | undefined;
1086 incomplete?: string | undefined;
1087 close?: string | undefined;
1088 verbose?: boolean | undefined;
1089 }
1090 }
1091
1092 /**
1093 * Initialize a new `Landing` reporter.
1094 *
1095 * @see https://mochajs.org/api/Mocha.reporters.Landing.html
1096 */
1097 class Landing extends Base {}
1098
1099 /**
1100 * Initialize a new `JSONStream` test reporter.
1101 *
1102 * @see https://mochajs.org/api/Mocha.reporters.JSONStream.html
1103 */
1104 class JSONStream extends Base {}
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(
2133 event: 'pre-require',
2134 listener: (context: MochaGlobals, file: string, mocha: Mocha) => void,
2135 ): this;
2136 prependListener(
2137 event: 'pre-require',
2138 listener: (context: MochaGlobals, file: string, mocha: Mocha) => void,
2139 ): this;
2140 prependOnceListener(
2141 event: 'pre-require',
2142 listener: (context: MochaGlobals, file: string, mocha: Mocha) => void,
2143 ): this;
2144 emit(name: 'pre-require', context: MochaGlobals, file: string, mocha: Mocha): boolean;
2145 }
2146 // #endregion Suite "pre-require" event
2147 // #region Suite "require" event
2148 interface Suite extends NodeJS.EventEmitter {
2149 on(event: 'require', listener: (module: any, file: string, mocha: Mocha) => void): this;
2150 once(event: 'require', listener: (module: any, file: string, mocha: Mocha) => void): this;
2151 addListener(event: 'require', listener: (module: any, file: string, mocha: Mocha) => void): this;
2152 removeListener(event: 'require', listener: (module: any, file: string, mocha: Mocha) => void): this;
2153 prependListener(event: 'require', listener: (module: any, file: string, mocha: Mocha) => void): this;
2154 prependOnceListener(event: 'require', listener: (module: any, file: string, mocha: Mocha) => void): this;
2155 emit(name: 'require', module: any, file: string, mocha: Mocha): boolean;
2156 }
2157 // #endregion Suite "require" event
2158 // #region Suite "post-require" event
2159 interface Suite extends NodeJS.EventEmitter {
2160 on(event: 'post-require', listener: (context: MochaGlobals, file: string, mocha: Mocha) => void): this;
2161 once(event: 'post-require', listener: (context: MochaGlobals, file: string, mocha: Mocha) => void): this;
2162 addListener(event: 'post-require', listener: (context: MochaGlobals, file: string, mocha: Mocha) => void): this;
2163 removeListener(
2164 event: 'post-require',
2165 listener: (context: MochaGlobals, file: string, mocha: Mocha) => void,
2166 ): this;
2167 prependListener(
2168 event: 'post-require',
2169 listener: (context: MochaGlobals, file: string, mocha: Mocha) => void,
2170 ): this;
2171 prependOnceListener(
2172 event: 'post-require',
2173 listener: (context: MochaGlobals, file: string, mocha: Mocha) => void,
2174 ): this;
2175 emit(name: 'post-require', context: MochaGlobals, file: string, mocha: Mocha): boolean;
2176 }
2177 // #endregion Suite "post-require" event
2178 // #region Suite untyped events
2179 interface Suite extends NodeJS.EventEmitter {
2180 on(event: string, listener: (...args: any[]) => void): this;
2181 once(event: string, listener: (...args: any[]) => void): this;
2182 addListener(event: string, listener: (...args: any[]) => void): this;
2183 removeListener(event: string, listener: (...args: any[]) => void): this;
2184 prependListener(event: string, listener: (...args: any[]) => void): this;
2185 prependOnceListener(event: string, listener: (...args: any[]) => void): this;
2186 emit(name: string, ...args: any[]): boolean;
2187 }
2188 // #endregion Runner untyped events
2189
2190 /**
2191 * Initialize a new `Hook` with the given `title` and callback `fn`
2192 *
2193 * @see https://mochajs.org/api/Hook.html
2194 */
2195 class Hook extends Runnable {
2196 private _error;
2197
2198 type: 'hook';
2199 originalTitle?: string | undefined; // added by Runner
2200
2201 /**
2202 * Get the test `err`.
2203 *
2204 * @see https://mochajs.org/api/Hook.html#error
2205 */
2206 error(): any;
2207
2208 /**
2209 * Set the test `err`.
2210 *
2211 * @see https://mochajs.org/api/Hook.html#error
2212 */
2213 error(err: any): void;
2214 }
2215
2216 /**
2217 * An alternative way to define root hooks that works with parallel runs.
2218 *
2219 * Root hooks work with any interface, but the property names do not change.
2220 * In other words, if you are using the tdd interface, suiteSetup maps to beforeAll, and setup maps to beforeEach.
2221 *
2222 * As with other hooks, `this` refers to to the current context object.
2223 *
2224 * @see https://mochajs.org/#root-hook-plugins
2225 */
2226 interface RootHookObject {
2227 /**
2228 * In serial mode, run after all tests end, once only.
2229 * In parallel mode, run after all tests end, for each file.
2230 */
2231 afterAll?: Func | AsyncFunc | Func[] | AsyncFunc[] | undefined;
2232 /**
2233 * In serial mode (Mocha's default), before all tests begin, once only.
2234 * In parallel mode, run before all tests begin, for each file.
2235 */
2236 beforeAll?: Func | AsyncFunc | Func[] | AsyncFunc[] | undefined;
2237 /**
2238 * In both modes, run after every test.
2239 */
2240 afterEach?: Func | AsyncFunc | Func[] | AsyncFunc[] | undefined;
2241 /**
2242 * In both modes, run before each test.
2243 */
2244 beforeEach?: Func | AsyncFunc | Func[] | AsyncFunc[] | undefined;
2245 }
2246
2247 /**
2248 * Initialize a new `Test` with the given `title` and callback `fn`.
2249 *
2250 * @see https://mochajs.org/api/Test.html
2251 */
2252 class Test extends Runnable {
2253 type: 'test';
2254 speed?: 'slow' | 'medium' | 'fast' | undefined; // added by reporters
2255 err?: Error | undefined; // added by reporters
2256 clone(): Test;
2257 }
2258
2259 /**
2260 * Test statistics
2261 */
2262 interface Stats {
2263 suites: number;
2264 tests: number;
2265 passes: number;
2266 pending: number;
2267 failures: number;
2268 start?: Date | undefined;
2269 end?: Date | undefined;
2270 duration?: number | undefined;
2271 }
2272
2273 type TestInterface = (suite: Suite) => void;
2274
2275 interface ReporterConstructor {
2276 new (runner: Runner, options: MochaOptions): reporters.Base;
2277 }
2278
2279 type Done = (err?: any) => void;
2280
2281 /**
2282 * Callback function used for tests and hooks.
2283 */
2284 type Func = (this: Context, done: Done) => void;
2285
2286 /**
2287 * Async callback function used for tests and hooks.
2288 */
2289 type AsyncFunc = (this: Context) => PromiseLike<any>;
2290
2291 /**
2292 * Options to pass to Mocha.
2293 */
2294 interface MochaOptions {
2295 /** Propagate uncaught errors? */
2296 allowUncaught?: boolean | undefined;
2297
2298 /** Force `done` callback or promise? */
2299 asyncOnly?: boolean | undefined;
2300
2301 /** bail on the first test failure. */
2302 bail?: boolean | undefined;
2303
2304 /** Check for global variable leaks? */
2305 checkLeaks?: boolean | undefined;
2306
2307 /** Color TTY output from reporter */
2308 color?: boolean | undefined;
2309
2310 /** Delay root suite execution? */
2311 delay?: boolean | undefined;
2312
2313 /** Show diff on failure? */
2314 diff?: boolean | undefined;
2315
2316 /** Report tests without running them? */
2317 dryRun?: boolean | undefined;
2318
2319 /** Test filter given string. */
2320 fgrep?: string | undefined;
2321
2322 /** Tests marked `only` fail the suite? */
2323 forbidOnly?: boolean | undefined;
2324
2325 /** Pending tests fail the suite? */
2326 forbidPending?: boolean | undefined;
2327
2328 /** Full stacktrace upon failure? */
2329 fullTrace?: boolean | undefined;
2330
2331 /** Variables expected in global scope. */
2332 globals?: string[] | undefined;
2333
2334 /** Test filter given regular expression. */
2335 grep?: string | RegExp | undefined;
2336
2337 /** Enable desktop notifications? */
2338 growl?: boolean | undefined;
2339
2340 /** Display inline diffs? */
2341 inlineDiffs?: boolean | undefined;
2342
2343 /** Invert test filter matches? */
2344 invert?: boolean | undefined;
2345
2346 /** Disable syntax highlighting? */
2347 noHighlighting?: boolean | undefined;
2348
2349 /** Reporter name or constructor. */
2350 reporter?: string | ReporterConstructor | undefined;
2351
2352 /** Reporter settings object. */
2353 reporterOptions?: any;
2354
2355 /** Number of times to retry failed tests. */
2356 retries?: number | undefined;
2357
2358 /** Slow threshold value. */
2359 slow?: number | undefined;
2360
2361 /** Timeout threshold value. */
2362 timeout?: number | string | undefined;
2363
2364 /** Interface name. */
2365 ui?: Interface | undefined;
2366
2367 /** Run jobs in parallel */
2368 parallel?: boolean | undefined;
2369
2370 /** Max number of worker processes for parallel runs. */
2371 jobs?: number | undefined;
2372
2373 /** Hooks to bootstrap the root suite with. */
2374 rootHooks?: RootHookObject | undefined;
2375
2376 /** Pathname of `rootHooks` plugin for parallel runs. */
2377 require?: string[] | undefined;
2378
2379 /** Should be `true` if `Mocha` process is running in a worker process. */
2380 isWorker?: boolean | undefined;
2381 }
2382
2383 interface MochaInstanceOptions extends MochaOptions {
2384 files?: string[] | undefined;
2385 }
2386
2387 /**
2388 * Variables added to the global scope by Mocha when run in the CLI.
2389 */
2390 interface MochaGlobals {
2391 /**
2392 * Execute before running tests.
2393 *
2394 * - _Only available when invoked via the mocha CLI._
2395 *
2396 * @see https://mochajs.org/api/global.html#before
2397 */
2398 before: HookFunction;
2399
2400 /**
2401 * Execute after running tests.
2402 *
2403 * - _Only available when invoked via the mocha CLI._
2404 *
2405 * @see https://mochajs.org/api/global.html#after
2406 */
2407 after: HookFunction;
2408
2409 /**
2410 * Execute before each test case.
2411 *
2412 * - _Only available when invoked via the mocha CLI._
2413 *
2414 * @see https://mochajs.org/api/global.html#beforeEach
2415 */
2416 beforeEach: HookFunction;
2417
2418 /**
2419 * Execute after each test case.
2420 *
2421 * - _Only available when invoked via the mocha CLI._
2422 *
2423 * @see https://mochajs.org/api/global.html#afterEach
2424 */
2425 afterEach: HookFunction;
2426
2427 /**
2428 * Describe a "suite" containing nested suites and tests.
2429 *
2430 * - _Only available when invoked via the mocha CLI._
2431 */
2432 describe: SuiteFunction;
2433
2434 /**
2435 * Describe a "suite" containing nested suites and tests.
2436 *
2437 * - _Only available when invoked via the mocha CLI._
2438 */
2439 context: SuiteFunction;
2440
2441 /**
2442 * Pending suite.
2443 *
2444 * - _Only available when invoked via the mocha CLI._
2445 */
2446 xdescribe: PendingSuiteFunction;
2447
2448 /**
2449 * Pending suite.
2450 *
2451 * - _Only available when invoked via the mocha CLI._
2452 */
2453 xcontext: PendingSuiteFunction;
2454
2455 /**
2456 * Describes a test case.
2457 *
2458 * - _Only available when invoked via the mocha CLI._
2459 */
2460 it: TestFunction;
2461
2462 /**
2463 * Describes a test case.
2464 *
2465 * - _Only available when invoked via the mocha CLI._
2466 */
2467 specify: TestFunction;
2468
2469 /**
2470 * Describes a pending test case.
2471 *
2472 * - _Only available when invoked via the mocha CLI._
2473 */
2474 xit: PendingTestFunction;
2475
2476 /**
2477 * Describes a pending test case.
2478 *
2479 * - _Only available when invoked via the mocha CLI._
2480 */
2481 xspecify: PendingTestFunction;
2482
2483 /**
2484 * Execute before running tests.
2485 *
2486 * - _Only available when invoked via the mocha CLI._
2487 *
2488 * @see https://mochajs.org/api/global.html#before
2489 */
2490 suiteSetup: HookFunction;
2491
2492 /**
2493 * Execute after running tests.
2494 *
2495 * - _Only available when invoked via the mocha CLI._
2496 *
2497 * @see https://mochajs.org/api/global.html#after
2498 */
2499 suiteTeardown: HookFunction;
2500
2501 /**
2502 * Execute before each test case.
2503 *
2504 * - _Only available when invoked via the mocha CLI._
2505 *
2506 * @see https://mochajs.org/api/global.html#beforeEach
2507 */
2508 setup: HookFunction;
2509
2510 /**
2511 * Execute after each test case.
2512 *
2513 * - _Only available when invoked via the mocha CLI._
2514 *
2515 * @see https://mochajs.org/api/global.html#afterEach
2516 */
2517 teardown: HookFunction;
2518
2519 /**
2520 * Describe a "suite" containing nested suites and tests.
2521 *
2522 * - _Only available when invoked via the mocha CLI._
2523 */
2524 suite: SuiteFunction;
2525
2526 /**
2527 * Describes a test case.
2528 *
2529 * - _Only available when invoked via the mocha CLI._
2530 */
2531 test: TestFunction;
2532
2533 run: typeof run;
2534 }
2535
2536 /**
2537 * Third-party declarations that want to add new entries to the `Reporter` union can
2538 * contribute names here.
2539 */
2540 interface ReporterContributions {
2541 Base: never;
2542 base: never;
2543 Dot: never;
2544 dot: never;
2545 TAP: never;
2546 tap: never;
2547 JSON: never;
2548 json: never;
2549 HTML: never;
2550 html: never;
2551 List: never;
2552 list: never;
2553 Min: never;
2554 min: never;
2555 Spec: never;
2556 spec: never;
2557 Nyan: never;
2558 nyan: never;
2559 XUnit: never;
2560 xunit: never;
2561 Markdown: never;
2562 markdown: never;
2563 Progress: never;
2564 progress: never;
2565 Landing: never;
2566 landing: never;
2567 JSONStream: never;
2568 'json-stream': never;
2569 }
2570
2571 type Reporter = keyof ReporterContributions;
2572
2573 /**
2574 * Third-party declarations that want to add new entries to the `Interface` union can
2575 * contribute names here.
2576 */
2577 interface InterfaceContributions {
2578 bdd: never;
2579 tdd: never;
2580 qunit: never;
2581 exports: never;
2582 }
2583
2584 type Interface = keyof InterfaceContributions;
2585}
2586
2587// #region Test interface augmentations
2588
2589/**
2590 * Triggers root suite execution.
2591 *
2592 * - _Only available if flag --delay is passed into Mocha._
2593 * - _Only available when invoked via the mocha CLI._
2594 *
2595 * @see https://mochajs.org/api/global.html#runWithSuite
2596 */
2597declare function run(): void;
2598
2599/**
2600 * Execute before running tests.
2601 *
2602 * - _Only available when invoked via the mocha CLI._
2603 *
2604 * @see https://mochajs.org/api/global.html#before
2605 */
2606declare var before: Mocha.HookFunction;
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 suiteSetup: Mocha.HookFunction;
2616
2617/**
2618 * Execute after running tests.
2619 *
2620 * - _Only available when invoked via the mocha CLI._
2621 *
2622 * @see https://mochajs.org/api/global.html#after
2623 */
2624declare var after: 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 suiteTeardown: Mocha.HookFunction;
2634
2635/**
2636 * Execute before each test case.
2637 *
2638 * - _Only available when invoked via the mocha CLI._
2639 *
2640 * @see https://mochajs.org/api/global.html#beforeEach
2641 */
2642declare var beforeEach: 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 setup: Mocha.HookFunction;
2652
2653/**
2654 * Execute after each test case.
2655 *
2656 * - _Only available when invoked via the mocha CLI._
2657 *
2658 * @see https://mochajs.org/api/global.html#afterEach
2659 */
2660declare var afterEach: 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 teardown: Mocha.HookFunction;
2670
2671/**
2672 * Describe a "suite" containing nested suites and tests.
2673 *
2674 * - _Only available when invoked via the mocha CLI._
2675 */
2676declare var describe: Mocha.SuiteFunction;
2677
2678/**
2679 * Describe a "suite" containing nested suites and tests.
2680 *
2681 * - _Only available when invoked via the mocha CLI._
2682 */
2683declare var context: Mocha.SuiteFunction;
2684
2685/**
2686 * Describe a "suite" containing nested suites and tests.
2687 *
2688 * - _Only available when invoked via the mocha CLI._
2689 */
2690declare var suite: Mocha.SuiteFunction;
2691
2692/**
2693 * Pending suite.
2694 *
2695 * - _Only available when invoked via the mocha CLI._
2696 */
2697declare var xdescribe: Mocha.PendingSuiteFunction;
2698
2699/**
2700 * Pending suite.
2701 *
2702 * - _Only available when invoked via the mocha CLI._
2703 */
2704declare var xcontext: Mocha.PendingSuiteFunction;
2705
2706/**
2707 * Describes a test case.
2708 *
2709 * - _Only available when invoked via the mocha CLI._
2710 */
2711declare var it: Mocha.TestFunction;
2712
2713/**
2714 * Describes a test case.
2715 *
2716 * - _Only available when invoked via the mocha CLI._
2717 */
2718declare var specify: Mocha.TestFunction;
2719
2720/**
2721 * Describes a test case.
2722 *
2723 * - _Only available when invoked via the mocha CLI._
2724 */
2725declare var test: Mocha.TestFunction;
2726
2727/**
2728 * Describes a pending test case.
2729 *
2730 * - _Only available when invoked via the mocha CLI._
2731 */
2732declare var xit: Mocha.PendingTestFunction;
2733
2734/**
2735 * Describes a pending test case.
2736 *
2737 * - _Only available when invoked via the mocha CLI._
2738 */
2739declare var xspecify: Mocha.PendingTestFunction;
2740
2741// #endregion Test interface augmentations
2742
2743// #region Reporter augmentations
2744
2745// Forward declaration for `HTMLLIElement` from lib.dom.d.ts.
2746// Required by Mocha.reporters.HTML.
2747// NOTE: Mocha *must not* have a direct dependency on DOM types.
2748// tslint:disable-next-line no-empty-interface
2749interface HTMLLIElement {}
2750
2751// Augments the DOM `Window` object when lib.dom.d.ts is loaded.
2752// tslint:disable-next-line no-empty-interface
2753interface Window extends Mocha.MochaGlobals {}
2754
2755declare namespace NodeJS {
2756 // Forward declaration for `NodeJS.EventEmitter` from node.d.ts.
2757 // Required by Mocha.Runnable, Mocha.Runner, and Mocha.Suite.
2758 // NOTE: Mocha *must not* have a direct dependency on @types/node.
2759 // tslint:disable-next-line no-empty-interface
2760 interface EventEmitter {}
2761
2762 // Augments NodeJS's `global` object when node.d.ts is loaded
2763 // tslint:disable-next-line no-empty-interface
2764 interface Global extends Mocha.MochaGlobals {}
2765}
2766
2767// #endregion Reporter augmentations
2768
2769// #region Browser augmentations
2770
2771/**
2772 * Mocha global.
2773 *
2774 * - _Only supported in the browser._
2775 */
2776declare const mocha: BrowserMocha;
2777
2778interface BrowserMocha extends Mocha {
2779 /**
2780 * Function to allow assertion libraries to throw errors directly into mocha.
2781 * This is useful when running tests in a browser because window.onerror will
2782 * only receive the 'message' attribute of the Error.
2783 *
2784 * - _Only supported in the browser._
2785 */
2786 throwError(err: any): never;
2787
2788 /**
2789 * Setup mocha with the given settings options.
2790 *
2791 * - _Only supported in the browser._
2792 */
2793 setup(opts?: Mocha.Interface | Mocha.MochaOptions): this;
2794}
2795
2796// #endregion Browser augmentations
2797
2798declare module 'mocha' {
2799 export = Mocha;
2800}
2801
2802declare module 'mocha/lib/stats-collector' {
2803 export = createStatsCollector;
2804
2805 /**
2806 * Provides stats such as test duration, number of tests passed / failed etc., by listening for events emitted by `runner`.
2807 */
2808 function createStatsCollector(runner: Mocha.Runner): void;
2809}
2810
2811declare module 'mocha/lib/interfaces/common' {
2812 export = common;
2813
2814 function common(suites: Mocha.Suite[], context: Mocha.MochaGlobals, mocha: Mocha): common.CommonFunctions;
2815
2816 namespace common {
2817 interface CommonFunctions {
2818 /**
2819 * This is only present if flag --delay is passed into Mocha. It triggers
2820 * root suite execution.
2821 */
2822 runWithSuite(suite: Mocha.Suite): () => void;
2823
2824 /**
2825 * Execute before running tests.
2826 */
2827 before(fn?: Mocha.Func | Mocha.AsyncFunc): void;
2828
2829 /**
2830 * Execute before running tests.
2831 */
2832 before(name: string, fn?: Mocha.Func | Mocha.AsyncFunc): void;
2833
2834 /**
2835 * Execute after running tests.
2836 */
2837 after(fn?: Mocha.Func | Mocha.AsyncFunc): void;
2838
2839 /**
2840 * Execute after running tests.
2841 */
2842 after(name: string, fn?: Mocha.Func | Mocha.AsyncFunc): void;
2843
2844 /**
2845 * Execute before each test case.
2846 */
2847 beforeEach(fn?: Mocha.Func | Mocha.AsyncFunc): void;
2848
2849 /**
2850 * Execute before each test case.
2851 */
2852 beforeEach(name: string, fn?: Mocha.Func | Mocha.AsyncFunc): void;
2853
2854 /**
2855 * Execute after each test case.
2856 */
2857 afterEach(fn?: Mocha.Func | Mocha.AsyncFunc): void;
2858
2859 /**
2860 * Execute after each test case.
2861 */
2862 afterEach(name: string, fn?: Mocha.Func | Mocha.AsyncFunc): void;
2863
2864 suite: SuiteFunctions;
2865 test: TestFunctions;
2866 }
2867
2868 interface CreateOptions {
2869 /** Title of suite */
2870 title: string;
2871
2872 /** Suite function */
2873 fn?: ((this: Mocha.Suite) => void) | undefined;
2874
2875 /** Is suite pending? */
2876 pending?: boolean | undefined;
2877
2878 /** Filepath where this Suite resides */
2879 file?: string | undefined;
2880
2881 /** Is suite exclusive? */
2882 isOnly?: boolean | undefined;
2883 }
2884
2885 interface SuiteFunctions {
2886 /**
2887 * Create an exclusive Suite; convenience function
2888 */
2889 only(opts: CreateOptions): Mocha.Suite;
2890
2891 /**
2892 * Create a Suite, but skip it; convenience function
2893 */
2894 skip(opts: CreateOptions): Mocha.Suite;
2895
2896 /**
2897 * Creates a suite.
2898 */
2899 create(opts: CreateOptions): Mocha.Suite;
2900 }
2901
2902 interface TestFunctions {
2903 /**
2904 * Exclusive test-case.
2905 */
2906 only(mocha: Mocha, test: Mocha.Test): Mocha.Test;
2907
2908 /**
2909 * Pending test case.
2910 */
2911 skip(title: string): void;
2912
2913 /**
2914 * Number of retry attempts
2915 */
2916 retries(n: number): void;
2917 }
2918 }
2919}
2920
\No newline at end of file