11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst { spawnPromisified } = require('../common');
41cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures.js');
51cb0ef41Sopenharmony_ciconst assert = require('node:assert');
61cb0ef41Sopenharmony_ciconst { execPath } = require('node:process');
71cb0ef41Sopenharmony_ciconst { describe, it } = require('node:test');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cidescribe('ESM: importing CJS', { concurrency: true }, () => {
111cb0ef41Sopenharmony_ci  it('should support valid CJS exports', async () => {
121cb0ef41Sopenharmony_ci    const validEntry = fixtures.path('/es-modules/cjs-exports.mjs');
131cb0ef41Sopenharmony_ci    const { code, signal, stdout } = await spawnPromisified(execPath, [validEntry]);
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci    assert.strictEqual(code, 0);
161cb0ef41Sopenharmony_ci    assert.strictEqual(signal, null);
171cb0ef41Sopenharmony_ci    assert.strictEqual(stdout, 'ok\n');
181cb0ef41Sopenharmony_ci  });
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci  it('should error on invalid CJS exports', async () => {
211cb0ef41Sopenharmony_ci    const invalidEntry = fixtures.path('/es-modules/cjs-exports-invalid.mjs');
221cb0ef41Sopenharmony_ci    const { code, signal, stderr } = await spawnPromisified(execPath, [invalidEntry]);
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci    assert.strictEqual(code, 1);
251cb0ef41Sopenharmony_ci    assert.strictEqual(signal, null);
261cb0ef41Sopenharmony_ci    assert.ok(stderr.includes('Warning: To load an ES module'));
271cb0ef41Sopenharmony_ci    assert.ok(stderr.includes('Unexpected token \'export\''));
281cb0ef41Sopenharmony_ci  });
291cb0ef41Sopenharmony_ci});
30