|
| 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 | +{ |
| 9 | + const entry = fixtures.path( |
| 10 | + '/es-modules/package-type-module/extension.unknown' |
| 11 | + ); |
| 12 | + const child = spawn(process.execPath, [entry]); |
| 13 | + let stdout = ''; |
| 14 | + let stderr = ''; |
| 15 | + child.stderr.setEncoding('utf8'); |
| 16 | + child.stdout.setEncoding('utf8'); |
| 17 | + child.stdout.on('data', (data) => { |
| 18 | + stdout += data; |
| 19 | + }); |
| 20 | + child.stderr.on('data', (data) => { |
| 21 | + stderr += data; |
| 22 | + }); |
| 23 | + child.on('close', common.mustCall((code, signal) => { |
| 24 | + assert.strictEqual(code, 1); |
| 25 | + assert.strictEqual(signal, null); |
| 26 | + assert.strictEqual(stdout, ''); |
| 27 | + assert.ok(stderr.indexOf('ERR_UNKNOWN_FILE_EXTENSION') !== -1); |
| 28 | + })); |
| 29 | +} |
| 30 | +{ |
| 31 | + const entry = fixtures.path( |
| 32 | + '/es-modules/package-type-module/imports-unknownext.mjs' |
| 33 | + ); |
| 34 | + const child = spawn(process.execPath, [entry]); |
| 35 | + let stdout = ''; |
| 36 | + let stderr = ''; |
| 37 | + child.stderr.setEncoding('utf8'); |
| 38 | + child.stdout.setEncoding('utf8'); |
| 39 | + child.stdout.on('data', (data) => { |
| 40 | + stdout += data; |
| 41 | + }); |
| 42 | + child.stderr.on('data', (data) => { |
| 43 | + stderr += data; |
| 44 | + }); |
| 45 | + child.on('close', common.mustCall((code, signal) => { |
| 46 | + assert.strictEqual(code, 1); |
| 47 | + assert.strictEqual(signal, null); |
| 48 | + assert.strictEqual(stdout, ''); |
| 49 | + assert.ok(stderr.indexOf('ERR_UNKNOWN_FILE_EXTENSION') !== -1); |
| 50 | + })); |
| 51 | +} |
| 52 | +{ |
| 53 | + const entry = fixtures.path('/es-modules/package-type-module/noext-esm'); |
| 54 | + const child = spawn(process.execPath, [entry]); |
| 55 | + let stdout = ''; |
| 56 | + child.stdout.setEncoding('utf8'); |
| 57 | + child.stdout.on('data', (data) => { |
| 58 | + stdout += data; |
| 59 | + }); |
| 60 | + child.on('close', common.mustCall((code, signal) => { |
| 61 | + assert.strictEqual(code, 0); |
| 62 | + assert.strictEqual(signal, null); |
| 63 | + assert.strictEqual(stdout, 'executed\n'); |
| 64 | + })); |
| 65 | +} |
| 66 | +{ |
| 67 | + const entry = fixtures.path( |
| 68 | + '/es-modules/package-type-module/imports-noext.mjs' |
| 69 | + ); |
| 70 | + const child = spawn(process.execPath, [entry]); |
| 71 | + let stdout = ''; |
| 72 | + child.stdout.setEncoding('utf8'); |
| 73 | + child.stdout.on('data', (data) => { |
| 74 | + stdout += data; |
| 75 | + }); |
| 76 | + child.on('close', common.mustCall((code, signal) => { |
| 77 | + assert.strictEqual(code, 0); |
| 78 | + assert.strictEqual(signal, null); |
| 79 | + assert.strictEqual(stdout, 'executed\n'); |
| 80 | + })); |
| 81 | +} |
0 commit comments