mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 15:30:56 +01:00
baa3621bb1
This ensures files with unknown extensions like foo.bar are not loaded as CJS/ESM when imported as a main entry point and makes sure that those files would maintain the same format even if loaded after the main entrypoint. PR-URL: https://github.com/nodejs/node/pull/31021 Reviewed-By: Guy Bedford <guybedford@gmail.com>
82 lines
2.2 KiB
JavaScript
82 lines
2.2 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const fixtures = require('../common/fixtures');
|
|
const { spawn } = require('child_process');
|
|
const assert = require('assert');
|
|
|
|
{
|
|
const entry = fixtures.path(
|
|
'/es-modules/package-type-module/extension.unknown'
|
|
);
|
|
const child = spawn(process.execPath, [entry]);
|
|
let stdout = '';
|
|
let stderr = '';
|
|
child.stderr.setEncoding('utf8');
|
|
child.stdout.setEncoding('utf8');
|
|
child.stdout.on('data', (data) => {
|
|
stdout += data;
|
|
});
|
|
child.stderr.on('data', (data) => {
|
|
stderr += data;
|
|
});
|
|
child.on('close', common.mustCall((code, signal) => {
|
|
assert.strictEqual(code, 1);
|
|
assert.strictEqual(signal, null);
|
|
assert.strictEqual(stdout, '');
|
|
assert.ok(stderr.indexOf('ERR_UNKNOWN_FILE_EXTENSION') !== -1);
|
|
}));
|
|
}
|
|
{
|
|
const entry = fixtures.path(
|
|
'/es-modules/package-type-module/imports-unknownext.mjs'
|
|
);
|
|
const child = spawn(process.execPath, [entry]);
|
|
let stdout = '';
|
|
let stderr = '';
|
|
child.stderr.setEncoding('utf8');
|
|
child.stdout.setEncoding('utf8');
|
|
child.stdout.on('data', (data) => {
|
|
stdout += data;
|
|
});
|
|
child.stderr.on('data', (data) => {
|
|
stderr += data;
|
|
});
|
|
child.on('close', common.mustCall((code, signal) => {
|
|
assert.strictEqual(code, 1);
|
|
assert.strictEqual(signal, null);
|
|
assert.strictEqual(stdout, '');
|
|
assert.ok(stderr.indexOf('ERR_UNKNOWN_FILE_EXTENSION') !== -1);
|
|
}));
|
|
}
|
|
{
|
|
const entry = fixtures.path('/es-modules/package-type-module/noext-esm');
|
|
const child = spawn(process.execPath, [entry]);
|
|
let stdout = '';
|
|
child.stdout.setEncoding('utf8');
|
|
child.stdout.on('data', (data) => {
|
|
stdout += data;
|
|
});
|
|
child.on('close', common.mustCall((code, signal) => {
|
|
assert.strictEqual(code, 0);
|
|
assert.strictEqual(signal, null);
|
|
assert.strictEqual(stdout, 'executed\n');
|
|
}));
|
|
}
|
|
{
|
|
const entry = fixtures.path(
|
|
'/es-modules/package-type-module/imports-noext.mjs'
|
|
);
|
|
const child = spawn(process.execPath, [entry]);
|
|
let stdout = '';
|
|
child.stdout.setEncoding('utf8');
|
|
child.stdout.on('data', (data) => {
|
|
stdout += data;
|
|
});
|
|
child.on('close', common.mustCall((code, signal) => {
|
|
assert.strictEqual(code, 0);
|
|
assert.strictEqual(signal, null);
|
|
assert.strictEqual(stdout, 'executed\n');
|
|
}));
|
|
}
|