@@ -6,6 +6,9 @@ import * as fs from 'fs';
66
77allowGlobals ( global . getModuleTypeStats ) ;
88
9+ const { importedESM : importedESMBefore ,
10+ importedCJS : importedCJSBefore } = await global . getModuleTypeStats ( ) ;
11+
912const basePath =
1013 new URL ( './node_modules/' , import . meta. url ) ;
1114
@@ -17,25 +20,24 @@ const createDir = (path) => {
1720} ;
1821
1922const moduleName = 'module-counter-by-type' ;
20-
2123const moduleDir = rel ( `${ moduleName } ` ) ;
22- createDir ( basePath ) ;
23- createDir ( moduleDir ) ;
24- fs . cpSync (
25- fixtures . path ( 'es-modules' , moduleName ) ,
26- moduleDir ,
27- { recursive : true }
28- ) ;
29-
30- const { importedESM : importedESMBefore ,
31- importedCJS : importedCJSBefore } = global . getModuleTypeStats ( ) ;
32-
33- await import ( ` ${ moduleName } ` ) . finally ( ( ) => {
24+ try {
25+ createDir ( basePath ) ;
26+ createDir ( moduleDir ) ;
27+ fs . cpSync (
28+ fixtures . path ( 'es-modules' , moduleName ) ,
29+ moduleDir ,
30+ { recursive : true }
31+ ) ;
32+
33+
34+ await import ( ` ${ moduleName } ` ) ;
35+ } finally {
3436 fs . rmSync ( basePath , { recursive : true , force : true } ) ;
35- } ) ;
37+ }
3638
3739const { importedESM : importedESMAfter ,
38- importedCJS : importedCJSAfter } = global . getModuleTypeStats ( ) ;
40+ importedCJS : importedCJSAfter } = await global . getModuleTypeStats ( ) ;
3941
4042// Dynamic import above should increment ESM counter but not CJS counter
4143assert . strictEqual ( importedESMBefore + 1 , importedESMAfter ) ;
0 commit comments