1'use strict'; 2 3const common = require('../common'); 4const fixtures = require('../common/fixtures'); 5const { spawn } = require('child_process'); 6const assert = require('assert'); 7 8// In a "type": "module" package scope, files with unknown extensions or no 9// extensions should throw; both when used as a main entry point and also when 10// referenced via `import`. 11 12[ 13 '/es-modules/package-type-module/noext-esm', 14 '/es-modules/package-type-module/imports-noext.mjs', 15 '/es-modules/package-type-module/extension.unknown', 16 '/es-modules/package-type-module/imports-unknownext.mjs', 17].forEach((fixturePath) => { 18 const entry = fixtures.path(fixturePath); 19 const child = spawn(process.execPath, [entry]); 20 let stdout = ''; 21 let stderr = ''; 22 child.stderr.setEncoding('utf8'); 23 child.stdout.setEncoding('utf8'); 24 child.stdout.on('data', (data) => { 25 stdout += data; 26 }); 27 child.stderr.on('data', (data) => { 28 stderr += data; 29 }); 30 child.on('close', common.mustCall((code, signal) => { 31 assert.strictEqual(code, 1); 32 assert.strictEqual(signal, null); 33 assert.strictEqual(stdout, ''); 34 assert.ok(stderr.indexOf('ERR_UNKNOWN_FILE_EXTENSION') !== -1); 35 })); 36}); 37