Skip to content

Commit aa3f2a1

Browse files
committed
test: scoped cts loading in Node v18
1 parent 8c61236 commit aa3f2a1

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

tests/specs/api.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ export default testSuite(({ describe }, node: NodeApis) => {
480480
nodeOptions: [],
481481
});
482482
expect(stdout).toBe('file.ts\nfoo.ts\njson.json\npromises\nbar.ts\npkg.js\nnode:process');
483+
}, {
484+
retry: 3,
483485
});
484486

485487
test('namespace & onImport', async () => {
@@ -508,6 +510,8 @@ export default testSuite(({ describe }, node: NodeApis) => {
508510
nodeOptions: [],
509511
});
510512
expect(stdout).toBe('file.ts\nfoo.ts\njson.json\nbar.ts\npkg.js');
513+
}, {
514+
retry: 3,
511515
});
512516

513517
describe('tsconfig', ({ test }) => {
@@ -702,6 +706,12 @@ export default testSuite(({ describe }, node: NodeApis) => {
702706
const { message: message2 } = await tsImport('./file.ts?with-query', __filename);
703707
console.log(message2);
704708
709+
const cts = await tsImport('./cjs/exports-yes.cts', __filename).then(({ cjsReexport, esmSyntax }) => \`\${cjsReexport} \${esmSyntax}\`, err => err.constructor.name);
710+
console.log(cts);
711+
712+
const cjs = await tsImport('./cjs/reexport.cjs', __filename).then(({ cjsReexport, esmSyntax }) => \`\${cjsReexport} \${esmSyntax}\`, err => err.constructor.name);
713+
console.log(cjs);
714+
705715
// Global not polluted
706716
await import('./file.ts?nocache').catch((error) => {
707717
console.log('Fails as expected 2');
@@ -715,7 +725,25 @@ export default testSuite(({ describe }, node: NodeApis) => {
715725
nodePath: node.path,
716726
nodeOptions: [],
717727
});
718-
expect(stdout).toMatch(/Fails as expected 1\nfoo bar json file\.ts\?tsx-namespace=\d+\nfoo bar json file\.ts\?with-query=&tsx-namespace=\d+\nFails as expected 2/);
728+
if (node.supports.cjsInterop) {
729+
expect(stdout).toMatch(new RegExp(
730+
`${String.raw`Fails as expected 1\n`
731+
+ String.raw`foo bar json file\.ts\?tsx-namespace=\d+\n`
732+
+ String.raw`foo bar json file\.ts\?with-query=&tsx-namespace=\d+\n`
733+
+ String.raw`cjsReexport esm syntax\n`
734+
+ String.raw`cjsReexport esm syntax\n`
735+
}Fails as expected 2`,
736+
));
737+
} else {
738+
expect(stdout).toMatch(new RegExp(
739+
`${String.raw`Fails as expected 1\n`
740+
+ String.raw`foo bar json file\.ts\?tsx-namespace=\d+\n`
741+
+ String.raw`foo bar json file\.ts\?with-query=&tsx-namespace=\d+\n`
742+
+ String.raw`SyntaxError\n`
743+
+ String.raw`Error\n`
744+
}Fails as expected 2`,
745+
));
746+
}
719747
});
720748

721749
test('mts from commonjs', async () => {

0 commit comments

Comments
 (0)