@@ -401,19 +401,37 @@ export interface TeardownFn {
401401 ( fn : ( ) => void ) : void ;
402402}
403403
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+
404423export interface TryFn < Context = unknown > {
405424 /**
406425 * 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.
409427 */
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 > ;
411429
412430 /**
413431 * 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.
415433 */
416- < Args extends any [ ] > ( fn : EitherMacro < Args , Context > , ...args : Args ) : Promise < TryResult > ;
434+ < Args extends any [ ] > ( fn : Implementation < Args , Context > , ...args : Args ) : Promise < TryResult > ;
417435}
418436
419437export interface AssertionError extends Error { }
@@ -451,34 +469,15 @@ export interface TryResult {
451469 discard ( options ?: CommitDiscardOptions ) : void ;
452470}
453471
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 ;
461475
462- /** A reusable test or hook implementation. */
463- export type Macro < Args extends any [ ] , Context = unknown > = UntitledMacro < Args , Context > & {
464476 /**
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 .
467479 */
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 ;
482481
483482 /** Declare a hook that is run once, after all tests have passed. */
484483 after : AfterInterface < Context > ;
@@ -501,21 +500,16 @@ export interface TestInterface<Context = unknown> {
501500 only : OnlyInterface < Context > ;
502501 skip : SkipInterface < Context > ;
503502 todo : TodoDeclaration ;
503+ macro : MacroDeclaration < Context > ;
504504 meta : MetaInterface ;
505505}
506506
507507export 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 ;
510510
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 ;
519513
520514 /** Declare a hook that is run once, after all tests are done. */
521515 always : AlwaysInterface < Context > ;
@@ -524,99 +518,66 @@ export interface AfterInterface<Context = unknown> {
524518}
525519
526520export 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 ;
532523
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 ;
538526
539527 skip : HookSkipInterface < Context > ;
540528}
541529
542530export 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 ;
545533
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 ;
554536
555537 skip : HookSkipInterface < Context > ;
556538}
557539
558540export 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 ;
561543
562544 /**
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.
565547 */
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 ;
573549
574550 only : OnlyInterface < Context > ;
575551 skip : SkipInterface < Context > ;
576552}
577553
578554export interface HookSkipInterface < Context = unknown > {
579555 /** 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 ;
584557
585558 /** 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 ;
590560}
591561
592562export 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 ;
601565
602566 /**
603567 * Declare a test that uses a macro. The macro is responsible for generating a unique test title.
604568 * Only this test and others declared with `.only()` are run.
605569 */
606- < T extends any [ ] > ( macro : EitherMacro < T , Context > , ...rest : T ) : void ;
570+ < Args extends any [ ] > ( macro : Macro < Args , Context > , ...args : Args ) : void ;
607571}
608572
609573export 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 ;
615576
616577 /**
617578 * Declare a serial test that uses a macro. The macro is responsible for generating a unique test title.
618579 */
619- < T extends any [ ] > ( macro : EitherMacro < T , Context > , ...rest : T ) : void ;
580+ < Args extends any [ ] > ( macro : Macro < Args , Context > , ...args : Args ) : void ;
620581
621582 /** Declare a serial hook that is run once, after all tests have passed. */
622583 after : AfterInterface < Context > ;
@@ -640,20 +601,28 @@ export interface SerialInterface<Context = unknown> {
640601
641602export interface SkipInterface < Context = unknown > {
642603 /** Skip this test. */
643- ( title : string , implementation : Implementation < Context > ) : void ;
604+ < Args extends any [ ] > ( title : string , implementation : Implementation < Args , Context > , ... args : Args ) : void ;
644605
645606 /** 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 ;
650608}
651609
652610export interface TodoDeclaration {
653611 /** Declare a test that should be implemented later. */
654612 ( title : string ) : void ;
655613}
656614
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+
657626export interface MetaInterface {
658627 /** Path to the test file being executed. */
659628 file : string ;
0 commit comments