2020-05-15 05:40:37 +00:00
|
|
|
'use strict';
|
|
|
|
|
2022-07-29 08:42:55 +00:00
|
|
|
const { spawnPromisified } = require('../common');
|
|
|
|
const fixtures = require('../common/fixtures.js');
|
|
|
|
const assert = require('node:assert');
|
|
|
|
const { execPath } = require('node:process');
|
|
|
|
const { describe, it } = require('node:test');
|
2020-05-15 05:40:37 +00:00
|
|
|
|
|
|
|
|
2022-07-29 08:42:55 +00:00
|
|
|
describe('ESM: importing CJS', { concurrency: true }, () => {
|
|
|
|
it('should support valid CJS exports', async () => {
|
|
|
|
const validEntry = fixtures.path('/es-modules/cjs-exports.mjs');
|
|
|
|
const { code, signal, stdout } = await spawnPromisified(execPath, [validEntry]);
|
|
|
|
|
|
|
|
assert.strictEqual(code, 0);
|
|
|
|
assert.strictEqual(signal, null);
|
|
|
|
assert.strictEqual(stdout, 'ok\n');
|
|
|
|
});
|
|
|
|
|
2022-08-03 21:48:09 +00:00
|
|
|
it('should error on invalid CJS exports', async () => {
|
2022-07-29 08:42:55 +00:00
|
|
|
const invalidEntry = fixtures.path('/es-modules/cjs-exports-invalid.mjs');
|
|
|
|
const { code, signal, stderr } = await spawnPromisified(execPath, [invalidEntry]);
|
2020-09-30 11:24:34 +00:00
|
|
|
|
2022-07-29 08:42:55 +00:00
|
|
|
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\''));
|
|
|
|
});
|
2020-09-30 11:24:34 +00:00
|
|
|
});
|