Skip to content

Commit 2e2d44b

Browse files
committed
Added tests for experimental json modules no longer requiring flag
1 parent 281dbc1 commit 2e2d44b

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

src/test/esm-loader.spec.ts

+32-11
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,38 @@ test.suite('esm', (test) => {
261261
test.suite('supports import assertions', (test) => {
262262
test.runIf(nodeSupportsImportAssertions);
263263

264-
test('Can import JSON using the appropriate flag and assertion', async (t) => {
265-
const { err, stdout } = await exec(
266-
`${CMD_ESM_LOADER_WITHOUT_PROJECT} --experimental-json-modules ./importJson.ts`,
267-
{
268-
cwd: resolve(TEST_DIR, 'esm-import-assertions'),
269-
}
270-
);
271-
expect(err).toBe(null);
272-
expect(stdout.trim()).toBe(
273-
'A fuchsia car has 2 seats and the doors are open.\nDone!'
274-
);
264+
test.suite('node >=17.5.0', (test) => {
265+
test.runIf(semver.gte(process.version, '17.5.0'));
266+
267+
test('Can import JSON modules with appropriate assertion', async (t) => {
268+
const { err, stdout } = await exec(
269+
`${CMD_ESM_LOADER_WITHOUT_PROJECT} ./importJson.ts`,
270+
{
271+
cwd: resolve(TEST_DIR, 'esm-import-assertions'),
272+
}
273+
);
274+
expect(err).toBe(null);
275+
expect(stdout.trim()).toBe(
276+
'A fuchsia car has 2 seats and the doors are open.\nDone!'
277+
);
278+
});
279+
});
280+
281+
test.suite('node <17.5.0', (test) => {
282+
test.runIf(semver.lt(process.version, '17.5.0'));
283+
284+
test('Can import JSON using the appropriate flag and assertion', async (t) => {
285+
const { err, stdout } = await exec(
286+
`${CMD_ESM_LOADER_WITHOUT_PROJECT} --experimental-json-modules ./importJson.ts`,
287+
{
288+
cwd: resolve(TEST_DIR, 'esm-import-assertions'),
289+
}
290+
);
291+
expect(err).toBe(null);
292+
expect(stdout.trim()).toBe(
293+
'A fuchsia car has 2 seats and the doors are open.\nDone!'
294+
);
295+
});
275296
});
276297
});
277298

0 commit comments

Comments
 (0)