Skip to content

Commit fbcbbcc

Browse files
committed
test: assert tsImport doesnt cache imports
1 parent dae9f0d commit fbcbbcc

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

tests/specs/api.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,27 +363,43 @@ export default testSuite(({ describe }, node: NodeApis) => {
363363
expect(stdout).toBe('Fails as expected\nfoo');
364364
});
365365

366-
test('onImport', async () => {
366+
test('onImport & doesnt cache files', async () => {
367367
await using fixture = await createFixture({
368368
'package.json': JSON.stringify({ type: 'module' }),
369369
'import.mjs': `
370+
import assert from 'assert';
370371
import { tsImport } from ${JSON.stringify(tsxEsmApiPath)};
371-
tsImport('./file.ts', {
372+
const dependenciesA = [];
373+
await tsImport('./file.ts', {
372374
parentURL: import.meta.url,
373375
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);
375385
},
376386
});
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))
377392
`,
378-
'file.ts': 'import(\'./foo.ts\')',
393+
'file.ts': 'import "./foo.ts"; import(\'./bar.ts\')',
379394
'foo.ts': 'console.log(\'foo\' as string)',
395+
'bar.ts': 'import(\'./foo.ts\')',
380396
});
381397

382398
const { stdout } = await execaNode(fixture.getPath('import.mjs'), [], {
383399
nodePath: node.path,
384400
nodeOptions: [],
385401
});
386-
expect(stdout).toBe('file.ts\nfoo.ts\nfoo');
402+
expect(stdout).toBe('foo\nfoo');
387403
});
388404
});
389405
} else {

0 commit comments

Comments
 (0)