2020-05-15 05:40:37 +00:00
|
|
|
'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/cjs-exports.mjs');
|
|
|
|
|
2020-09-30 11:24:34 +00:00
|
|
|
let child = spawn(process.execPath, [entry]);
|
2020-05-15 05:40:37 +00:00
|
|
|
child.stderr.setEncoding('utf8');
|
|
|
|
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, 'ok\n');
|
|
|
|
}));
|
2020-09-30 11:24:34 +00:00
|
|
|
|
|
|
|
const entryInvalid = fixtures.path('/es-modules/cjs-exports-invalid.mjs');
|
|
|
|
child = spawn(process.execPath, [entryInvalid]);
|
|
|
|
let stderr = '';
|
|
|
|
child.stderr.setEncoding('utf8');
|
|
|
|
child.stderr.on('data', (data) => {
|
|
|
|
stderr += data;
|
|
|
|
});
|
|
|
|
child.on('close', common.mustCall((code, signal) => {
|
|
|
|
assert.strictEqual(code, 1);
|
|
|
|
assert.strictEqual(signal, null);
|
|
|
|
assert.ok(stderr.includes('Warning: To load an ES module'));
|
|
|
|
assert.ok(stderr.includes('Unexpected token \'export\''));
|
|
|
|
}));
|