@@ -1170,22 +1170,40 @@ describe('e2e', function () {
1170
1170
env : {
1171
1171
...process . env ,
1172
1172
NODE_PATH : path . resolve ( __dirname , 'fixtures' , 'node-path' ) ,
1173
+ NODE_OPTIONS : '--expose-gc' ,
1173
1174
} ,
1174
1175
} ) ;
1175
1176
await shell . waitForPrompt ( ) ;
1176
1177
shell . assertNoErrors ( ) ;
1177
1178
} ) ;
1178
1179
1179
- it ( 'require() searches the current working directory according to Node.js rules' , async function ( ) {
1180
- let result ;
1180
+ it ( 'require() and import() search the current working directory according to Node.js rules' , async function ( ) {
1181
+ let result : string ;
1181
1182
result = await shell . executeLine ( 'require("a")' ) ;
1182
1183
expect ( result ) . to . match ( / E r r o r : C a n n o t f i n d m o d u l e ' a ' / ) ;
1183
1184
result = await shell . executeLine ( 'require("./a")' ) ;
1184
1185
expect ( result ) . to . match ( / ^ A $ / m) ;
1185
1186
result = await shell . executeLine ( 'require("b")' ) ;
1186
1187
expect ( result ) . to . match ( / ^ B $ / m) ;
1188
+ result = await shell . executeLine ( 'require("b-esm").value' ) ;
1189
+ expect ( result ) . to . match ( / ^ B - E S M $ / m) ;
1187
1190
result = await shell . executeLine ( 'require("c")' ) ;
1188
1191
expect ( result ) . to . match ( / ^ C $ / m) ;
1192
+ result = await shell . executeLine ( 'import("b").then(m => m.default)' ) ;
1193
+ expect ( result ) . to . match ( / ^ B $ / m) ;
1194
+ result = await shell . executeLine ( 'import("b-esm").then(m => m.value)' ) ;
1195
+ expect ( result ) . to . match ( / ^ B - E S M $ / m) ;
1196
+ } ) ;
1197
+
1198
+ // Regression test for https://github.com/nodejs/node/issues/38695
1199
+ it ( 'import() works when interleaved with GC' , async function ( ) {
1200
+ await shell . executeLine ( 'importESM = () => import("b-esm")' ) ;
1201
+ expect ( await shell . executeLine ( 'globalThis.gc(); "ran gc"' ) ) . to . include (
1202
+ 'ran gc'
1203
+ ) ;
1204
+ const result = await shell . executeLine ( 'importESM().then(m => m.value)' ) ;
1205
+ expect ( result ) . to . match ( / ^ B - E S M $ / m) ;
1206
+ shell . assertNoErrors ( ) ;
1189
1207
} ) ;
1190
1208
1191
1209
it ( 'Can use Node.js APIs without any extra effort' , async function ( ) {
@@ -1194,6 +1212,7 @@ describe('e2e', function () {
1194
1212
`fs.readFileSync(${ JSON . stringify ( __filename ) } , 'utf8')`
1195
1213
) ;
1196
1214
expect ( result ) . to . include ( 'Too lazy to write a fixture' ) ;
1215
+ shell . assertNoErrors ( ) ;
1197
1216
} ) ;
1198
1217
} ) ;
1199
1218
0 commit comments