mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
PR-URL: https://github.com/nodejs/node/pull/49869 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
import { spawnPromisified } from '../common/index.mjs';
|
|
import { spawn } from 'node:child_process';
|
|
import { describe, it } from 'node:test';
|
|
import { strictEqual, match } from 'node:assert';
|
|
|
|
describe('the type flag should change the interpretation of string input', { concurrency: true }, () => {
|
|
it('should run as ESM input passed via --eval', async () => {
|
|
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
|
|
'--experimental-default-type=module',
|
|
'--eval',
|
|
'import "data:text/javascript,console.log(42)"',
|
|
]);
|
|
|
|
strictEqual(stderr, '');
|
|
strictEqual(stdout, '42\n');
|
|
strictEqual(code, 0);
|
|
strictEqual(signal, null);
|
|
});
|
|
|
|
// ESM is unsupported for --print via --input-type=module
|
|
|
|
it('should run as ESM input passed via STDIN', async () => {
|
|
const child = spawn(process.execPath, [
|
|
'--experimental-default-type=module',
|
|
]);
|
|
child.stdin.end('console.log(typeof import.meta.resolve)');
|
|
|
|
match((await child.stdout.toArray()).toString(), /^function\r?\n$/);
|
|
});
|
|
|
|
it('should be overridden by --input-type', async () => {
|
|
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
|
|
'--experimental-default-type=module',
|
|
'--input-type=commonjs',
|
|
'--eval',
|
|
'console.log(require("process").version)',
|
|
]);
|
|
|
|
strictEqual(stderr, '');
|
|
strictEqual(stdout, `${process.version}\n`);
|
|
strictEqual(code, 0);
|
|
strictEqual(signal, null);
|
|
});
|
|
});
|