UNPKG

32.6 kBTypeScriptView Raw
1// TODO: can be removed as soon as https://github.com/tapjs/node-tap/pull/607 is merged
2
3/// <reference types="node" />
4import { EventEmitter } from "events";
5
6/**
7 * Tap v15 deprecates **ALL** synonyms for assertions.
8 */
9declare class DeprecatedAssertionSynonyms {
10 /**
11 * @deprecated use ok() instead.
12 */
13 true: Assertions.Basic;
14 /**
15 * @deprecated use ok() instead.
16 */
17 assert: Assertions.Basic;
18
19 /**
20 * @deprecated use teardown() instead.
21 */
22 tearDown(fn: () => void | Promise<void>): void;
23
24 /**
25 * @deprecated use notOk() instead.
26 */
27 false: Assertions.Basic;
28 /**
29 * @deprecated use assertNot() instead.
30 */
31 assertNot: Assertions.Basic;
32
33 /**
34 * @deprecated use error() instead.
35 */
36 ifErr: Assertions.Basic;
37 /**
38 * @deprecated use error() instead.
39 */
40 ifError: Assertions.Basic;
41
42 /**
43 * @deprecated use doesNotThrow() instead.
44 */
45 notThrow: Assertions.DoesNotThrow;
46
47 /**
48 * @deprecated use throws() instead.
49 */
50 throw: Assertions.Throws;
51
52 /**
53 * @deprecated use equal() instead.
54 */
55 equals: Assertions.Equal;
56 /**
57 * @deprecated use equal() instead.
58 */
59 isEqual: Assertions.Equal;
60 /**
61 * @deprecated use equal() instead.
62 */
63 is: Assertions.Equal;
64 /**
65 * @deprecated use equal() instead.
66 */
67 strictEqual: Assertions.Equal;
68 /**
69 * @deprecated use equal() instead.
70 */
71 strictEquals: Assertions.Equal;
72 /**
73 * @deprecated use equal() instead.
74 */
75 strictIs: Assertions.Equal;
76 /**
77 * @deprecated use equal() instead.
78 */
79 isStrict: Assertions.Equal;
80 /**
81 * @deprecated use equal() instead.
82 */
83 isStrictly: Assertions.Equal;
84
85 /**
86 * @deprecated use not() instead.
87 */
88 notEqual: Assertions.NotEqual;
89 /**
90 * @deprecated use not() instead.
91 */
92 notEquals: Assertions.NotEqual;
93 /**
94 * @deprecated use not() instead.
95 */
96 inequal: Assertions.NotEqual;
97 /**
98 * @deprecated use not() instead.
99 */
100 notStrictEqual: Assertions.NotEqual;
101 /**
102 * @deprecated use not() instead.
103 */
104 notStrictEquals: Assertions.NotEqual;
105 /**
106 * @deprecated use not() instead.
107 */
108 isNotEqual: Assertions.NotEqual;
109 /**
110 * @deprecated use not() instead.
111 */
112 isNot: Assertions.NotEqual;
113 /**
114 * @deprecated use not() instead.
115 */
116 doesNotEqual: Assertions.NotEqual;
117 /**
118 * @deprecated use not() instead.
119 */
120 isInequal: Assertions.NotEqual;
121
122 /**
123 * @deprecated use same() instead.
124 */
125 equivalent: Assertions.Equal;
126 /**
127 * @deprecated use same() instead.
128 */
129 looseEqual: Assertions.Equal;
130 /**
131 * @deprecated use same() instead.
132 */
133 looseEquals: Assertions.Equal;
134 /**
135 * @deprecated use same() instead.
136 */
137 deepEqual: Assertions.Equal;
138 /**
139 * @deprecated use same() instead.
140 */
141 deepEquals: Assertions.Equal;
142 /**
143 * @deprecated use same() instead.
144 */
145 isLoose: Assertions.Equal;
146 /**
147 * @deprecated use same() instead.
148 */
149 looseIs: Assertions.Equal;
150
151 /**
152 * @deprecated use notSame() instead.
153 */
154 inequivalent: Assertions.NotEqual;
155 /**
156 * @deprecated use notSame() instead.
157 */
158 looseInequal: Assertions.NotEqual;
159 /**
160 * @deprecated use notSame() instead.
161 */
162 notDeep: Assertions.NotEqual;
163 /**
164 * @deprecated use notSame() instead.
165 */
166 deepInequal: Assertions.NotEqual;
167 /**
168 * @deprecated use notSame() instead.
169 */
170 notLoose: Assertions.NotEqual;
171 /**
172 * @deprecated use notSame() instead.
173 */
174 looseNot: Assertions.NotEqual;
175
176 /**
177 * @deprecated use strictSame() instead.
178 */
179 strictEquivalent: Assertions.Equal;
180 /**
181 * @deprecated use strictSame() instead.
182 */
183 strictDeepEqual: Assertions.Equal;
184 /**
185 * @deprecated use strictSame() instead.
186 */
187 sameStrict: Assertions.Equal;
188 /**
189 * @deprecated use strictSame() instead.
190 */
191 deepIs: Assertions.Equal;
192 /**
193 * @deprecated use strictSame() instead.
194 */
195 isDeeply: Assertions.Equal;
196 /**
197 * @deprecated use strictSame() instead.
198 */
199 isDeep: Assertions.Equal;
200 /**
201 * @deprecated use strictSame() instead.
202 */
203 strictDeepEquals: Assertions.Equal;
204
205 /**
206 * @deprecated use strictNotSame() instead.
207 */
208 strictInequivalent: Assertions.NotEqual;
209 /**
210 * @deprecated use strictNotSame() instead.
211 */
212 strictDeepInequal: Assertions.NotEqual;
213 /**
214 * @deprecated use strictNotSame() instead.
215 */
216 notSameStrict: Assertions.NotEqual;
217 /**
218 * @deprecated use strictNotSame() instead.
219 */
220 deepNot: Assertions.NotEqual;
221 /**
222 * @deprecated use strictNotSame() instead.
223 */
224 notDeeply: Assertions.NotEqual;
225 /**
226 * @deprecated use strictNotSame() instead.
227 */
228 strictDeepInequals: Assertions.NotEqual;
229 /**
230 * @deprecated use strictNotSame() instead.
231 */
232 notStrictSame: Assertions.NotEqual;
233
234 /**
235 * @deprecated use match() instead.
236 */
237 matches: Assertions.Match;
238 /**
239 * @deprecated use match() instead.
240 */
241 similar: Assertions.Match;
242 /**
243 * @deprecated use match() instead.
244 */
245 like: Assertions.Match;
246 /**
247 * @deprecated use match() instead.
248 */
249 isLike: Assertions.Match;
250 /**
251 * @deprecated use match() instead.
252 */
253 isSimilar: Assertions.Match;
254
255 /**
256 * @deprecated use notMatch() instead.
257 */
258 dissimilar: Assertions.Match;
259 /**
260 * @deprecated use notMatch() instead.
261 */
262 unsimilar: Assertions.Match;
263 /**
264 * @deprecated use notMatch() instead.
265 */
266 notSimilar: Assertions.Match;
267 /**
268 * @deprecated use notMatch() instead.
269 */
270 unlike: Assertions.Match;
271 /**
272 * @deprecated use notMatch() instead.
273 */
274 isUnlike: Assertions.Match;
275 /**
276 * @deprecated use notMatch() instead.
277 */
278 notLike: Assertions.Match;
279 /**
280 * @deprecated use notMatch() instead.
281 */
282 isNotLike: Assertions.Match;
283 /**
284 * @deprecated use notMatch() instead.
285 */
286 doesNotHave: Assertions.Match;
287 /**
288 * @deprecated use notMatch() instead.
289 */
290 isNotSimilar: Assertions.Match;
291 /**
292 * @deprecated use notMatch() instead.
293 */
294 isDissimilar: Assertions.Match;
295
296 /**
297 * @deprecated use type() instead.
298 */
299 isa: Assertions.Type;
300 /**
301 * @deprecated use type() instead.
302 */
303 isA: Assertions.Type;
304
305 /**
306 * @deprecated use has() instead.
307 */
308 hasFields: Assertions.Match;
309 /**
310 * @deprecated use has() instead.
311 */
312 includes: Assertions.Match;
313 /**
314 * @deprecated use has() instead.
315 */
316 include: Assertions.Match;
317 /**
318 * @deprecated use has() instead.
319 */
320 contains: Assertions.Match;
321}
322
323declare namespace Assertions {
324 type Basic = (obj: any, message?: string, extra?: Options.Assert) => boolean;
325 interface Throws {
326 (fn?: (...args: any[]) => any, expectedError?: any, message?: string, extra?: Options.Assert): boolean;
327 (fn?: (...args: any[]) => any, expectedError?: any, extra?: Options.Assert): boolean;
328 }
329 type DoesNotThrow = (fn?: (...args: any[]) => any, message?: string, extra?: Options.Assert) => boolean;
330 type Equal = (found: any, wanted: any, message?: string, extra?: Options.Assert) => boolean;
331 type NotEqual = (found: any, notWanted: any, message?: string, extra?: Options.Assert) => boolean;
332 type Match = (
333 found: any,
334 pattern: any,
335 message?: string,
336 extra?: Options.Assert,
337 ) => boolean;
338 type Type = (
339 found: any,
340 type: string | (new(...args: any[]) => object),
341 message?: string,
342 extra?: Options.Assert,
343 ) => boolean;
344}
345
346declare namespace Options {
347 interface Bag {
348 [key: string]: any;
349 }
350
351 interface Pragma {
352 [key: string]: boolean;
353 }
354
355 interface Assert extends Bag {
356 todo?: boolean | string | undefined;
357 skip?: boolean | string | undefined;
358 diagnostic?: boolean | undefined;
359 }
360
361 interface Spawn extends Assert {
362 bail?: boolean | undefined;
363 timeout?: number | undefined;
364 }
365
366 interface Test extends Assert {
367 timeout?: number | undefined;
368 bail?: boolean | undefined;
369 autoend?: boolean | undefined;
370 buffered?: boolean | undefined;
371 jobs?: number | undefined;
372 grep?: RegExp[] | undefined;
373 only?: boolean | undefined;
374 runOnly?: boolean | undefined;
375 }
376}
377
378declare global {
379 namespace Tap {
380 class Test extends DeprecatedAssertionSynonyms {
381 constructor(options?: Options.Test);
382
383 /**
384 * Run the supplied function when t.end() is called, or when t.plan is met.
385 *
386 * This function can return a promise to support async actions.
387 * @see {@link https://node-tap.org/docs/api/test-lifecycle-events}
388 * @param fn
389 */
390 teardown(fn: () => void | Promise<void>): void;
391
392 /**
393 * Fail the test with a timeout error if it goes longer than the specified number of ms.
394 *
395 * Call t.setTimeout(0) to remove the timeout setting.
396 *
397 * When this is called on the top-level tap object, it sets the runners timeout value
398 * to the specified value for that test process as well.
399 */
400 setTimeout(n: number): void;
401
402 /**
403 * Call the end() method on all child tests, and then on this one.
404 */
405 endAll(): void;
406
407 /**
408 * Automatically end() the test on the next turn of the event loop after its internal queue is drained.
409 */
410 autoend(value: boolean): void;
411
412 /**
413 * When an uncaught exception is raised in the context of a test,
414 * then this method is used to handle the error. It fails the test,
415 * and prints out appropriate information about the stack, message, current test,
416 * and so on.
417 *
418 * Generally, you never need to worry about this directly.
419 */
420 threw(error: Error, extra?: Error, proxy?: Test): void;
421
422 /**
423 * Sets a pragma switch for a set of boolean keys in the argument.
424 *
425 * The only pragma currently supported by the TAP parser is strict,
426 * which tells the parser to treat non-TAP output as a failure.
427 */
428 pragma(set: Options.Pragma): void;
429
430 /**
431 * Specify that a given number of tests are going to be run.
432 *
433 * This may only be called before running any asserts or child tests.
434 */
435 plan(n: number, comment?: string): void;
436
437 /**
438 * Call when tests are done running. This is not necessary if t.plan() was used,
439 * or if the test function returns a Promise.
440 *
441 * If you call t.end() explicitly more than once, an error will be raised.
442 */
443 end(): void;
444
445 /**
446 * Create a subtest.
447 *
448 * Returns a Promise which resolves with the parent when the child test is completed.
449 * @param name - The name for this subtest.
450 * @param extra - Any options this subtest should adhere to.
451 * @param cb - The function containing the sub-tests. If not present, the test
452 * will automatically be marked as a todo.
453 */
454 test(name: string, extra?: Options.Test, cb?: (t: Test) => Promise<void> | void): Promise<void>;
455
456 /**
457 * Create a subtest.
458 *
459 * Returns a Promise which resolves with the parent when the child test is completed.
460 * @param name - The name for this subtest.
461 * @param cb - The function containing the sub-tests. If not present, the test
462 * will automatically be marked as a todo.
463 */
464 test(name: string, cb?: (t: Test) => Promise<void> | void): Promise<void>;
465
466 /**
467 * Exactly the same as t.test(), but adds todo: true in the options.
468 */
469 todo(name: string, cb?: (t: Test) => Promise<void> | void): Promise<void>;
470 todo(name: string, extra?: Options.Test, cb?: (t: Test) => Promise<void> | void): Promise<void>;
471
472 /**
473 * Exactly the same as t.test(), but adds skip: true in the options.
474 */
475 skip(name: string, cb?: (t: Test) => Promise<void> | void): Promise<void>;
476 skip(name: string, extra?: Options.Test, cb?: (t: Test) => Promise<void> | void): Promise<void>;
477
478 /**
479 * Exactly the same as t.test(), but adds only: true in the options.
480 *
481 * @see {@link https://node-tap.org/docs/api/only}
482 */
483 only(name: string, cb?: (t: Test) => Promise<void> | void): Promise<void>;
484 only(name: string, extra?: Options.Test, cb?: (t: Test) => Promise<void> | void): Promise<void>;
485
486 current(): Test;
487
488 /**
489 * Parse standard input as if it was a child test named /dev/stdin.
490 *
491 * Returns a Promise which resolves with the parent when the input stream is
492 * completed.
493 */
494 stdin(name: string, extra?: Options.Bag): Promise<void>;
495
496 /**
497 * Sometimes, instead of running a child test directly inline, you might
498 * want to run a TAP producting test as a child process, and treat its
499 * standard output as the TAP stream.
500 *
501 * Returns a Promise which resolves with the parent when the child process
502 * is completed.
503 *
504 * @see {@link https://node-tap.org/docs/api/advanced/#tspawncommand-arguments-options-name}
505 */
506 spawn(
507 cmd: string,
508 args: string,
509 options?: Options.Bag,
510 name?: string,
511 extra?: Options.Spawn,
512 ): Promise<void>;
513
514 done(): void;
515
516 /**
517 * Return true if everything so far is ok.
518 */
519 passing(): boolean;
520
521 pass(message?: string, extra?: Options.Assert): boolean;
522
523 fail(message?: string, extra?: Options.Assert): boolean;
524
525 /**
526 * This is used for creating assertion methods on the Test class.
527 *
528 * @param name The name of the assertion method.
529 * @param length The amount of arguments the assertion has.
530 * @param fn The code to be ran when this assertion is called.
531 *
532 * @example
533 * // Add an assertion that a string is in Title Case
534 * // It takes one argument (the string to be tested)
535 * t.Test.prototype.addAssert('titleCase', 1, function (str, message, extra) {
536 * message = message || 'should be in Title Case'
537 * // the string in Title Case
538 * const tc = str.toLowerCase().replace(/\b./, match => match.toUpperCase())
539 * // should always return another assert call, or
540 * // this.pass(message) or this.fail(message, extra)
541 * return this.equal(str, tc, message, extra)
542 * })
543 *
544 * t.titleCase('This Passes')
545 * t.titleCase('however, tHis tOTaLLy faILS')
546 */
547 addAssert(name: string, length: number, fn: (...args: any[]) => boolean): boolean;
548
549 comment(message: string, ...args: any[]): void;
550
551 /**
552 * Use this when things are severely broken, and cannot be reasonably handled. Immediately terminates the entire test run.
553 */
554 bailout(reason?: string): void;
555
556 /**
557 * Run the provided function once before any tests are ran.
558 * If this function returns a promise, it will wait for the promise to
559 * resolve, before running any tests.
560 */
561 before(fn: () => any): void;
562
563 /**
564 * Before any child test (or any children of any child tests, etc.) the
565 * supplied function is called with the test object that it's prefixing.
566 *
567 * If the function returns a Promise, then that is used as the indication of
568 * doneness. Thus, async functions automatically end when all of their
569 * awaited Promises are complete.
570 */
571 beforeEach(fn: (() => any) | ((childTest: any) => any)): void;
572
573 /**
574 * This is called after each child test (or any children of any child tests,
575 * on down the tree). Like beforeEach, it's called with the child test
576 * object, and can return a Promise to perform asynchronous operations.
577 */
578 afterEach(fn: (() => any) | ((childTest: any) => any)): void;
579
580 /**
581 * Formats a string from a snapshot. This can be used to remove variables
582 * and replace them with sentinel values.
583 *
584 * @see {@link https://node-tap.org/docs/api/snapshot-testing/}
585 *
586 * @example
587 * t.cleanSnapshot = s => {
588 * return s.replace(/ time=[0-9]+$/g, ' time={time}')
589 * }
590 */
591 cleanSnapshot: (s: string) => string;
592
593 /**
594 * Formats the data argument of any snapshot into this string.
595 *
596 * @see {@link https://node-tap.org/docs/api/snapshot-testing/}
597 *
598 * @example t.formatSnapshot = object => JSON.stringify(object)
599 */
600 formatSnapshot: (obj: any) => string;
601
602 /**
603 * Create a fixture object to specify hard links and symbolic links
604 * in the fixture definition object passed to t.testdir().
605 */
606 fixture(type: "symlink" | "link", content: string): Fixture.Instance;
607 fixture(type: "file", content: string | Buffer): Fixture.Instance;
608 fixture(type: "dir", content: Fixture.Spec): Fixture.Instance;
609
610 /**
611 * Create a fresh directory with the specified fixtures,
612 * which is deleted on test teardown. Returns the directory name.
613 *
614 * @see {@link https://node-tap.org/docs/api/fixtures/}
615 */
616 testdir(spec?: Fixture.Spec): string;
617
618 readonly testdirName: string;
619
620 /**
621 * This is an object which is inherited by child tests, and is a handy place to put
622 * various contextual information.
623 *
624 * t.context will only be inherited by child tests if it is an object.
625 *
626 * This typically will be used with lifecycle events, such as beforeEach or afterEach.
627 * @see {@link https://node-tap.org/docs/api/test-lifecycle-events}
628 */
629 context: any;
630
631 /**
632 * This is a read-only property set to the string value provided
633 * as the name argument to t.test(), or an empty string if no name is provided.
634 */
635 readonly name: string;
636
637 /**
638 * Set to true to only run child tests that have only: true
639 * set in their options (or are run with t.only(), which is the same thing).
640 */
641 runOnly: boolean;
642
643 /**
644 * If you set the t.jobs property to a number greater than 1,
645 * then it will enable parallel execution of all of this test's children.
646 */
647 jobs: number;
648
649 // TODO: Investigate whether - using generics - this could
650 // return the type of module provided unioned with the mocks?
651
652 /**
653 * Takes a path to a module and returns the specified module in context of the
654 * mocks provided.
655 *
656 * @see {@link https://node-tap.org/docs/api/mocks/}
657 *
658 * @param modulePath - The string path to the module that is being required,
659 * relative to the current test file.
660 * @param mocks - The key/value pairs of paths (relative to the current test)
661 * and the value that should be returned when anything in the loaded module requires
662 * those modules.
663 */
664 mock(modulePath: string, mocks: Record<string, any>): any;
665
666 // ----
667 // Assertions below this line!
668 // ----
669
670 /**
671 * Verifies that the object is truthy.
672 */
673 ok: Assertions.Basic;
674
675 /**
676 * Verifies that the object is not truthy.
677 */
678 notOk: Assertions.Basic;
679
680 /**
681 * If the object is an error, then the assertion fails.
682 *
683 * Note: if an error is encountered unexpectedly,
684 * it's often better to simply throw it. The Test object will handle this as a failure.
685 */
686 error: Assertions.Basic;
687
688 /**
689 * Verify that the event emitter emits the named event before the end of the test.
690 */
691 emits(eventEmitter: EventEmitter, event: string, message?: string, extra?: Options.Assert): void;
692
693 /**
694 * Verifies that the promise (or promise-returning function) rejects.
695 *
696 * If an expected error is provided,
697 * then also verify that the rejection matches the expected error.
698 */
699 rejects(
700 promiseOrFn: Promise<any> | ((...args: any[]) => Promise<any>),
701 expectedError: any,
702 message?: string,
703 extra?: Options.Assert,
704 ): Promise<void>;
705 rejects(
706 promiseOrFn: Promise<any> | ((...args: any[]) => Promise<any>),
707 message?: string,
708 extra?: Options.Assert,
709 ): Promise<void>;
710
711 /**
712 * Verifies that the promise (or promise-returning function) resolves,
713 * making no expectation about the value that the promise resolves to.
714 */
715 resolves(
716 promiseOrFn: Promise<any> | ((...args: any[]) => Promise<any>),
717 message?: string,
718 extra?: Options.Assert,
719 ): Promise<void>;
720
721 /**
722 * Verifies that the promise (or promise-returning function) resolves
723 * and that the value of the promise matches the wanted pattern using t.match.
724 *
725 * @see match
726 */
727 resolveMatch(
728 promiseOrFn: Promise<any> | ((...args: any[]) => Promise<any>),
729 wanted: any,
730 message?: string,
731 extra?: Options.Assert,
732 ): Promise<void>;
733
734 /**
735 * Verifies that the promise (or promise-returning function) resolves, and
736 * furthermore that the value of the promise matches the snapshot.
737 *
738 * Note: since promises always reject and resolve asynchronously, this
739 * assertion is implemented asynchronously. As such, it does not return a
740 * boolean to indicate its passing status. Instead, it returns a Promise
741 * that resolves when it is completed.
742 */
743 resolveMatchSnapshot(
744 promiseOrFn: Promise<any> | ((...args: any[]) => Promise<any>),
745 message?: string,
746 extra?: Options.Assert,
747 ): Promise<void>;
748
749 // WARN: This is not described in the documentation formally anymore?
750
751 /**
752 * Checks if the output in data matches the data with this snapshot name.
753 *
754 * @see {@link https://node-tap.org/docs/api/snapshot-testing/}
755 */
756 matchSnapshot(output: any, message?: string, extra?: Options.Assert): boolean;
757
758 /**
759 * Expect the function to throw an error.
760 * If an expected error is provided, then also verify that the thrown error
761 * matches the expected error.
762 *
763 * If the function has a name, and the message is not provided,
764 * then the function name will be used as the message.
765 *
766 * If the function is not provided, then this will be treated as a todo test.
767 */
768 throws: Assertions.Throws;
769
770 /**
771 * Verify that the provided function does not throw.
772 *
773 * If the function has a name, and the message is not provided,
774 * then the function name will be used as the message.
775 *
776 * If the function is not provided, then this will be treated as a todo test.
777 *
778 * Note: If an error is encountered unexpectedly,
779 * it's often better to simply throw it. The Test object will handle this as a failure.
780 */
781 doesNotThrow: Assertions.DoesNotThrow;
782
783 /**
784 * Expect the function to throw an uncaught exception at some point in the future,
785 * before the test ends.
786 * If the test ends without having thrown the expected error, then the test fails.
787 *
788 * If the error is thrown synchronously, or within a promise,
789 * then the t.throws() or t.rejects() methods are more appropriate.
790 *
791 * If called multiple times, then the uncaught exception errors must be emitted in the order called.
792 */
793 expectUncaughtException(
794 fn?: (...args: any[]) => any,
795 expectedError?: Error,
796 message?: string,
797 extra?: Options.Assert,
798 ): boolean;
799
800 /**
801 * Verify that the object found is exactly the same (that is, ===)
802 * to the object that is wanted.
803 */
804 equal: Assertions.Equal;
805
806 /**
807 * Inverse of t.equal().
808 *
809 * Verify that the object found is not exactly the same (that is, !==)
810 * as the object that is wanted.
811 */
812 not: Assertions.NotEqual;
813
814 /**
815 * Verify that the found object is deeply equivalent to the wanted object.
816 *
817 * Uses non-strict equality for scalars (ie, ==).
818 */
819 same: Assertions.Equal;
820
821 /**
822 * Inverse of t.same().
823 *
824 * Verify that the found object is not deeply equivalent to the unwanted object.
825 * Uses non-strict inequality (ie, !=) for scalars.
826 */
827 notSame: Assertions.NotEqual;
828
829 /**
830 * Strict version of t.same().
831 *
832 * Verify that the found object is deeply equivalent to the wanted object.
833 * Uses strict equality for scalars (ie, ===).
834 */
835 strictSame: Assertions.Equal;
836
837 /**
838 * Inverse of t.strictSame().
839 *
840 * Verify that the found object is not deeply equivalent to the unwanted object.
841 * Uses strict equality for scalars (ie, ===).
842 */
843 strictNotSame: Assertions.NotEqual;
844
845 /**
846 * Verify that the found object contains all of the provided fields,
847 * and that they are of the same type and value as the pattern provided.
848 *
849 * @see has
850 */
851 hasStrict: Assertions.Match;
852
853 /**
854 * Verify that the found object matches the pattern provided.
855 *
856 * If pattern is a regular expression, and found is a string, then verify that the string matches the pattern.
857 * If the pattern is a string, and found is a string, then verify that the pattern occurs within the string somewhere.
858 * If pattern is an object, then verify that all of the (enumerable) fields in the pattern match the corresponding fields in the object using this same algorithm.
859 *
860 * This is useful when you want to verify that an object has a certain set of required fields, but additional fields are ok.
861 *
862 * @example {x:/a[sdf]{3}/} would successfully match {x:'asdf',y:'z'}.
863 */
864 match: Assertions.Match;
865
866 /**
867 * Verify that the found object contains all of the provided fields, and that they coerce to the same values, even if the types do not match.
868 *
869 * This does not do advanced/loose matching based on constructor, regexp patterns, and so on, like t.match() does.
870 * You may specify key: undefined in the pattern to ensure that a field is not defined in the found object,
871 * but it will not differentiate between a missing property and a property set to undefined.
872 */
873 has: Assertions.Match;
874
875 /**
876 * Verify that the found object contains the provided property and that it is not undefined. Searches the prototype chain as well as "own" properties.
877 *
878 * @example t.hasProp({ a: 1, b: 2 }, 'a') would succeed, while both t.hasProp({ a: 1, b: 2 }, 'c') and t.hasProp({ a: undefined, b: 2 }, 'a') would fail.
879 */
880 hasProp: Assertions.Match;
881
882 /**
883 * Verifies that the object found contains each of the property names in propertyList, and that they are not undefined. Searches prototype chain as well as "own" properties.
884 *
885 * @example t.hasProps({ a: 1, b: 2 }, ['a', 'b']) would succeed, while both t.hasProp({ a: 1, b: 2 }, ['a', 'c']) and t.hasProp({ a: undefined, b: 2 }, ['a', 'b']) would fail.
886 */
887 hasProps: Assertions.Match;
888
889 /**
890 * Inverse of match().
891 *
892 * Verify that the found object does not match the pattern provided.
893 */
894 notMatch: Assertions.Match;
895
896 /**
897 * Verify that the object is of the type provided.
898 *
899 * Type can be a string that matches the typeof value of the object,
900 * or the string name of any constructor in the object's prototype chain,
901 * or a constructor function in the object's prototype chain.
902 *
903 * @example type(new Date(), "object") - true
904 * @example type(new Date(), "Date") - true
905 * @example type(new Date(), Date) - true
906 */
907 type: Assertions.Type;
908 }
909
910 namespace Fixture {
911 interface Instance {
912 type: "symlink" | "link" | "file" | "dir";
913 content: string | Buffer | Spec;
914 }
915
916 interface Spec {
917 [pathname: string]: string | Buffer | Instance | Spec;
918 }
919 }
920
921 interface MochaIt {
922 (name?: string, fn?: (a: any) => any): void;
923 skip: (name?: string, fn?: (a: any) => any) => void;
924 todo: (name?: string, fn?: (a: any) => any) => void;
925 }
926
927 interface Mocha {
928 it: MochaIt;
929 describe: (name?: string, fn?: (a: any) => any) => void;
930 global: () => void;
931 }
932
933 // Little hack to simulate the Test class on the tap export
934 interface TestConstructor {
935 new(options?: Options.Test): Test;
936 prototype: Test;
937 }
938
939 class Tap extends Test {
940 Test: TestConstructor;
941 mocha: Mocha;
942 mochaGlobals: () => void;
943 }
944 }
945}
946
947declare const tap: Tap.Tap;
948export = tap;