• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const { spawnPromisified } = require('../common');
4const fixtures = require('../common/fixtures.js');
5const assert = require('node:assert');
6const { execPath } = require('node:process');
7const { describe, it } = require('node:test');
8
9
10describe('ESM: importing CJS', { concurrency: true }, () => {
11  it('should support valid CJS exports', async () => {
12    const validEntry = fixtures.path('/es-modules/cjs-exports.mjs');
13    const { code, signal, stdout } = await spawnPromisified(execPath, [validEntry]);
14
15    assert.strictEqual(code, 0);
16    assert.strictEqual(signal, null);
17    assert.strictEqual(stdout, 'ok\n');
18  });
19
20  it('should error on invalid CJS exports', async () => {
21    const invalidEntry = fixtures.path('/es-modules/cjs-exports-invalid.mjs');
22    const { code, signal, stderr } = await spawnPromisified(execPath, [invalidEntry]);
23
24    assert.strictEqual(code, 1);
25    assert.strictEqual(signal, null);
26    assert.ok(stderr.includes('Warning: To load an ES module'));
27    assert.ok(stderr.includes('Unexpected token \'export\''));
28  });
29});
30