node/test/es-module/test-esm-json.mjs
Antoine du Hamel 5a7491b5ac
esm: add a runtime warning when using import assertions
PR-URL: https://github.com/nodejs/node/pull/46901
Refs: https://github.com/nodejs/node/issues/46830
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
2023-03-03 18:31:12 +00:00

24 lines
841 B
JavaScript

import { spawnPromisified } from '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import assert from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';
import secret from '../fixtures/experimental.json' assert { type: 'json' };
describe('ESM: importing JSON', () => {
it('should load JSON', () => {
assert.strictEqual(secret.ofLife, 42);
});
it('should print an experimental warning', async () => {
const { code, signal, stderr } = await spawnPromisified(execPath, [
fixtures.path('/es-modules/json-modules.mjs'),
]);
assert.match(stderr, /ExperimentalWarning: Importing JSON modules/);
assert.match(stderr, /ExperimentalWarning: Import assertions/);
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
});