@@ -6,6 +6,9 @@ import * as fs from 'fs';
6
6
7
7
allowGlobals ( global . getModuleTypeStats ) ;
8
8
9
+ const { importedESM : importedESMBefore ,
10
+ importedCJS : importedCJSBefore } = await global . getModuleTypeStats ( ) ;
11
+
9
12
const basePath =
10
13
new URL ( './node_modules/' , import . meta. url ) ;
11
14
@@ -17,25 +20,24 @@ const createDir = (path) => {
17
20
} ;
18
21
19
22
const moduleName = 'module-counter-by-type' ;
20
-
21
23
const 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 {
34
36
fs . rmSync ( basePath , { recursive : true , force : true } ) ;
35
- } ) ;
37
+ }
36
38
37
39
const { importedESM : importedESMAfter ,
38
- importedCJS : importedCJSAfter } = global . getModuleTypeStats ( ) ;
40
+ importedCJS : importedCJSAfter } = await global . getModuleTypeStats ( ) ;
39
41
40
42
// Dynamic import above should increment ESM counter but not CJS counter
41
43
assert . strictEqual ( importedESMBefore + 1 , importedESMAfter ) ;
0 commit comments