@@ -15,10 +15,13 @@ import {
1515 EXPERIMENTAL_MODULES_FLAG ,
1616 nodeSupportsEsmHooks ,
1717 nodeSupportsImportAssertions ,
18+ nodeSupportsUnflaggedJsonImports ,
1819 nodeSupportsSpawningChildProcess ,
1920 nodeUsesNewHooksApi ,
2021 resetNodeEnvironment ,
2122 TEST_DIR ,
23+ tsSupportsImportAssertions ,
24+ tsSupportsResolveJsonModule ,
2225} from './helpers' ;
2326import { createExec , createSpawn , ExecReturn } from './exec-helpers' ;
2427import { join , resolve } from 'path' ;
@@ -268,40 +271,39 @@ test.suite('esm', (test) => {
268271 } ) ;
269272
270273 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+ ) ;
275279
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+ ) ;
288291 } ) ;
289292
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+ ) ;
305307 } ) ;
306308 } ) ;
307309
0 commit comments