@@ -14,7 +14,8 @@ import { createPackageJson, createTsconfig, expectErrors } from '../fixtures.js'
14
14
const tsFiles = {
15
15
'file.ts' : `
16
16
import { foo } from './foo'
17
- export const message = \`\${foo} \${(typeof __filename === 'undefined' ? import.meta.url : __filename).split(/[\\\\/]/).pop()}\` as string
17
+ import { json } from './json.json'
18
+ export const message = \`\${foo} \${json} \${(typeof __filename === 'undefined' ? import.meta.url : __filename).split(/[\\\\/]/).pop()}\` as string
18
19
export { async } from './foo'
19
20
` ,
20
21
'foo.ts' : `
@@ -36,6 +37,7 @@ const tsFiles = {
36
37
'esm-syntax.js' : 'export default "cts export"' ,
37
38
'bar.ts' : 'export type A = 1; export { bar } from "pkg"' ,
38
39
'async.ts' : 'export default "async"' ,
40
+ 'json.json' : JSON . stringify ( { json : 'json' } ) ,
39
41
'node_modules/pkg' : {
40
42
'package.json' : createPackageJson ( {
41
43
name : 'pkg' ,
@@ -54,7 +56,7 @@ const tsFiles = {
54
56
55
57
export default testSuite ( ( { describe } , node : NodeApis ) => {
56
58
describe ( 'API' , ( { describe } ) => {
57
- describe ( 'CommonJS' , ( { test } ) => {
59
+ describe ( 'CommonJS' , ( { describe , test } ) => {
58
60
test ( 'cli' , async ( ) => {
59
61
await using fixture = await createFixture ( {
60
62
'index.ts' : 'import { message } from \'./file\';\n\nconsole.log(message, new Error().stack);' ,
@@ -104,12 +106,12 @@ export default testSuite(({ describe }, node: NodeApis) => {
104
106
nodeOptions : [ ] ,
105
107
} ) ;
106
108
107
- expect ( stdout ) . toBe ( 'Fails as expected\nfoo bar file.ts\nUnregistered' ) ;
109
+ expect ( stdout ) . toBe ( 'Fails as expected\nfoo bar json file.ts\nUnregistered' ) ;
108
110
} ) ;
109
111
110
112
describe ( 'tsx.require()' , ( { test } ) => {
111
113
test ( 'loads' , async ( ) => {
112
- await using fixture = await createFixture ( {
114
+ const fixture = await createFixture ( {
113
115
'require.cjs' : `
114
116
const path = require('node:path');
115
117
const tsx = require(${ JSON . stringify ( tsxCjsApiPath ) } );
@@ -135,13 +137,14 @@ export default testSuite(({ describe }, node: NodeApis) => {
135
137
` ,
136
138
...tsFiles ,
137
139
} ) ;
140
+ console . log ( fixture . path ) ;
138
141
139
142
const { stdout } = await execaNode ( fixture . getPath ( 'require.cjs' ) , [ ] , {
140
143
nodePath : node . path ,
141
144
nodeOptions : [ ] ,
142
145
} ) ;
143
146
144
- expect ( stdout ) . toMatch ( / F a i l s a s e x p e c t e d \n f o o b a r f i l e .t s \n f i l e .t s \? n a m e s p a c e = \d + \n U n p o l l u t e d g l o b a l r e q u i r e / ) ;
147
+ expect ( stdout ) . toMatch ( / F a i l s a s e x p e c t e d \n f o o b a r j s o n f i l e .t s \n f i l e .t s \? n a m e s p a c e = \d + \n U n p o l l u t e d g l o b a l r e q u i r e / ) ;
145
148
} ) ;
146
149
147
150
test ( 'catchable' , async ( ) => {
@@ -197,7 +200,7 @@ export default testSuite(({ describe }, node: NodeApis) => {
197
200
nodeOptions : [ ] ,
198
201
} ) ;
199
202
200
- expect ( stdout ) . toBe ( 'foo bar file.ts\nfoo bar file.ts\nfoo bar file.ts\nUnregistered' ) ;
203
+ expect ( stdout ) . toBe ( 'foo bar json file.ts\nfoo bar json file.ts\nfoo bar json file.ts\nUnregistered' ) ;
201
204
} ) ;
202
205
203
206
test ( 'namespace' , async ( ) => {
@@ -229,7 +232,7 @@ export default testSuite(({ describe }, node: NodeApis) => {
229
232
nodeOptions : [ ] ,
230
233
} ) ;
231
234
232
- expect ( stdout ) . toBe ( 'foo bar file.ts\nasync' ) ;
235
+ expect ( stdout ) . toBe ( 'foo bar json file.ts\nasync' ) ;
233
236
} ) ;
234
237
} ) ;
235
238
} ) ;
@@ -277,7 +280,7 @@ export default testSuite(({ describe }, node: NodeApis) => {
277
280
nodeOptions : [ ] ,
278
281
} ) ;
279
282
280
- expect ( stdout ) . toBe ( 'Fails as expected\nfoo bar file.ts?nocache' ) ;
283
+ expect ( stdout ) . toBe ( 'Fails as expected\nfoo bar json file.ts?nocache' ) ;
281
284
} ) ;
282
285
283
286
describe ( 'register / unregister' , ( { test, describe } ) => {
@@ -323,7 +326,7 @@ export default testSuite(({ describe }, node: NodeApis) => {
323
326
nodePath : node . path ,
324
327
nodeOptions : [ ] ,
325
328
} ) ;
326
- expect ( stdout ) . toBe ( 'Fails as expected 1\nfoo bar file.ts?2\nFails as expected 2\nfoo bar file.ts?4' ) ;
329
+ expect ( stdout ) . toBe ( 'Fails as expected 1\nfoo bar json file.ts?2\nFails as expected 2\nfoo bar json file.ts?4' ) ;
327
330
} ) ;
328
331
329
332
test ( 'onImport' , async ( ) => {
@@ -347,7 +350,7 @@ export default testSuite(({ describe }, node: NodeApis) => {
347
350
nodePath : node . path ,
348
351
nodeOptions : [ ] ,
349
352
} ) ;
350
- expect ( stdout ) . toBe ( 'file.ts\nfoo.ts\npromises\nbar.ts\nindex.js\nnode:process' ) ;
353
+ expect ( stdout ) . toBe ( 'file.ts\nfoo.ts\njson.json\ npromises\nbar.ts\nindex.js\nnode:process' ) ;
351
354
} ) ;
352
355
353
356
test ( 'namespace & onImport' , async ( ) => {
@@ -375,7 +378,7 @@ export default testSuite(({ describe }, node: NodeApis) => {
375
378
nodePath : node . path ,
376
379
nodeOptions : [ ] ,
377
380
} ) ;
378
- expect ( stdout ) . toBe ( 'file.ts\nfoo.ts\nbar.ts\nindex.js' ) ;
381
+ expect ( stdout ) . toBe ( 'file.ts\nfoo.ts\njson.json\ nbar.ts\nindex.js' ) ;
379
382
} ) ;
380
383
381
384
describe ( 'tsconfig' , ( { test } ) => {
@@ -547,9 +550,9 @@ export default testSuite(({ describe }, node: NodeApis) => {
547
550
} ) ;
548
551
549
552
if ( node . supports . cjsInterop ) {
550
- 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 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 t s e x p o r t \n f o o b a r 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 / ) ;
553
+ 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 t s e x p o r t \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 / ) ;
551
554
} else {
552
- 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 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 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 / ) ;
555
+ 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 / ) ;
553
556
}
554
557
} ) ;
555
558
@@ -583,7 +586,7 @@ export default testSuite(({ describe }, node: NodeApis) => {
583
586
nodePath : node . path ,
584
587
nodeOptions : [ ] ,
585
588
} ) ;
586
- 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 f i l e \. t s \? t s x - n a m e s p a c e = \d + \n f o o b a r 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 / ) ;
589
+ 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 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 / ) ;
587
590
} ) ;
588
591
589
592
test ( 'mts from commonjs' , async ( ) => {
0 commit comments