@@ -38,11 +38,7 @@ describe("API: resources interceptors option", () => {
3838 const dom = await JSDOM . fromURL ( url , {
3939 resources : { dispatcher : agent , interceptors : [ cache ] }
4040 } ) ;
41- try {
42- assert . equal ( dom . window . document . querySelector ( "p" ) . textContent , "cached response" ) ;
43- } finally {
44- dom . window . close ( ) ;
45- }
41+ assert . equal ( dom . window . document . querySelector ( "p" ) . textContent , "cached response" ) ;
4642 }
4743 } finally {
4844 await agent . destroy ( ) ;
@@ -70,11 +66,7 @@ describe("API: resources interceptors option", () => {
7066 const dom = await JSDOM . fromURL ( serverURL ( redirect ) , {
7167 resources : { dispatcher : agent , interceptors : [ cache ] }
7268 } ) ;
73- try {
74- assert . equal ( dom . window . document . querySelector ( "p" ) . textContent , "redirect target" ) ;
75- } finally {
76- dom . window . close ( ) ;
77- }
69+ assert . equal ( dom . window . document . querySelector ( "p" ) . textContent , "redirect target" ) ;
7870 }
7971 assert . equal ( redirectRequests , 1 , "The second redirect response must come from the cache" ) ;
8072 assert . equal ( targetRequests , 2 , "Both loads must reach the redirect target" ) ;
@@ -1248,12 +1240,8 @@ describe("API: resources interceptors option", () => {
12481240 }
12491241 } ) ;
12501242
1251- try {
1252- window . stop ( ) ;
1253- assert . equal ( await canceled . promise , signal . reason ) ;
1254- } finally {
1255- window . close ( ) ;
1256- }
1243+ window . stop ( ) ;
1244+ assert . equal ( await canceled . promise , signal . reason ) ;
12571245 } ) ;
12581246
12591247 it ( "should report cancellation once when a fetch-backed interceptor rejects" , async ( ) => {
@@ -1284,7 +1272,6 @@ describe("API: resources interceptors option", () => {
12841272 assert . equal ( errors . length , 1 ) ;
12851273 assert . equal ( errors [ 0 ] , signal . reason ) ;
12861274 } finally {
1287- window . close ( ) ;
12881275 await server . destroy ( ) ;
12891276 }
12901277 } ) ;
@@ -1306,23 +1293,19 @@ describe("API: resources interceptors option", () => {
13061293 }
13071294 } ) ;
13081295
1309- try {
1310- window . stop ( ) ;
1311- response . resolve ( new Response ( new ReadableStream ( {
1312- pull ( controller ) {
1313- controller . close ( ) ;
1314- bodyAction . resolve ( { action : "read" } ) ;
1315- } ,
1316- cancel ( reason ) {
1317- bodyAction . resolve ( { action : "cancel" , reason } ) ;
1318- }
1319- } , { highWaterMark : 0 } ) ) ) ;
1320- const { action, reason } = await bodyAction . promise ;
1321- assert . equal ( action , "cancel" ) ;
1322- assert . equal ( reason , signal . reason ) ;
1323- } finally {
1324- window . close ( ) ;
1325- }
1296+ window . stop ( ) ;
1297+ response . resolve ( new Response ( new ReadableStream ( {
1298+ pull ( controller ) {
1299+ controller . close ( ) ;
1300+ bodyAction . resolve ( { action : "read" } ) ;
1301+ } ,
1302+ cancel ( reason ) {
1303+ bodyAction . resolve ( { action : "cancel" , reason } ) ;
1304+ }
1305+ } , { highWaterMark : 0 } ) ) ) ;
1306+ const { action, reason } = await bodyAction . promise ;
1307+ assert . equal ( action , "cancel" ) ;
1308+ assert . equal ( reason , signal . reason ) ;
13261309 } ) ;
13271310
13281311 it ( "should not report a second error when canceling a late response rejects" , async ( ) => {
@@ -1344,22 +1327,18 @@ describe("API: resources interceptors option", () => {
13441327 }
13451328 } ) ;
13461329
1347- try {
1348- window . stop ( ) ;
1349- response . resolve ( new Response ( new ReadableStream ( {
1350- cancel ( ) {
1351- canceled . resolve ( ) ;
1352- throw new Error ( "Response cleanup failed" ) ;
1353- }
1354- } , { highWaterMark : 0 } ) ) ) ;
1355- await canceled . promise ;
1356- // Let the cleanup rejection reach the interceptor's rejection handler.
1357- await nextTurn ( ) ;
1358- assert . equal ( errors . length , 1 ) ;
1359- assert . equal ( errors [ 0 ] , signal . reason ) ;
1360- } finally {
1361- window . close ( ) ;
1362- }
1330+ window . stop ( ) ;
1331+ response . resolve ( new Response ( new ReadableStream ( {
1332+ cancel ( ) {
1333+ canceled . resolve ( ) ;
1334+ throw new Error ( "Response cleanup failed" ) ;
1335+ }
1336+ } , { highWaterMark : 0 } ) ) ) ;
1337+ await canceled . promise ;
1338+ // Let the cleanup rejection reach the interceptor's rejection handler.
1339+ await nextTurn ( ) ;
1340+ assert . equal ( errors . length , 1 ) ;
1341+ assert . equal ( errors [ 0 ] , signal . reason ) ;
13631342 } ) ;
13641343
13651344 it ( "should cancel a pass-through request stopped while connecting" , async ( ) => {
@@ -1393,7 +1372,6 @@ describe("API: resources interceptors option", () => {
13931372 assert . equal ( errors . length , 1 ) ;
13941373 assert . equal ( errors [ 0 ] . name , "AbortError" ) ;
13951374 } finally {
1396- window . close ( ) ;
13971375 await agent . destroy ( ) ;
13981376 await server . destroy ( ) ;
13991377 }
@@ -1418,14 +1396,10 @@ describe("API: resources interceptors option", () => {
14181396 }
14191397 } ) ;
14201398
1421- try {
1422- const script = window . document . createElement ( "script" ) ;
1423- script . src = "/stopped.js" ;
1424- window . document . body . append ( script ) ;
1425- assert . equal ( called , false ) ;
1426- } finally {
1427- window . close ( ) ;
1428- }
1399+ const script = window . document . createElement ( "script" ) ;
1400+ script . src = "/stopped.js" ;
1401+ window . document . body . append ( script ) ;
1402+ assert . equal ( called , false ) ;
14291403 } ) ;
14301404
14311405 it ( "should abort the request signal synchronously when window.close() is called" , async ( ) => {
0 commit comments