summaryrefslogtreecommitdiff
path: root/test/es-module/test-esm-experimental-warnings.mjs
blob: 85b458258b61340a36e96ccb55a4699b52f5fc82 (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { spawnPromisified } from '../common/index.mjs';
import { fileURL } from '../common/fixtures.mjs';
import { doesNotMatch, match, strictEqual } from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';


describe('ESM: warn for obsolete hooks provided', { concurrency: true }, () => {
  it('should not print warnings when no experimental features are enabled or used', async () => {
    const { code, signal, stderr } = await spawnPromisified(execPath, [
      '--input-type=module',
      '--eval',
      `import ${JSON.stringify(fileURL('es-module-loaders', 'module-named-exports.mjs'))}`,
    ]);

    doesNotMatch(
      stderr,
      /ExperimentalWarning/,
      new Error('No experimental warning(s) should be emitted when no experimental feature is enabled')
    );
    strictEqual(code, 0);
    strictEqual(signal, null);
  });

  describe('experimental warnings for enabled experimental feature', () => {
    for (
      const [experiment, arg] of [
        [/Custom ESM Loaders/, `--experimental-loader=${fileURL('es-module-loaders', 'hooks-custom.mjs')}`],
        [/Network Imports/, '--experimental-network-imports'],
      ]
    ) {
      it(`should print for ${experiment.toString().replaceAll('/', '')}`, async () => {
        const { code, signal, stderr } = await spawnPromisified(execPath, [
          arg,
          '--input-type=module',
          '--eval',
          `import ${JSON.stringify(fileURL('es-module-loaders', 'module-named-exports.mjs'))}`,
        ]);

        match(stderr, /ExperimentalWarning/);
        match(stderr, experiment);
        strictEqual(code, 0);
        strictEqual(signal, null);
      });
    }
  });
});