Skip to content

Commit

Permalink
Added tests for experimental json modules no longer requiring flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamesernator committed Mar 1, 2022
1 parent 281dbc1 commit 2e2d44b
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions src/test/esm-loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,17 +261,38 @@ test.suite('esm', (test) => {
test.suite('supports import assertions', (test) => {
test.runIf(nodeSupportsImportAssertions);

test('Can import JSON using the appropriate flag and assertion', async (t) => {
const { err, stdout } = await exec(
`${CMD_ESM_LOADER_WITHOUT_PROJECT} --experimental-json-modules ./importJson.ts`,
{
cwd: resolve(TEST_DIR, 'esm-import-assertions'),
}
);
expect(err).toBe(null);
expect(stdout.trim()).toBe(
'A fuchsia car has 2 seats and the doors are open.\nDone!'
);
test.suite('node >=17.5.0', (test) => {
test.runIf(semver.gte(process.version, '17.5.0'));

test('Can import JSON modules with appropriate assertion', async (t) => {
const { err, stdout } = await exec(
`${CMD_ESM_LOADER_WITHOUT_PROJECT} ./importJson.ts`,
{
cwd: resolve(TEST_DIR, 'esm-import-assertions'),
}
);
expect(err).toBe(null);
expect(stdout.trim()).toBe(
'A fuchsia car has 2 seats and the doors are open.\nDone!'
);
});
});

test.suite('node <17.5.0', (test) => {
test.runIf(semver.lt(process.version, '17.5.0'));

test('Can import JSON using the appropriate flag and assertion', async (t) => {
const { err, stdout } = await exec(
`${CMD_ESM_LOADER_WITHOUT_PROJECT} --experimental-json-modules ./importJson.ts`,
{
cwd: resolve(TEST_DIR, 'esm-import-assertions'),
}
);
expect(err).toBe(null);
expect(stdout.trim()).toBe(
'A fuchsia car has 2 seats and the doors are open.\nDone!'
);
});
});
});

Expand Down

0 comments on commit 2e2d44b

Please sign in to comment.