@@ -1170,22 +1170,40 @@ describe('e2e', function () {
11701170 env : {
11711171 ...process . env ,
11721172 NODE_PATH : path . resolve ( __dirname , 'fixtures' , 'node-path' ) ,
1173+ NODE_OPTIONS : '--expose-gc' ,
11731174 } ,
11741175 } ) ;
11751176 await shell . waitForPrompt ( ) ;
11761177 shell . assertNoErrors ( ) ;
11771178 } ) ;
11781179
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 ;
11811182 result = await shell . executeLine ( 'require("a")' ) ;
11821183 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 ' / ) ;
11831184 result = await shell . executeLine ( 'require("./a")' ) ;
11841185 expect ( result ) . to . match ( / ^ A $ / m) ;
11851186 result = await shell . executeLine ( 'require("b")' ) ;
11861187 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) ;
11871190 result = await shell . executeLine ( 'require("c")' ) ;
11881191 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 ( ) ;
11891207 } ) ;
11901208
11911209 it ( 'Can use Node.js APIs without any extra effort' , async function ( ) {
@@ -1194,6 +1212,7 @@ describe('e2e', function () {
11941212 `fs.readFileSync(${ JSON . stringify ( __filename ) } , 'utf8')`
11951213 ) ;
11961214 expect ( result ) . to . include ( 'Too lazy to write a fixture' ) ;
1215+ shell . assertNoErrors ( ) ;
11971216 } ) ;
11981217 } ) ;
11991218
0 commit comments