summaryrefslogtreecommitdiff
path: root/test/es-module/test-esm-json.mjs
blob: 2740c0097f77da09d11b2ace564e82bcec7b523e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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);
  });
});