node/test/es-module/test-esm-experimental-warnings.mjs
Antoine du Hamel d4034dfb62
test: forbid use of named imports for fixtures
PR-URL: https://github.com/nodejs/node/pull/61228
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
2026-02-22 23:16:09 +01:00

50 lines
1.8 KiB
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';
describe('ESM: warn for obsolete hooks provided', { concurrency: !process.env.TEST_PARALLEL }, () => {
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(fixtures.fileURL('es-module-loaders', 'module-named-exports.mjs'))}`,
]);
assert.doesNotMatch(
stderr,
/ExperimentalWarning/,
new Error('No experimental warning(s) should be emitted when no experimental feature is enabled')
);
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
describe('experimental warnings for enabled experimental feature', () => {
for (
const [experiment, ...args] of [
[
/`--experimental-loader` may be removed in the future/,
'--experimental-loader',
fixtures.fileURL('es-module-loaders', 'hooks-custom.mjs'),
],
]
) {
it(`should print for ${experiment.toString().replaceAll('/', '')}`, async () => {
const { code, signal, stderr } = await spawnPromisified(execPath, [
...args,
'--input-type=module',
'--eval',
`import ${JSON.stringify(fixtures.fileURL('es-module-loaders', 'module-named-exports.mjs'))}`,
]);
assert.match(stderr, /ExperimentalWarning/);
assert.match(stderr, experiment);
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
}
});
});