script.js
This file
Path
test/methods/script.js
60 lines · 2.2 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061import assert from 'node:assert/strict';import test from 'node:test';import {isStream} from 'is-stream';import {$} from '../../index.js';import {setFixtureDirectory} from '../helpers/fixtures-directory.js';import {foobarString} from '../helpers/input.js';
setFixtureDirectory();
const testScriptStdoutSync = (getSubprocess, expectedStdout) => { const {stdout} = getSubprocess(); assert.equal(stdout, expectedStdout);};
test('$.sync`...`', () => testScriptStdoutSync(() => $.sync`echo.js foo bar`, 'foo\nbar'));test('$.s`...`', () => testScriptStdoutSync(() => $.s`echo.js foo bar`, 'foo\nbar'));test('$(options).sync`...`', () => testScriptStdoutSync(() => $({stripFinalNewline: false}).sync`echo.js ${foobarString}`, `${foobarString}\n`));test('$.sync(options)`...`', () => testScriptStdoutSync(() => $.sync({stripFinalNewline: false})`echo.js ${foobarString}`, `${foobarString}\n`));
test('Cannot call $.sync.sync', () => { assert.equal('sync' in $.sync, false);});
test('Cannot call $.sync(options).sync', () => { assert.equal('sync' in $.sync({}), false);});
test('$(options)() stdin defaults to "inherit"', async () => { const {stdout} = await $({input: foobarString})('stdin-script.js'); assert.equal(stdout, foobarString);});
test('$.sync(options)() stdin defaults to "inherit"', () => { const {stdout} = $.sync({input: foobarString})('stdin-script.js'); assert.equal(stdout, foobarString);});
test('$(options).sync() stdin defaults to "inherit"', () => { const {stdout} = $({input: foobarString}).sync('stdin-script.js'); assert.equal(stdout, foobarString);});
test('$(options)`...` stdin defaults to "inherit"', async () => { const {stdout} = await $({input: foobarString})`stdin-script.js`; assert.equal(stdout, foobarString);});
test('$.sync(options)`...` stdin defaults to "inherit"', () => { const {stdout} = $.sync({input: foobarString})`stdin-script.js`; assert.equal(stdout, foobarString);});
test('$(options).sync`...` stdin defaults to "inherit"', () => { const {stdout} = $({input: foobarString}).sync`stdin-script.js`; assert.equal(stdout, foobarString);});
test('$ stdin has no default value when stdio is set', () => { assert.ok(isStream($({stdio: 'pipe'})`noop.js`.stdin));});