@@ -15,10 +15,13 @@ import {
15
15
EXPERIMENTAL_MODULES_FLAG ,
16
16
nodeSupportsEsmHooks ,
17
17
nodeSupportsImportAssertions ,
18
+ nodeSupportsUnflaggedJsonImports ,
18
19
nodeSupportsSpawningChildProcess ,
19
20
nodeUsesNewHooksApi ,
20
21
resetNodeEnvironment ,
21
22
TEST_DIR ,
23
+ tsSupportsImportAssertions ,
24
+ tsSupportsResolveJsonModule ,
22
25
} from './helpers' ;
23
26
import { createExec , createSpawn , ExecReturn } from './exec-helpers' ;
24
27
import { join , resolve } from 'path' ;
@@ -268,40 +271,39 @@ test.suite('esm', (test) => {
268
271
} ) ;
269
272
270
273
test . suite ( 'supports import assertions' , ( test ) => {
271
- test . runIf ( nodeSupportsImportAssertions ) ;
272
-
273
- test . suite ( 'node >=17.5.0' , ( test ) => {
274
- test . runIf ( semver . gte ( process . version , '17.5.0' ) ) ;
274
+ test . runIf (
275
+ nodeSupportsImportAssertions &&
276
+ tsSupportsImportAssertions &&
277
+ tsSupportsResolveJsonModule
278
+ ) ;
275
279
276
- test ( 'Can import JSON modules with appropriate assertion' , async ( t ) => {
277
- const { err, stdout } = await exec (
278
- `${ CMD_ESM_LOADER_WITHOUT_PROJECT } ./importJson.ts` ,
279
- {
280
- cwd : resolve ( TEST_DIR , 'esm-import-assertions' ) ,
281
- }
282
- ) ;
283
- expect ( err ) . toBe ( null ) ;
284
- expect ( stdout . trim ( ) ) . toBe (
285
- 'A fuchsia car has 2 seats and the doors are open.\nDone!'
286
- ) ;
287
- } ) ;
280
+ const macro = test . macro ( ( flags : string ) => async ( t ) => {
281
+ const { err, stdout } = await exec (
282
+ `${ CMD_ESM_LOADER_WITHOUT_PROJECT } ${ flags } ./importJson.ts` ,
283
+ {
284
+ cwd : resolve ( TEST_DIR , 'esm-import-assertions' ) ,
285
+ }
286
+ ) ;
287
+ expect ( err ) . toBe ( null ) ;
288
+ expect ( stdout . trim ( ) ) . toBe (
289
+ 'A fuchsia car has 2 seats and the doors are open.\nDone!'
290
+ ) ;
288
291
} ) ;
289
292
290
- test . suite ( 'node <17.5.0' , ( test ) => {
291
- test . runIf ( semver . lt ( process . version , '17.5.0' ) ) ;
292
-
293
- test ( 'Can import JSON using the appropriate flag and assertion' , async ( t ) => {
294
- const { err, stdout } = await exec (
295
- `${ CMD_ESM_LOADER_WITHOUT_PROJECT } --experimental-json-modules ./importJson.ts` ,
296
- {
297
- cwd : resolve ( TEST_DIR , 'esm-import-assertions' ) ,
298
- }
299
- ) ;
300
- expect ( err ) . toBe ( null ) ;
301
- expect ( stdout . trim ( ) ) . toBe (
302
- 'A fuchsia car has 2 seats and the doors are open.\nDone!'
303
- ) ;
304
- } ) ;
293
+ test . suite (
294
+ 'when node does not require --experimental-json-modules' ,
295
+ ( test ) => {
296
+ test . runIf ( nodeSupportsUnflaggedJsonImports ) ;
297
+ test ( 'Can import JSON modules with appropriate assertion' , macro , '' ) ;
298
+ }
299
+ ) ;
300
+ test . suite ( 'when node requires --experimental-json-modules' , ( test ) => {
301
+ test . runIf ( ! nodeSupportsUnflaggedJsonImports ) ;
302
+ test (
303
+ 'Can import JSON using the appropriate flag and assertion' ,
304
+ macro ,
305
+ '--experimental-json-modules'
306
+ ) ;
305
307
} ) ;
306
308
} ) ;
307
309
0 commit comments