Files
node/test/es-module/test-require-module-feature-detect.js
T
Joyee Cheung e95163b170 process: add process.features.require_module
For detecting whether `require(esm)` is supported without triggering
the experimental warning.

PR-URL: https://github.com/nodejs/node/pull/55241
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2024-10-11 23:58:11 +02:00

39 lines
869 B
JavaScript

'use strict';
// This tests that process.features.require_module can be used to feature-detect
// require(esm) without triggering a warning.
require('../common');
const { spawnSyncAndAssert } = require('../common/child_process');
spawnSyncAndAssert(process.execPath, [
'--no-warnings',
'--experimental-require-module',
'-p',
'process.features.require_module',
], {
trim: true,
stdout: 'true',
stderr: '', // Should not emit warnings.
});
// It is not enabled by default.
spawnSyncAndAssert(process.execPath, [
'-p',
'process.features.require_module',
], {
trim: true,
stdout: 'false',
stderr: '', // Should not emit warnings.
});
spawnSyncAndAssert(process.execPath, [
'--no-experimental-require-module',
'-p',
'process.features.require_module',
], {
trim: true,
stdout: 'false',
stderr: '', // Should not emit warnings.
});