|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const fixtures = require('../common/fixtures'); |
| 5 | +const { spawn } = require('child_process'); |
| 6 | +const assert = require('assert'); |
| 7 | + |
| 8 | +// In a "type": "module" package scope, files with no extensions should |
| 9 | +// not 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 | +].forEach((fixturePath) => { |
| 16 | + const entry = fixtures.path(fixturePath); |
| 17 | + const child = spawn(process.execPath, [entry]); |
| 18 | + let stdout = ''; |
| 19 | + let stderr = ''; |
| 20 | + child.stderr.setEncoding('utf8'); |
| 21 | + child.stdout.setEncoding('utf8'); |
| 22 | + child.stdout.on('data', (data) => { |
| 23 | + stdout += data; |
| 24 | + }); |
| 25 | + child.stderr.on('data', (data) => { |
| 26 | + stderr += data; |
| 27 | + }); |
| 28 | + child.on('close', common.mustCall((code, signal) => { |
| 29 | + assert.strictEqual(code, 0); |
| 30 | + assert.strictEqual(signal, null); |
| 31 | + assert.strictEqual(stdout, 'executed\n'); |
| 32 | + assert.ok(stderr.indexOf('ERR_UNKNOWN_FILE_EXTENSION') === -1); |
| 33 | + })); |
| 34 | +}); |
0 commit comments