@@ -50,13 +50,23 @@ const tsFiles = {
50
50
'bar.ts' : 'export type A = 1; export { bar } from "pkg"' ,
51
51
'async.ts' : 'export default "async"' ,
52
52
'json.json' : JSON . stringify ( { json : 'json' } ) ,
53
- 'node_modules/pkg' : {
54
- 'package.json' : createPackageJson ( {
55
- name : 'pkg' ,
56
- type : 'module' ,
57
- exports : './pkg.js' ,
58
- } ) ,
59
- 'pkg.js' : 'import "node:process"; export const bar = "bar";' ,
53
+ node_modules : {
54
+ pkg : {
55
+ 'package.json' : createPackageJson ( {
56
+ name : 'pkg' ,
57
+ type : 'module' ,
58
+ exports : './pkg.js' ,
59
+ } ) ,
60
+ 'pkg.js' : 'import "node:process"; export const bar = "bar";' ,
61
+ } ,
62
+ '@a/b.cjs' : {
63
+ 'package.json' : createPackageJson ( {
64
+ name : '@a/b.cjs' ,
65
+ type : 'module' ,
66
+ exports : './pkg.js' ,
67
+ } ) ,
68
+ 'pkg.js' : 'import "node:process"; export const bar = "bar";' ,
69
+ } ,
60
70
} ,
61
71
'tsconfig.json' : createTsconfig ( {
62
72
compilerOptions : {
@@ -662,8 +672,13 @@ export default testSuite(({ describe }, node: NodeApis) => {
662
672
// Loads cts vis CJS namespace even if there are no exports
663
673
await tsImport('./cjs/exports-no.cts', import.meta.url).catch((error) => console.log(error.constructor.name))
664
674
665
- const cjsExport = await tsImport('./cjs/exports-yes.cts', import.meta.url).then(({ cjsReexport, esmSyntax }) => \`\${cjsReexport} \${esmSyntax}\`, err => err.constructor.name);
666
- console.log(cjsExport);
675
+ const cts = await tsImport('./cjs/exports-yes.cts', import.meta.url).then(({ cjsReexport, esmSyntax }) => \`\${cjsReexport} \${esmSyntax}\`, err => err.constructor.name);
676
+ console.log(cts);
677
+
678
+ const cjs = await tsImport('./cjs/reexport.cjs?query', import.meta.url).then(({ cjsReexport, esmSyntax }) => \`\${cjsReexport} \${esmSyntax}\`, err => err.constructor.name);
679
+ console.log(cjs);
680
+
681
+ await tsImport('@a/b.cjs', import.meta.url);
667
682
668
683
const { message: message2 } = await tsImport('./file.ts?with-query', import.meta.url);
669
684
console.log(message2);
@@ -682,11 +697,15 @@ export default testSuite(({ describe }, node: NodeApis) => {
682
697
nodeOptions : [ ] ,
683
698
} ) ;
684
699
685
- if ( node . supports . cjsInterop ) {
686
- expect ( stdout ) . toMatch ( / F a i l s a s e x p e c t e d 1 \n f o o b a r j s o n f i l e \. t s \? t s x - n a m e s p a c e = \d + \n c t s l o a d e d \n c j s R e e x p o r t e s m s y n t a x \n f o o b a r j s o n f i l e \. t s \? w i t h - q u e r y = & t s x - n a m e s p a c e = \d + \n F a i l s a s e x p e c t e d 2 / ) ;
687
- } else {
688
- expect ( stdout ) . toMatch ( / F a i l s a s e x p e c t e d 1 \n f o o b a r j s o n f i l e \. t s \? t s x - n a m e s p a c e = \d + \n S y n t a x E r r o r \n S y n t a x E r r o r \n f o o b a r j s o n f i l e \. t s \? w i t h - q u e r y = & t s x - n a m e s p a c e = \d + \n F a i l s a s e x p e c t e d 2 / ) ;
689
- }
700
+ expect ( stdout ) . toMatch ( new RegExp ( [
701
+ 'Fails as expected 1' ,
702
+ String . raw `foo bar json file\.ts\?tsx-namespace=\d+` ,
703
+ 'cts loaded' ,
704
+ 'cjsReexport esm syntax' ,
705
+ 'cjsReexport esm syntax' ,
706
+ String . raw `foo bar json file\.ts\?with-query&tsx-namespace=\d+` ,
707
+ 'Fails as expected 2' ,
708
+ ] . join ( String . raw `\n` ) ) ) ;
690
709
} ) ;
691
710
692
711
test ( 'commonjs' , async ( ) => {
@@ -706,12 +725,14 @@ export default testSuite(({ describe }, node: NodeApis) => {
706
725
const { message: message2 } = await tsImport('./file.ts?with-query', __filename);
707
726
console.log(message2);
708
727
709
- const cts = await tsImport('./cjs/exports-yes.cts', __filename).then(({ cjsReexport, esmSyntax }) => \`\${cjsReexport} \${esmSyntax}\`, err => err.constructor.name);
728
+ const cts = await tsImport('./cjs/exports-yes.cts?query ', __filename).then(({ cjsReexport, esmSyntax }) => \`\${cjsReexport} \${esmSyntax}\`, err => err.constructor.name);
710
729
console.log(cts);
711
730
712
- const cjs = await tsImport('./cjs/reexport.cjs', __filename).then(({ cjsReexport, esmSyntax }) => \`\${cjsReexport} \${esmSyntax}\`, err => err.constructor.name);
731
+ const cjs = await tsImport('./cjs/reexport.cjs?query ', __filename).then(({ cjsReexport, esmSyntax }) => \`\${cjsReexport} \${esmSyntax}\`, err => err.constructor.name);
713
732
console.log(cjs);
714
733
734
+ await tsImport('@a/b.cjs', __filename);
735
+
715
736
// Global not polluted
716
737
await import('./file.ts?nocache').catch((error) => {
717
738
console.log('Fails as expected 2');
@@ -725,25 +746,15 @@ export default testSuite(({ describe }, node: NodeApis) => {
725
746
nodePath : node . path ,
726
747
nodeOptions : [ ] ,
727
748
} ) ;
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
- }
749
+
750
+ expect ( stdout ) . toMatch ( new RegExp ( [
751
+ 'Fails as expected 1' ,
752
+ String . raw `foo bar json file\.ts\?tsx-namespace=\d+` ,
753
+ String . raw `foo bar json file\.ts\?with-query&tsx-namespace=\d+` ,
754
+ 'cjsReexport esm syntax' ,
755
+ 'cjsReexport esm syntax' ,
756
+ 'Fails as expected 2' ,
757
+ ] . join ( String . raw `\n` ) ) ) ;
747
758
} ) ;
748
759
749
760
test ( 'mts from commonjs' , async ( ) => {
0 commit comments