1import { spawnPromisified } from '../common/index.mjs'; 2import { spawn } from 'node:child_process'; 3import { describe, it } from 'node:test'; 4import { strictEqual, match } from 'node:assert'; 5 6describe('the type flag should change the interpretation of string input', { concurrency: true }, () => { 7 it('should run as ESM input passed via --eval', async () => { 8 const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [ 9 '--experimental-default-type=module', 10 '--eval', 11 'import "data:text/javascript,console.log(42)"', 12 ]); 13 14 strictEqual(stderr, ''); 15 strictEqual(stdout, '42\n'); 16 strictEqual(code, 0); 17 strictEqual(signal, null); 18 }); 19 20 // ESM is unsupported for --print via --input-type=module 21 22 it('should run as ESM input passed via STDIN', async () => { 23 const child = spawn(process.execPath, [ 24 '--experimental-default-type=module', 25 ]); 26 child.stdin.end('console.log(typeof import.meta.resolve)'); 27 28 match((await child.stdout.toArray()).toString(), /^function\r?\n$/); 29 }); 30 31 it('should be overridden by --input-type', async () => { 32 const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [ 33 '--experimental-default-type=module', 34 '--input-type=commonjs', 35 '--eval', 36 'console.log(require("process").version)', 37 ]); 38 39 strictEqual(stderr, ''); 40 strictEqual(stdout, `${process.version}\n`); 41 strictEqual(code, 0); 42 strictEqual(signal, null); 43 }); 44}); 45