• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --experimental-json-modules
2import '../common/index.mjs';
3import { path } from '../common/fixtures.mjs';
4import { strictEqual, ok } from 'assert';
5import { spawn } from 'child_process';
6
7import secret from '../fixtures/experimental.json';
8
9strictEqual(secret.ofLife, 42);
10
11// Test warning message
12const child = spawn(process.execPath, [
13  '--experimental-json-modules',
14  path('/es-modules/json-modules.mjs'),
15]);
16
17let stderr = '';
18child.stderr.setEncoding('utf8');
19child.stderr.on('data', (data) => {
20  stderr += data;
21});
22child.on('close', (code, signal) => {
23  strictEqual(code, 0);
24  strictEqual(signal, null);
25  ok(stderr.toString().includes(
26    'ExperimentalWarning: Importing JSON modules is an experimental feature. ' +
27    'This feature could change at any time'
28  ));
29});
30