1'use strict'; 2 3const common = require('../common'); 4const fixtures = require('../common/fixtures'); 5const { spawn } = require('child_process'); 6const assert = require('assert'); 7 8const entry = fixtures.path('/es-modules/cjs-exports.mjs'); 9 10let child = spawn(process.execPath, [entry]); 11child.stderr.setEncoding('utf8'); 12let stdout = ''; 13child.stdout.setEncoding('utf8'); 14child.stdout.on('data', (data) => { 15 stdout += data; 16}); 17child.on('close', common.mustCall((code, signal) => { 18 assert.strictEqual(code, 0); 19 assert.strictEqual(signal, null); 20 assert.strictEqual(stdout, 'ok\n'); 21})); 22 23const entryInvalid = fixtures.path('/es-modules/cjs-exports-invalid.mjs'); 24child = spawn(process.execPath, [entryInvalid]); 25let stderr = ''; 26child.stderr.setEncoding('utf8'); 27child.stderr.on('data', (data) => { 28 stderr += data; 29}); 30child.on('close', common.mustCall((code, signal) => { 31 assert.strictEqual(code, 1); 32 assert.strictEqual(signal, null); 33 assert.ok(stderr.includes('Warning: To load an ES module')); 34 assert.ok(stderr.includes('Unexpected token \'export\'')); 35})); 36