• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import { spawnPromisified } from '../common/index.mjs';
2import { fileURL } from '../common/fixtures.mjs';
3import { doesNotMatch, match, strictEqual } from 'node:assert';
4import { execPath } from 'node:process';
5import { describe, it } from 'node:test';
6
7
8describe('ESM: warn for obsolete hooks provided', { concurrency: true }, () => {
9  it('should not print warnings when no experimental features are enabled or used', async () => {
10    const { code, signal, stderr } = await spawnPromisified(execPath, [
11      '--input-type=module',
12      '--eval',
13      `import ${JSON.stringify(fileURL('es-module-loaders', 'module-named-exports.mjs'))}`,
14    ]);
15
16    doesNotMatch(
17      stderr,
18      /ExperimentalWarning/,
19      new Error('No experimental warning(s) should be emitted when no experimental feature is enabled')
20    );
21    strictEqual(code, 0);
22    strictEqual(signal, null);
23  });
24
25  describe('experimental warnings for enabled experimental feature', () => {
26    for (
27      const [experiment, ...args] of [
28        [
29          /`--experimental-loader` may be removed in the future/,
30          '--experimental-loader',
31          fileURL('es-module-loaders', 'hooks-custom.mjs'),
32        ],
33        [/Network Imports/, '--experimental-network-imports'],
34        [/specifier resolution/, '--experimental-specifier-resolution=node'],
35      ]
36    ) {
37      it(`should print for ${experiment.toString().replaceAll('/', '')}`, async () => {
38        const { code, signal, stderr } = await spawnPromisified(execPath, [
39          ...args,
40          '--input-type=module',
41          '--eval',
42          `import ${JSON.stringify(fileURL('es-module-loaders', 'module-named-exports.mjs'))}`,
43        ]);
44
45        match(stderr, /ExperimentalWarning/);
46        match(stderr, experiment);
47        strictEqual(code, 0);
48        strictEqual(signal, null);
49      });
50    }
51  });
52});
53