@@ -13,20 +13,13 @@ import {
1313 it ,
1414} from "./describe.ts" ;
1515import { TestSuiteInternal } from "./test_suite.ts" ;
16- import {
17- assertSpyCall ,
18- assertSpyCalls ,
19- FakeTime ,
20- Spy ,
21- spy ,
22- stub ,
23- } from "./test_deps.ts" ;
16+ import { assertSpyCall , assertSpyCalls , Spy , spy , stub } from "./test_deps.ts" ;
2417
2518Deno . test ( "global" , async ( t ) => {
2619 class TestContext implements Deno . TestContext {
2720 steps : TestContext [ ] ;
2821 spies : {
29- step : Spy < void > ;
22+ step : Spy ;
3023 } ;
3124
3225 constructor ( ) {
@@ -78,32 +71,37 @@ Deno.test("global", async (t) => {
7871 eachTimer : number ;
7972 }
8073
81- function beforeAllFns ( ) {
74+ let timerIdx = 1 ;
75+ const timers = new Map < number , number > ( ) ;
76+ function hookFns ( ) {
77+ timerIdx = 1 ;
78+ timers . clear ( ) ;
8279 return {
8380 beforeAllFn : spy ( async function ( this : GlobalContext ) {
8481 await Promise . resolve ( ) ;
85- this . allTimer = setTimeout ( ( ) => { } , Number . MAX_SAFE_INTEGER ) ;
82+ this . allTimer = timerIdx ++ ;
83+ timers . set ( this . allTimer , setTimeout ( ( ) => { } , 10000 ) ) ;
8684 } ) ,
8785 afterAllFn : spy ( async function ( this : GlobalContext ) {
8886 await Promise . resolve ( ) ;
89- clearTimeout ( this . allTimer ) ;
87+ clearTimeout ( timers . get ( this . allTimer ) ) ;
9088 } ) ,
9189 beforeEachFn : spy ( async function ( this : GlobalContext ) {
9290 await Promise . resolve ( ) ;
93- this . eachTimer = setTimeout ( ( ) => { } , Number . MAX_SAFE_INTEGER ) ;
91+ this . eachTimer = timerIdx ++ ;
92+ timers . set ( this . eachTimer , setTimeout ( ( ) => { } , 10000 ) ) ;
9493 } ) ,
9594 afterEachFn : spy ( async function ( this : GlobalContext ) {
9695 await Promise . resolve ( ) ;
97- clearTimeout ( this . eachTimer ) ;
96+ clearTimeout ( timers . get ( this . eachTimer ) ) ;
9897 } ) ,
9998 } ;
10099 }
101100
102101 await t . step ( "global hooks" , async ( ) => {
103102 const test = stub ( Deno , "test" ) ,
104- time = new FakeTime ( ) ,
105103 fns = [ spy ( ) , spy ( ) ] ,
106- { beforeAllFn, afterAllFn, beforeEachFn, afterEachFn } = beforeAllFns ( ) ;
104+ { beforeAllFn, afterAllFn, beforeEachFn, afterEachFn } = hookFns ( ) ;
107105
108106 try {
109107 beforeAll ( beforeAllFn ) ;
@@ -131,7 +129,6 @@ Deno.test("global", async (t) => {
131129 } finally {
132130 TestSuiteInternal . reset ( ) ;
133131 test . restore ( ) ;
134- time . restore ( ) ;
135132 }
136133
137134 let fn = fns [ 0 ] ;
@@ -159,7 +156,7 @@ Deno.test("global", async (t) => {
159156 await t . step ( "it" , async ( t ) => {
160157 async function assertOptions < T > (
161158 expectedOptions : Omit < Deno . TestDefinition , "name" | "fn" > ,
162- cb : ( fn : Spy < void > ) => void ,
159+ cb : ( fn : Spy ) => void ,
163160 ) : Promise < void > {
164161 const test = stub ( Deno , "test" ) ;
165162 const fn = spy ( ) ;
@@ -195,13 +192,13 @@ Deno.test("global", async (t) => {
195192 }
196193
197194 async function assertMinimumOptions (
198- cb : ( fn : Spy < void > ) => void ,
195+ cb : ( fn : Spy ) => void ,
199196 ) : Promise < void > {
200197 await assertOptions ( { } , cb ) ;
201198 }
202199
203200 async function assertAllOptions (
204- cb : ( fn : Spy < void > ) => void ,
201+ cb : ( fn : Spy ) => void ,
205202 ) : Promise < void > {
206203 await assertOptions ( baseOptions , cb ) ;
207204 }
@@ -334,13 +331,13 @@ Deno.test("global", async (t) => {
334331
335332 await t . step ( "only" , async ( t ) => {
336333 async function assertMinimumOptions (
337- cb : ( fn : Spy < void > ) => void ,
334+ cb : ( fn : Spy ) => void ,
338335 ) : Promise < void > {
339336 await assertOptions ( { only : true } , cb ) ;
340337 }
341338
342339 async function assertAllOptions (
343- cb : ( fn : Spy < void > ) => void ,
340+ cb : ( fn : Spy ) => void ,
344341 ) : Promise < void > {
345342 await assertOptions ( { ...baseOptions , only : true } , cb ) ;
346343 }
@@ -480,13 +477,13 @@ Deno.test("global", async (t) => {
480477
481478 await t . step ( "ignore" , async ( t ) => {
482479 async function assertMinimumOptions (
483- cb : ( fn : Spy < void > ) => void ,
480+ cb : ( fn : Spy ) => void ,
484481 ) : Promise < void > {
485482 await assertOptions ( { ignore : true } , cb ) ;
486483 }
487484
488485 async function assertAllOptions (
489- cb : ( fn : Spy < void > ) => void ,
486+ cb : ( fn : Spy ) => void ,
490487 ) : Promise < void > {
491488 await assertOptions ( { ...baseOptions , ignore : true } , cb ) ;
492489 }
@@ -628,7 +625,7 @@ Deno.test("global", async (t) => {
628625 await t . step ( "describe" , async ( t ) => {
629626 async function assertOptions (
630627 expectedOptions : Omit < Deno . TestDefinition , "name" | "fn" > ,
631- cb : ( fns : Spy < void > [ ] ) => void ,
628+ cb : ( fns : Spy [ ] ) => void ,
632629 ) : Promise < void > {
633630 const test = stub ( Deno , "test" ) ;
634631 const fns = [ spy ( ) , spy ( ) ] ;
@@ -676,13 +673,13 @@ Deno.test("global", async (t) => {
676673 }
677674
678675 async function assertMinimumOptions (
679- cb : ( fns : Spy < void > [ ] ) => void ,
676+ cb : ( fns : Spy [ ] ) => void ,
680677 ) : Promise < void > {
681678 await assertOptions ( { } , cb ) ;
682679 }
683680
684681 async function assertAllOptions (
685- cb : ( fns : Spy < void > [ ] ) => void ,
682+ cb : ( fns : Spy [ ] ) => void ,
686683 ) : Promise < void > {
687684 await assertOptions ( { ...baseOptions } , cb ) ;
688685 }
@@ -851,13 +848,13 @@ Deno.test("global", async (t) => {
851848
852849 await t . step ( "only" , async ( t ) => {
853850 async function assertMinimumOptions (
854- cb : ( fns : Spy < void > [ ] ) => void ,
851+ cb : ( fns : Spy [ ] ) => void ,
855852 ) : Promise < void > {
856853 await assertOptions ( { only : true } , cb ) ;
857854 }
858855
859856 async function assertAllOptions (
860- cb : ( fns : Spy < void > [ ] ) => void ,
857+ cb : ( fns : Spy [ ] ) => void ,
861858 ) : Promise < void > {
862859 await assertOptions ( { ...baseOptions , only : true } , cb ) ;
863860 }
@@ -1042,13 +1039,13 @@ Deno.test("global", async (t) => {
10421039
10431040 await t . step ( "ignore" , async ( t ) => {
10441041 async function assertMinimumOptions (
1045- cb : ( fns : Spy < void > [ ] ) => void ,
1042+ cb : ( fns : Spy [ ] ) => void ,
10461043 ) : Promise < void > {
10471044 await assertOptions ( { ignore : true } , cb ) ;
10481045 }
10491046
10501047 async function assertAllOptions (
1051- cb : ( fns : Spy < void > [ ] ) => void ,
1048+ cb : ( fns : Spy [ ] ) => void ,
10521049 ) : Promise < void > {
10531050 await assertOptions ( { ...baseOptions , ignore : true } , cb ) ;
10541051 }
@@ -1233,7 +1230,7 @@ Deno.test("global", async (t) => {
12331230
12341231 await t . step ( "nested only" , async ( t ) => {
12351232 async function assertOnly (
1236- cb : ( fns : Spy < void > [ ] ) => void ,
1233+ cb : ( fns : Spy [ ] ) => void ,
12371234 ) : Promise < void > {
12381235 const test = stub ( Deno , "test" ) ;
12391236 const fns = [ spy ( ) , spy ( ) , spy ( ) ] ;
@@ -1327,19 +1324,17 @@ Deno.test("global", async (t) => {
13271324 async function assertHooks (
13281325 cb : (
13291326 options : {
1330- beforeAllFn : Spy < void > ;
1331- afterAllFn : Spy < void > ;
1332- beforeEachFn : Spy < void > ;
1333- afterEachFn : Spy < void > ;
1334- fns : Spy < void > [ ] ;
1327+ beforeAllFn : Spy ;
1328+ afterAllFn : Spy ;
1329+ beforeEachFn : Spy ;
1330+ afterEachFn : Spy ;
1331+ fns : Spy [ ] ;
13351332 } ,
13361333 ) => void ,
13371334 ) {
13381335 const test = stub ( Deno , "test" ) ,
1339- time = new FakeTime ( ) ,
13401336 fns = [ spy ( ) , spy ( ) ] ,
1341- { beforeAllFn, afterAllFn, beforeEachFn, afterEachFn } =
1342- beforeAllFns ( ) ;
1337+ { beforeAllFn, afterAllFn, beforeEachFn, afterEachFn } = hookFns ( ) ;
13431338
13441339 try {
13451340 cb ( { beforeAllFn, afterAllFn, beforeEachFn, afterEachFn, fns } ) ;
@@ -1360,7 +1355,6 @@ Deno.test("global", async (t) => {
13601355 } finally {
13611356 TestSuiteInternal . reset ( ) ;
13621357 test . restore ( ) ;
1363- time . restore ( ) ;
13641358 }
13651359
13661360 let fn = fns [ 0 ] ;
@@ -1434,10 +1428,8 @@ Deno.test("global", async (t) => {
14341428 "nested" ,
14351429 async ( ) => {
14361430 const test = stub ( Deno , "test" ) ,
1437- time = new FakeTime ( ) ,
14381431 fns = [ spy ( ) , spy ( ) ] ,
1439- { beforeAllFn, afterAllFn, beforeEachFn, afterEachFn } =
1440- beforeAllFns ( ) ;
1432+ { beforeAllFn, afterAllFn, beforeEachFn, afterEachFn } = hookFns ( ) ;
14411433
14421434 try {
14431435 describe ( "example" , ( ) => {
@@ -1474,7 +1466,6 @@ Deno.test("global", async (t) => {
14741466 } finally {
14751467 TestSuiteInternal . reset ( ) ;
14761468 test . restore ( ) ;
1477- time . restore ( ) ;
14781469 }
14791470
14801471 let fn = fns [ 0 ] ;
@@ -1509,34 +1500,34 @@ Deno.test("global", async (t) => {
15091500 "nested with hooks" ,
15101501 async ( ) => {
15111502 const test = stub ( Deno , "test" ) ,
1512- time = new FakeTime ( ) ,
15131503 fns = [ spy ( ) , spy ( ) ] ,
1514- { beforeAllFn, afterAllFn, beforeEachFn, afterEachFn } =
1515- beforeAllFns ( ) ,
1504+ { beforeAllFn, afterAllFn, beforeEachFn, afterEachFn } = hookFns ( ) ,
15161505 beforeAllFnNested = spy ( async function ( this : NestedContext ) {
15171506 await Promise . resolve ( ) ;
1518- this . allTimerNested = setTimeout (
1519- ( ) => { } ,
1520- Number . MAX_SAFE_INTEGER ,
1507+ this . allTimerNested = timerIdx ++ ;
1508+ timers . set (
1509+ this . allTimerNested ,
1510+ setTimeout ( ( ) => { } , 10000 ) ,
15211511 ) ;
15221512 } ) ,
15231513 afterAllFnNested = spy (
15241514 async function ( this : NestedContext ) {
15251515 await Promise . resolve ( ) ;
1526- clearTimeout ( this . allTimerNested ) ;
1516+ clearTimeout ( timers . get ( this . allTimerNested ) ) ;
15271517 } ,
15281518 ) ,
15291519 beforeEachFnNested = spy ( async function ( this : NestedContext ) {
15301520 await Promise . resolve ( ) ;
1531- this . eachTimerNested = setTimeout (
1532- ( ) => { } ,
1533- Number . MAX_SAFE_INTEGER ,
1521+ this . eachTimerNested = timerIdx ++ ;
1522+ timers . set (
1523+ this . eachTimerNested ,
1524+ setTimeout ( ( ) => { } , 10000 ) ,
15341525 ) ;
15351526 } ) ,
15361527 afterEachFnNested = spy (
15371528 async function ( this : NestedContext ) {
15381529 await Promise . resolve ( ) ;
1539- clearTimeout ( this . eachTimerNested ) ;
1530+ clearTimeout ( timers . get ( this . eachTimerNested ) ) ;
15401531 } ,
15411532 ) ;
15421533
@@ -1581,7 +1572,6 @@ Deno.test("global", async (t) => {
15811572 } finally {
15821573 TestSuiteInternal . reset ( ) ;
15831574 test . restore ( ) ;
1584- time . restore ( ) ;
15851575 }
15861576
15871577 let fn = fns [ 0 ] ;
0 commit comments