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
|
|
|
|
|
|
|
|
2024-03-23 21:11:28 +00:00
|
|
|
describe('ESM: importing CJS', { concurrency: !process.env.TEST_PARALLEL }, () => {
|
2022-07-29 08:42:55 +00:00
|
|
|
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
|
|
|
|
2024-07-20 18:30:46 +00:00
|
|
|
assert.match(stderr, /SyntaxError: The requested module '\.\/invalid-cjs\.js' does not provide an export named 'default'/);
|
2022-07-29 08:42:55 +00:00
|
|
|
assert.strictEqual(code, 1);
|
|
|
|
assert.strictEqual(signal, null);
|
|
|
|
});
|
2020-09-30 11:24:34 +00:00
|
|
|
});
|