@@ -401,19 +401,37 @@ export interface TeardownFn {
401
401
( fn : ( ) => void ) : void ;
402
402
}
403
403
404
+ export type ImplementationFn < Args extends any [ ] , Context = unknown > =
405
+ ( ( t : ExecutionContext < Context > , ...args : Args ) => PromiseLike < void > ) |
406
+ ( ( t : ExecutionContext < Context > , ...args : Args ) => Subscribable ) |
407
+ ( ( t : ExecutionContext < Context > , ...args : Args ) => void ) ;
408
+
409
+ export type TitleFn < Args extends any [ ] > = ( providedTitle : string | undefined , ...args : Args ) => string ;
410
+
411
+ /** A reusable test or hook implementation. */
412
+ export type Macro < Args extends any [ ] , Context = unknown > = {
413
+ /** The function that is executed when the macro is used. */
414
+ readonly exec : ImplementationFn < Args , Context > ;
415
+
416
+ /** Generates a test title when this macro is used. */
417
+ readonly title ?: TitleFn < Args > ;
418
+ } ;
419
+
420
+ /** A test or hook implementation. */
421
+ export type Implementation < Args extends any [ ] , Context = unknown > = ImplementationFn < Args , Context > | Macro < Args , Context > ;
422
+
404
423
export interface TryFn < Context = unknown > {
405
424
/**
406
425
* Attempt to run some assertions. The result must be explicitly committed or discarded or else
407
- * the test will fail. A macro may be provided. The title may help distinguish attempts from
408
- * one another.
426
+ * the test will fail. The title may help distinguish attempts from one another.
409
427
*/
410
- < Args extends any [ ] > ( title : string , fn : EitherMacro < Args , Context > , ...args : Args ) : Promise < TryResult > ;
428
+ < Args extends any [ ] > ( title : string , fn : Implementation < Args , Context > , ...args : Args ) : Promise < TryResult > ;
411
429
412
430
/**
413
431
* Attempt to run some assertions. The result must be explicitly committed or discarded or else
414
- * the test will fail. A macro may be provided.
432
+ * the test will fail.
415
433
*/
416
- < Args extends any [ ] > ( fn : EitherMacro < Args , Context > , ...args : Args ) : Promise < TryResult > ;
434
+ < Args extends any [ ] > ( fn : Implementation < Args , Context > , ...args : Args ) : Promise < TryResult > ;
417
435
}
418
436
419
437
export interface AssertionError extends Error { }
@@ -451,34 +469,15 @@ export interface TryResult {
451
469
discard ( options ?: CommitDiscardOptions ) : void ;
452
470
}
453
471
454
- // FIXME(novemberborn) Refactor implementations to be different types returning a promise,, subscribable, or void, not a
455
- // single type returning a union. A union with void as a return type doesn't make sense.
456
- export type ImplementationResult = PromiseLike < void > | Subscribable | boolean | void ;
457
- export type Implementation < Context = unknown > = ( t : ExecutionContext < Context > ) => ImplementationResult ;
458
-
459
- /** A reusable test or hook implementation. */
460
- export type UntitledMacro < Args extends any [ ] , Context = unknown > = ( t : ExecutionContext < Context > , ...args : Args ) => ImplementationResult ;
472
+ export interface TestInterface < Context = unknown > {
473
+ /** Declare a concurrent test. Additional arguments are passed along. */
474
+ < Args extends any [ ] > ( title : string , implementation : Implementation < Args , Context > , ...args : Args ) : void ;
461
475
462
- /** A reusable test or hook implementation. */
463
- export type Macro < Args extends any [ ] , Context = unknown > = UntitledMacro < Args , Context > & {
464
476
/**
465
- * Implement this function to generate a test (or hook) title whenever this macro is used. `providedTitle` contains
466
- * the title provided when the test or hook was declared. Also receives the remaining test arguments .
477
+ * Declare a concurrent test that uses a macro. The macro is responsible for generating a unique test title.
478
+ * Additional arguments are passed along .
467
479
*/
468
- title ?: ( providedTitle : string | undefined , ...args : Args ) => string ;
469
- } ;
470
-
471
- export type EitherMacro < Args extends any [ ] , Context > = Macro < Args , Context > | UntitledMacro < Args , Context > ;
472
-
473
- export interface TestInterface < Context = unknown > {
474
- /** Declare a concurrent test. */
475
- ( title : string , implementation : Implementation < Context > ) : void ;
476
-
477
- /** Declare a concurrent test that uses a macro. Additional arguments are passed to the macro. */
478
- < T extends any [ ] > ( title : string , macro : EitherMacro < T , Context > , ...rest : T ) : void ;
479
-
480
- /** Declare a concurrent test that uses a macro. The macro is responsible for generating a unique test title. */
481
- < T extends any [ ] > ( macro : EitherMacro < T , Context > , ...rest : T ) : void ;
480
+ < Args extends any [ ] > ( macro : Macro < Args , Context > , ...args : Args ) : void ;
482
481
483
482
/** Declare a hook that is run once, after all tests have passed. */
484
483
after : AfterInterface < Context > ;
@@ -501,21 +500,16 @@ export interface TestInterface<Context = unknown> {
501
500
only : OnlyInterface < Context > ;
502
501
skip : SkipInterface < Context > ;
503
502
todo : TodoDeclaration ;
503
+ macro : MacroDeclaration < Context > ;
504
504
meta : MetaInterface ;
505
505
}
506
506
507
507
export interface AfterInterface < Context = unknown > {
508
- /** Declare a hook that is run once, after all tests have passed. */
509
- ( implementation : Implementation < Context > ) : void ;
508
+ /** Declare a hook that is run once, after all tests have passed. Additional arguments are passed along. */
509
+ < Args extends any [ ] > ( title : string , implementation : Implementation < Args , Context > , ... args : Args ) : void ;
510
510
511
- /** Declare a hook that is run once, after all tests have passed. */
512
- ( title : string , implementation : Implementation < Context > ) : void ;
513
-
514
- /** Declare a hook that is run once, after all tests have passed. Additional arguments are passed to the macro. */
515
- < T extends any [ ] > ( title : string , macro : EitherMacro < T , Context > , ...rest : T ) : void ;
516
-
517
- /** Declare a hook that is run once, after all tests have passed. */
518
- < T extends any [ ] > ( macro : EitherMacro < T , Context > , ...rest : T ) : void ;
511
+ /** Declare a hook that is run once, after all tests have passed. Additional arguments are passed along. */
512
+ < Args extends any [ ] > ( implementation : Implementation < Args , Context > , ...args : Args ) : void ;
519
513
520
514
/** Declare a hook that is run once, after all tests are done. */
521
515
always : AlwaysInterface < Context > ;
@@ -524,99 +518,66 @@ export interface AfterInterface<Context = unknown> {
524
518
}
525
519
526
520
export interface AlwaysInterface < Context = unknown > {
527
- /** Declare a hook that is run once, after all tests are done. */
528
- ( implementation : Implementation < Context > ) : void ;
529
-
530
- /** Declare a hook that is run once, after all tests are done. */
531
- ( title : string , implementation : Implementation < Context > ) : void ;
521
+ /** Declare a hook that is run once, after all tests are done. Additional arguments are passed along. */
522
+ < Args extends any [ ] > ( title : string , implementation : Implementation < Args , Context > , ...args : Args ) : void ;
532
523
533
- /** Declare a hook that is run once, after all tests are done. Additional arguments are passed to the macro. */
534
- < T extends any [ ] > ( title : string , macro : EitherMacro < T , Context > , ...rest : T ) : void ;
535
-
536
- /** Declare a hook that is run once, after all tests are done. */
537
- < T extends any [ ] > ( macro : EitherMacro < T , Context > , ...rest : T ) : void ;
524
+ /** Declare a hook that is run once, after all tests are done. Additional arguments are passed along. */
525
+ < Args extends any [ ] > ( implementation : Implementation < Args , Context > , ...args : Args ) : void ;
538
526
539
527
skip : HookSkipInterface < Context > ;
540
528
}
541
529
542
530
export interface BeforeInterface < Context = unknown > {
543
- /** Declare a hook that is run once, before all tests. */
544
- ( implementation : Implementation < Context > ) : void ;
531
+ /** Declare a hook that is run once, before all tests. Additional arguments are passed along. */
532
+ < Args extends any [ ] > ( title : string , implementation : Implementation < Args , Context > , ... args : Args ) : void ;
545
533
546
- /** Declare a hook that is run once, before all tests. */
547
- ( title : string , implementation : Implementation < Context > ) : void ;
548
-
549
- /** Declare a hook that is run once, before all tests. Additional arguments are passed to the macro. */
550
- < T extends any [ ] > ( title : string , macro : EitherMacro < T , Context > , ...rest : T ) : void ;
551
-
552
- /** Declare a hook that is run once, before all tests. */
553
- < T extends any [ ] > ( macro : EitherMacro < T , Context > , ...rest : T ) : void ;
534
+ /** Declare a hook that is run once, before all tests. Additional arguments are passed along. */
535
+ < Args extends any [ ] > ( implementation : Implementation < Args , Context > , ...args : Args ) : void ;
554
536
555
537
skip : HookSkipInterface < Context > ;
556
538
}
557
539
558
540
export interface FailingInterface < Context = unknown > {
559
- /** Declare a concurrent test. The test is expected to fail. */
560
- ( title : string , implementation : Implementation < Context > ) : void ;
541
+ /** Declare a concurrent test. Additional arguments are passed along. The test is expected to fail. */
542
+ < Args extends any [ ] > ( title : string , implementation : Implementation < Args , Context > , ... args : Args ) : void ;
561
543
562
544
/**
563
- * Declare a concurrent test that uses a macro. Additional arguments are passed to the macro .
564
- * The test is expected to fail.
545
+ * Declare a concurrent test that uses a macro. Additional arguments are passed along .
546
+ * The macro is responsible for generating a unique test title. The test is expected to fail.
565
547
*/
566
- < T extends any [ ] > ( title : string , macro : EitherMacro < T , Context > , ...rest : T ) : void ;
567
-
568
- /**
569
- * Declare a concurrent test that uses a macro. The macro is responsible for generating a unique test title.
570
- * The test is expected to fail.
571
- */
572
- < T extends any [ ] > ( macro : EitherMacro < T , Context > , ...rest : T ) : void ;
548
+ < Args extends any [ ] > ( macro : Macro < Args , Context > , ...args : Args ) : void ;
573
549
574
550
only : OnlyInterface < Context > ;
575
551
skip : SkipInterface < Context > ;
576
552
}
577
553
578
554
export interface HookSkipInterface < Context = unknown > {
579
555
/** Skip this hook. */
580
- ( implementation : Implementation < Context > ) : void ;
581
-
582
- /** Skip this hook. */
583
- ( title : string , implementation : Implementation < Context > ) : void ;
556
+ < Args extends any [ ] > ( title : string , implementation : Implementation < Args , Context > , ...args : Args ) : void ;
584
557
585
558
/** Skip this hook. */
586
- < T extends any [ ] > ( title : string , macro : EitherMacro < T , Context > , ...rest : T ) : void ;
587
-
588
- /** Skip this hook. */
589
- < T extends any [ ] > ( macro : EitherMacro < T , Context > , ...rest : T ) : void ;
559
+ < Args extends any [ ] > ( implementation : Implementation < Args , Context > , ...args : Args ) : void ;
590
560
}
591
561
592
562
export interface OnlyInterface < Context = unknown > {
593
- /** Declare a test. Only this test and others declared with `.only()` are run. */
594
- ( title : string , implementation : Implementation < Context > ) : void ;
595
-
596
- /**
597
- * Declare a test that uses a macro. Additional arguments are passed to the macro.
598
- * Only this test and others declared with `.only()` are run.
599
- */
600
- < T extends any [ ] > ( title : string , macro : EitherMacro < T , Context > , ...rest : T ) : void ;
563
+ /** Declare a test. Additional arguments are passed along. Only this test and others declared with `.only()` are run. */
564
+ < Args extends any [ ] > ( title : string , implementation : Implementation < Args , Context > , ...args : Args ) : void ;
601
565
602
566
/**
603
567
* Declare a test that uses a macro. The macro is responsible for generating a unique test title.
604
568
* Only this test and others declared with `.only()` are run.
605
569
*/
606
- < T extends any [ ] > ( macro : EitherMacro < T , Context > , ...rest : T ) : void ;
570
+ < Args extends any [ ] > ( macro : Macro < Args , Context > , ...args : Args ) : void ;
607
571
}
608
572
609
573
export interface SerialInterface < Context = unknown > {
610
- /** Declare a serial test. */
611
- ( title : string , implementation : Implementation < Context > ) : void ;
612
-
613
- /** Declare a serial test that uses a macro. Additional arguments are passed to the macro. */
614
- < T extends any [ ] > ( title : string , macro : EitherMacro < T , Context > , ...rest : T ) : void ;
574
+ /** Declare a serial test. Additional arguments are passed along. */
575
+ < Args extends any [ ] > ( title : string , implementation : Implementation < Args , Context > , ...args : Args ) : void ;
615
576
616
577
/**
617
578
* Declare a serial test that uses a macro. The macro is responsible for generating a unique test title.
618
579
*/
619
- < T extends any [ ] > ( macro : EitherMacro < T , Context > , ...rest : T ) : void ;
580
+ < Args extends any [ ] > ( macro : Macro < Args , Context > , ...args : Args ) : void ;
620
581
621
582
/** Declare a serial hook that is run once, after all tests have passed. */
622
583
after : AfterInterface < Context > ;
@@ -640,20 +601,28 @@ export interface SerialInterface<Context = unknown> {
640
601
641
602
export interface SkipInterface < Context = unknown > {
642
603
/** Skip this test. */
643
- ( title : string , implementation : Implementation < Context > ) : void ;
604
+ < Args extends any [ ] > ( title : string , implementation : Implementation < Args , Context > , ... args : Args ) : void ;
644
605
645
606
/** Skip this test. */
646
- < T extends any [ ] > ( title : string , macro : EitherMacro < T , Context > , ...rest : T ) : void ;
647
-
648
- /** Skip this test. */
649
- < T extends any [ ] > ( macro : EitherMacro < T , Context > , ...rest : T ) : void ;
607
+ < Args extends any [ ] > ( macro : Macro < Args , Context > , ...args : Args ) : void ;
650
608
}
651
609
652
610
export interface TodoDeclaration {
653
611
/** Declare a test that should be implemented later. */
654
612
( title : string ) : void ;
655
613
}
656
614
615
+ export type MacroDeclarationOptions < Args extends any [ ] , Context = unknown > = {
616
+ exec : ImplementationFn < Args , Context > ;
617
+ title : TitleFn < Args > ;
618
+ } ;
619
+
620
+ export interface MacroDeclaration < Context = unknown > {
621
+ /** Declare a reusable test implementation. */
622
+ < Args extends any [ ] > ( exec : ImplementationFn < Args , Context > ) : Macro < Args , Context > ;
623
+ < Args extends any [ ] > ( declaration : MacroDeclarationOptions < Args , Context > ) : Macro < Args , Context > ;
624
+ }
625
+
657
626
export interface MetaInterface {
658
627
/** Path to the test file being executed. */
659
628
file : string ;
0 commit comments