@@ -363,27 +363,43 @@ export default testSuite(({ describe }, node: NodeApis) => {
363
363
expect ( stdout ) . toBe ( 'Fails as expected\nfoo' ) ;
364
364
} ) ;
365
365
366
- test ( 'onImport' , async ( ) => {
366
+ test ( 'onImport & doesnt cache files ' , async ( ) => {
367
367
await using fixture = await createFixture ( {
368
368
'package.json' : JSON . stringify ( { type : 'module' } ) ,
369
369
'import.mjs' : `
370
+ import assert from 'assert';
370
371
import { tsImport } from ${ JSON . stringify ( tsxEsmApiPath ) } ;
371
- tsImport('./file.ts', {
372
+ const dependenciesA = [];
373
+ await tsImport('./file.ts', {
372
374
parentURL: import.meta.url,
373
375
onImport(file) {
374
- console.log(file.split('/').pop());
376
+ dependenciesA.push(file);
377
+ },
378
+ });
379
+
380
+ const dependenciesB = [];
381
+ await tsImport('./file.ts', {
382
+ parentURL: import.meta.url,
383
+ onImport(file) {
384
+ dependenciesB.push(file);
375
385
},
376
386
});
387
+
388
+ // wait for async import() to finish
389
+ await new Promise((resolve) => setTimeout(resolve, 10));
390
+
391
+ assert(JSON.stringify(dependenciesA) === JSON.stringify(dependenciesB))
377
392
` ,
378
- 'file.ts' : 'import(\'./foo .ts\')' ,
393
+ 'file.ts' : 'import "./foo.ts"; import (\'./bar .ts\')' ,
379
394
'foo.ts' : 'console.log(\'foo\' as string)' ,
395
+ 'bar.ts' : 'import(\'./foo.ts\')' ,
380
396
} ) ;
381
397
382
398
const { stdout } = await execaNode ( fixture . getPath ( 'import.mjs' ) , [ ] , {
383
399
nodePath : node . path ,
384
400
nodeOptions : [ ] ,
385
401
} ) ;
386
- expect ( stdout ) . toBe ( 'file.ts\nfoo.ts \nfoo' ) ;
402
+ expect ( stdout ) . toBe ( 'foo \nfoo' ) ;
387
403
} ) ;
388
404
} ) ;
389
405
} else {
0 commit comments