script.js
This file
Path
test/script.js
458 lines · 30.2 KiB · JavaScript
Last changed by
Allow newlines in `$` (#843)ehmickybefore adoption1315486
History of this fileTake it
`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562
line 1why, one step back1import {spawn} from 'node:child_process';Split files (#791)ehmickybefore adoption932fb26
lines 2–5why, one step back2import test from 'ava';3import {isStream} from 'is-stream';4import {$} from '../index.js';5import {setFixtureDir} from './helpers/fixtures-dir.js';`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562
line 6why, one step back6import {foobarString} from './helpers/input.js';Split files (#791)ehmickybefore adoption932fb26
lines 7–9why, one step back78setFixtureDir();9Allow newlines in `$` (#843)ehmickybefore adoption1315486
lines 10–15why, one step back10// Workaround since some text editors or IDEs do not allow inputting \r directly11const escapedCall = string => {12 const templates = [string];13 templates.raw = [string];14 return $(templates);15};Split files (#791)ehmickybefore adoption932fb26
line 16why, one step back16Allow newlines in `$` (#843)ehmickybefore adoption1315486
lines 17–20why, one step back17const testScriptStdout = async (t, getChildProcess, expectedStdout) => {18 const {stdout} = await getChildProcess();19 t.is(stdout, expectedStdout);20};Split files (#791)ehmickybefore adoption932fb26
line 21why, one step back21Allow newlines in `$` (#843)ehmickybefore adoption1315486
lines 22–241why, one step back22test('$ executes command', testScriptStdout, () => $`echo.js foo bar`, 'foo\nbar');23test('$ accepts options', testScriptStdout, () => $({stripFinalNewline: true})`noop.js foo`, 'foo');24test('$ allows number interpolation', testScriptStdout, () => $`echo.js 1 ${2}`, '1\n2');25test('$ can concatenate multiple tokens', testScriptStdout, () => $`echo.js ${'foo'}bar${'foo'}`, 'foobarfoo');26test('$ can use newlines and tab indentations', testScriptStdout, () => $`echo.js foo27 bar`, 'foo\nbar');28test('$ can use newlines and space indentations', testScriptStdout, () => $`echo.js foo29 bar`, 'foo\nbar');30test('$ can use Windows newlines and tab indentations', testScriptStdout, () => escapedCall('echo.js foo\r\n\tbar'), 'foo\nbar');31test('$ can use Windows newlines and space indentations', testScriptStdout, () => escapedCall('echo.js foo\r\n bar'), 'foo\nbar');32test('$ does not ignore comments in expressions', testScriptStdout, () => $`echo.js foo33 ${/* This is a comment */''}34 bar35 ${/* This is another comment */''}36 baz37`, 'foo\n\nbar\n\nbaz');38test('$ allows escaping spaces with interpolation', testScriptStdout, () => $`echo.js ${'foo bar'}`, 'foo bar');39test('$ allows escaping spaces in commands with interpolation', testScriptStdout, () => $`${'command with space.js'} foo bar`, 'foo\nbar');40test('$ trims', testScriptStdout, () => $` echo.js foo bar `, 'foo\nbar');41test('$ allows array interpolation', testScriptStdout, () => $`echo.js ${['foo', 'bar']}`, 'foo\nbar');42test('$ allows empty array interpolation', testScriptStdout, () => $`echo.js foo ${[]} bar`, 'foo\nbar');43test('$ allows space escaped values in array interpolation', testScriptStdout, () => $`echo.js ${['foo', 'bar baz']}`, 'foo\nbar baz');44test('$ can concatenate at the end of tokens followed by an array', testScriptStdout, () => $`echo.js foo${['bar', 'foo']}`, 'foobar\nfoo');45test('$ can concatenate at the start of tokens followed by an array', testScriptStdout, () => $`echo.js ${['foo', 'bar']}foo`, 'foo\nbarfoo');46test('$ can concatenate at the start and end of tokens followed by an array', testScriptStdout, () => $`echo.js foo${['bar', 'foo']}bar`, 'foobar\nfoobar');47test('$ handles escaped newlines', testScriptStdout, () => $`echo.js a\48b`, 'ab');49test('$ handles backslashes at end of lines', testScriptStdout, () => $`echo.js a\\50 b`, 'a\\\nb');51test('$ handles double backslashes at end of lines', testScriptStdout, () => $`echo.js a\\\\52 b`, 'a\\\\\nb');53test('$ handles tokens - a', testScriptStdout, () => $`echo.js a`, 'a');54test('$ handles expressions - a', testScriptStdout, () => $`echo.js ${'a'}`, 'a');55test('$ handles tokens - abc', testScriptStdout, () => $`echo.js abc`, 'abc');56test('$ handles expressions - abc', testScriptStdout, () => $`echo.js ${'abc'}`, 'abc');57test('$ handles tokens - ""', testScriptStdout, () => $`echo.js`, '');58test('$ handles expressions - ""', testScriptStdout, () => $`echo.js a ${''} b`, 'a\n\nb');59test('$ splits tokens - ""', testScriptStdout, () => $`echo.js ab`, 'ab');60test('$ splits expressions - ""', testScriptStdout, () => $`echo.js ${'a'}${'b'}`, 'ab');61test('$ concatenates expressions - ""', testScriptStdout, () => $`echo.js a${'b'}c`, 'abc');62test('$ handles tokens - " "', testScriptStdout, () => $`echo.js `, '');63test('$ handles expressions - " "', testScriptStdout, () => $`echo.js ${' '}`, ' ');64test('$ splits tokens - " "', testScriptStdout, () => $`echo.js a b`, 'a\nb');65test('$ splits expressions - " "', testScriptStdout, () => $`echo.js ${'a'} ${'b'}`, 'a\nb');66test('$ concatenates tokens - " "', testScriptStdout, () => $`echo.js a `, 'a');67test('$ concatenates expressions - " "', testScriptStdout, () => $`echo.js ${'a'} `, 'a');68test('$ handles tokens - " " (2 spaces)', testScriptStdout, () => $`echo.js `, '');69test('$ handles expressions - " " (2 spaces)', testScriptStdout, () => $`echo.js ${' '}`, ' ');70test('$ splits tokens - " " (2 spaces)', testScriptStdout, () => $`echo.js a b`, 'a\nb');71test('$ splits expressions - " " (2 spaces)', testScriptStdout, () => $`echo.js ${'a'} ${'b'}`, 'a\nb');72test('$ concatenates tokens - " " (2 spaces)', testScriptStdout, () => $`echo.js a `, 'a');73test('$ concatenates expressions - " " (2 spaces)', testScriptStdout, () => $`echo.js ${'a'} `, 'a');74test('$ handles tokens - " " (3 spaces)', testScriptStdout, () => $`echo.js `, '');75test('$ handles expressions - " " (3 spaces)', testScriptStdout, () => $`echo.js ${' '}`, ' ');76test('$ splits tokens - " " (3 spaces)', testScriptStdout, () => $`echo.js a b`, 'a\nb');77test('$ splits expressions - " " (3 spaces)', testScriptStdout, () => $`echo.js ${'a'} ${'b'}`, 'a\nb');78test('$ concatenates tokens - " " (3 spaces)', testScriptStdout, () => $`echo.js a `, 'a');79test('$ concatenates expressions - " " (3 spaces)', testScriptStdout, () => $`echo.js ${'a'} `, 'a');80test('$ handles tokens - \\t (no escape)', testScriptStdout, () => $`echo.js `, '');81test('$ handles expressions - \\t (no escape)', testScriptStdout, () => $`echo.js ${' '}`, '\t');82test('$ splits tokens - \\t (no escape)', testScriptStdout, () => $`echo.js a b`, 'a\nb');83test('$ splits expressions - \\t (no escape)', testScriptStdout, () => $`echo.js ${'a'} ${'b'}`, 'a\nb');84test('$ concatenates tokens - \\t (no escape)', testScriptStdout, () => $`echo.js a b`, 'a\nb');85test('$ concatenates expressions - \\t (no escape)', testScriptStdout, () => $`echo.js ${'a'} b`, 'a\nb');86test('$ handles tokens - \\t (escape)', testScriptStdout, () => $`echo.js \t`, '\t');87test('$ handles expressions - \\t (escape)', testScriptStdout, () => $`echo.js ${'\t'}`, '\t');88test('$ splits tokens - \\t (escape)', testScriptStdout, () => $`echo.js a\tb`, 'a\tb');89test('$ splits expressions - \\t (escape)', testScriptStdout, () => $`echo.js ${'a'}\t${'b'}`, 'a\tb');90test('$ concatenates tokens - \\t (escape)', testScriptStdout, () => $`echo.js \ta\t b`, '\ta\t\nb');91test('$ concatenates expressions - \\t (escape)', testScriptStdout, () => $`echo.js \t${'a'}\t b`, '\ta\t\nb');92test('$ handles tokens - \\n (no escape)', testScriptStdout, () => $`echo.js93 `, '');94test('$ handles expressions - \\n (no escape)', testScriptStdout, () => $`echo.js ${`95`} `, '\n');96test('$ splits tokens - \\n (no escape)', testScriptStdout, () => $`echo.js a97 b`, 'a\nb');98test('$ splits expressions - \\n (no escape)', testScriptStdout, () => $`echo.js ${'a'}99 ${'b'}`, 'a\nb');100test('$ concatenates tokens - \\n (no escape)', testScriptStdout, () => $`echo.js101a102 b`, 'a\nb');103test('$ concatenates expressions - \\n (no escape)', testScriptStdout, () => $`echo.js104${'a'}105 b`, 'a\nb');106test('$ handles tokens - \\n (escape)', testScriptStdout, () => $`echo.js \n `, '\n');107test('$ handles expressions - \\n (escape)', testScriptStdout, () => $`echo.js ${'\n'} `, '\n');108test('$ splits tokens - \\n (escape)', testScriptStdout, () => $`echo.js a\n b`, 'a\n\nb');109test('$ splits expressions - \\n (escape)', testScriptStdout, () => $`echo.js ${'a'}\n ${'b'}`, 'a\n\nb');110test('$ concatenates tokens - \\n (escape)', testScriptStdout, () => $`echo.js \na\n b`, '\na\n\nb');111test('$ concatenates expressions - \\n (escape)', testScriptStdout, () => $`echo.js \n${'a'}\n b`, '\na\n\nb');112test('$ handles tokens - \\r (no escape)', testScriptStdout, () => escapedCall('echo.js \r '), '');113test('$ splits tokens - \\r (no escape)', testScriptStdout, () => escapedCall('echo.js a\rb'), 'a\nb');114test('$ splits expressions - \\r (no escape)', testScriptStdout, () => escapedCall(`echo.js ${'a'}\r${'b'}`), 'a\nb');115test('$ concatenates tokens - \\r (no escape)', testScriptStdout, () => escapedCall('echo.js \ra\r b'), 'a\nb');116test('$ concatenates expressions - \\r (no escape)', testScriptStdout, () => escapedCall(`echo.js \r${'a'}\r b`), 'a\nb');117test('$ splits tokens - \\r (escape)', testScriptStdout, () => $`echo.js a\r b`, 'a\r\nb');118test('$ splits expressions - \\r (escape)', testScriptStdout, () => $`echo.js ${'a'}\r ${'b'}`, 'a\r\nb');119test('$ concatenates tokens - \\r (escape)', testScriptStdout, () => $`echo.js \ra\r b`, '\ra\r\nb');120test('$ concatenates expressions - \\r (escape)', testScriptStdout, () => $`echo.js \r${'a'}\r b`, '\ra\r\nb');121test('$ handles tokens - \\r\\n (no escape)', testScriptStdout, () => escapedCall('echo.js \r\n '), '');122test('$ splits tokens - \\r\\n (no escape)', testScriptStdout, () => escapedCall('echo.js a\r\nb'), 'a\nb');123test('$ splits expressions - \\r\\n (no escape)', testScriptStdout, () => escapedCall(`echo.js ${'a'}\r\n${'b'}`), 'a\nb');124test('$ concatenates tokens - \\r\\n (no escape)', testScriptStdout, () => escapedCall('echo.js \r\na\r\n b'), 'a\nb');125test('$ concatenates expressions - \\r\\n (no escape)', testScriptStdout, () => escapedCall(`echo.js \r\n${'a'}\r\n b`), 'a\nb');126test('$ handles tokens - \\r\\n (escape)', testScriptStdout, () => $`echo.js \r\n `, '\r\n');127test('$ handles expressions - \\r\\n (escape)', testScriptStdout, () => $`echo.js ${'\r\n'} `, '\r\n');128test('$ splits tokens - \\r\\n (escape)', testScriptStdout, () => $`echo.js a\r\n b`, 'a\r\n\nb');129test('$ splits expressions - \\r\\n (escape)', testScriptStdout, () => $`echo.js ${'a'}\r\n ${'b'}`, 'a\r\n\nb');130test('$ concatenates tokens - \\r\\n (escape)', testScriptStdout, () => $`echo.js \r\na\r\n b`, '\r\na\r\n\nb');131test('$ concatenates expressions - \\r\\n (escape)', testScriptStdout, () => $`echo.js \r\n${'a'}\r\n b`, '\r\na\r\n\nb');132/* eslint-disable no-irregular-whitespace */133test('$ handles expressions - \\f (no escape)', testScriptStdout, () => $`echo.js ${''}`, '\f');134test('$ splits tokens - \\f (no escape)', testScriptStdout, () => $`echo.js ab`, 'a\fb');135test('$ splits expressions - \\f (no escape)', testScriptStdout, () => $`echo.js ${'a'}${'b'}`, 'a\fb');136test('$ concatenates tokens - \\f (no escape)', testScriptStdout, () => $`echo.js a b`, '\fa\f\nb');137test('$ concatenates expressions - \\f (no escape)', testScriptStdout, () => $`echo.js ${'a'} b`, '\fa\f\nb');138/* eslint-enable no-irregular-whitespace */139test('$ handles tokens - \\f (escape)', testScriptStdout, () => $`echo.js \f`, '\f');140test('$ handles expressions - \\f (escape)', testScriptStdout, () => $`echo.js ${'\f'}`, '\f');141test('$ splits tokens - \\f (escape)', testScriptStdout, () => $`echo.js a\fb`, 'a\fb');142test('$ splits expressions - \\f (escape)', testScriptStdout, () => $`echo.js ${'a'}\f${'b'}`, 'a\fb');143test('$ concatenates tokens - \\f (escape)', testScriptStdout, () => $`echo.js \fa\f b`, '\fa\f\nb');144test('$ concatenates expressions - \\f (escape)', testScriptStdout, () => $`echo.js \f${'a'}\f b`, '\fa\f\nb');145test('$ handles tokens - \\', testScriptStdout, () => $`echo.js \\`, '\\');146test('$ handles expressions - \\', testScriptStdout, () => $`echo.js ${'\\'}`, '\\');147test('$ splits tokens - \\', testScriptStdout, () => $`echo.js a\\b`, 'a\\b');148test('$ splits expressions - \\', testScriptStdout, () => $`echo.js ${'a'}\\${'b'}`, 'a\\b');149test('$ concatenates tokens - \\', testScriptStdout, () => $`echo.js \\a\\ b`, '\\a\\\nb');150test('$ concatenates expressions - \\', testScriptStdout, () => $`echo.js \\${'a'}\\ b`, '\\a\\\nb');151test('$ handles tokens - \\\\', testScriptStdout, () => $`echo.js \\\\`, '\\\\');152test('$ handles expressions - \\\\', testScriptStdout, () => $`echo.js ${'\\\\'}`, '\\\\');153test('$ splits tokens - \\\\', testScriptStdout, () => $`echo.js a\\\\b`, 'a\\\\b');154test('$ splits expressions - \\\\', testScriptStdout, () => $`echo.js ${'a'}\\\\${'b'}`, 'a\\\\b');155test('$ concatenates tokens - \\\\', testScriptStdout, () => $`echo.js \\\\a\\\\ b`, '\\\\a\\\\\nb');156test('$ concatenates expressions - \\\\', testScriptStdout, () => $`echo.js \\\\${'a'}\\\\ b`, '\\\\a\\\\\nb');157test('$ handles tokens - `', testScriptStdout, () => $`echo.js \``, '`');158test('$ handles expressions - `', testScriptStdout, () => $`echo.js ${'`'}`, '`');159test('$ splits tokens - `', testScriptStdout, () => $`echo.js a\`b`, 'a`b');160test('$ splits expressions - `', testScriptStdout, () => $`echo.js ${'a'}\`${'b'}`, 'a`b');161test('$ concatenates tokens - `', testScriptStdout, () => $`echo.js \`a\` b`, '`a`\nb');162test('$ concatenates expressions - `', testScriptStdout, () => $`echo.js \`${'a'}\` b`, '`a`\nb');163test('$ handles tokens - \\v', testScriptStdout, () => $`echo.js \v`, '\v');164test('$ handles expressions - \\v', testScriptStdout, () => $`echo.js ${'\v'}`, '\v');165test('$ splits tokens - \\v', testScriptStdout, () => $`echo.js a\vb`, 'a\vb');166test('$ splits expressions - \\v', testScriptStdout, () => $`echo.js ${'a'}\v${'b'}`, 'a\vb');167test('$ concatenates tokens - \\v', testScriptStdout, () => $`echo.js \va\v b`, '\va\v\nb');168test('$ concatenates expressions - \\v', testScriptStdout, () => $`echo.js \v${'a'}\v b`, '\va\v\nb');169test('$ handles tokens - \\u2028', testScriptStdout, () => $`echo.js \u2028`, '\u2028');170test('$ handles expressions - \\u2028', testScriptStdout, () => $`echo.js ${'\u2028'}`, '\u2028');171test('$ splits tokens - \\u2028', testScriptStdout, () => $`echo.js a\u2028b`, 'a\u2028b');172test('$ splits expressions - \\u2028', testScriptStdout, () => $`echo.js ${'a'}\u2028${'b'}`, 'a\u2028b');173test('$ concatenates tokens - \\u2028', testScriptStdout, () => $`echo.js \u2028a\u2028 b`, '\u2028a\u2028\nb');174test('$ concatenates expressions - \\u2028', testScriptStdout, () => $`echo.js \u2028${'a'}\u2028 b`, '\u2028a\u2028\nb');175test('$ handles tokens - \\a', testScriptStdout, () => $`echo.js \a`, 'a');176test('$ splits tokens - \\a', testScriptStdout, () => $`echo.js a\ab`, 'aab');177test('$ splits expressions - \\a', testScriptStdout, () => $`echo.js ${'a'}\a${'b'}`, 'aab');178test('$ concatenates tokens - \\a', testScriptStdout, () => $`echo.js \aa\a b`, 'aaa\nb');179test('$ concatenates expressions - \\a', testScriptStdout, () => $`echo.js \a${'a'}\a b`, 'aaa\nb');180test('$ handles tokens - \\cJ', testScriptStdout, () => $`echo.js \cJ`, 'cJ');181test('$ splits tokens - \\cJ', testScriptStdout, () => $`echo.js a\cJb`, 'acJb');182test('$ splits expressions - \\cJ', testScriptStdout, () => $`echo.js ${'a'}\cJ${'b'}`, 'acJb');183test('$ concatenates tokens - \\cJ', testScriptStdout, () => $`echo.js \cJa\cJ b`, 'cJacJ\nb');184test('$ concatenates expressions - \\cJ', testScriptStdout, () => $`echo.js \cJ${'a'}\cJ b`, 'cJacJ\nb');185test('$ handles tokens - \\.', testScriptStdout, () => $`echo.js \.`, '.');186test('$ splits tokens - \\.', testScriptStdout, () => $`echo.js a\.b`, 'a.b');187test('$ splits expressions - \\.', testScriptStdout, () => $`echo.js ${'a'}\.${'b'}`, 'a.b');188test('$ concatenates tokens - \\.', testScriptStdout, () => $`echo.js \.a\. b`, '.a.\nb');189test('$ concatenates expressions - \\.', testScriptStdout, () => $`echo.js \.${'a'}\. b`, '.a.\nb');190/* eslint-disable unicorn/no-hex-escape */191test('$ handles tokens - \\x63', testScriptStdout, () => $`echo.js \x63`, 'c');192test('$ splits tokens - \\x63', testScriptStdout, () => $`echo.js a\x63b`, 'acb');193test('$ splits expressions - \\x63', testScriptStdout, () => $`echo.js ${'a'}\x63${'b'}`, 'acb');194test('$ concatenates tokens - \\x63', testScriptStdout, () => $`echo.js \x63a\x63 b`, 'cac\nb');195test('$ concatenates expressions - \\x63', testScriptStdout, () => $`echo.js \x63${'a'}\x63 b`, 'cac\nb');196/* eslint-enable unicorn/no-hex-escape */197test('$ handles tokens - \\u0063', testScriptStdout, () => $`echo.js \u0063`, 'c');198test('$ splits tokens - \\u0063', testScriptStdout, () => $`echo.js a\u0063b`, 'acb');199test('$ splits expressions - \\u0063', testScriptStdout, () => $`echo.js ${'a'}\u0063${'b'}`, 'acb');200test('$ concatenates tokens - \\u0063', testScriptStdout, () => $`echo.js \u0063a\u0063 b`, 'cac\nb');201test('$ concatenates expressions - \\u0063', testScriptStdout, () => $`echo.js \u0063${'a'}\u0063 b`, 'cac\nb');202test('$ handles tokens - \\u{1}', testScriptStdout, () => $`echo.js \u{1}`, '\u0001');203test('$ splits tokens - \\u{1}', testScriptStdout, () => $`echo.js a\u{1}b`, 'a\u0001b');204test('$ splits expressions - \\u{1}', testScriptStdout, () => $`echo.js ${'a'}\u{1}${'b'}`, 'a\u0001b');205test('$ concatenates tokens - \\u{1}', testScriptStdout, () => $`echo.js \u{1}a\u{1} b`, '\u0001a\u0001\nb');206test('$ concatenates expressions - \\u{1}', testScriptStdout, () => $`echo.js \u{1}${'a'}\u{1} b`, '\u0001a\u0001\nb');207test('$ handles tokens - \\u{63}', testScriptStdout, () => $`echo.js \u{63}`, 'c');208test('$ splits tokens - \\u{63}', testScriptStdout, () => $`echo.js a\u{63}b`, 'acb');209test('$ splits expressions - \\u{63}', testScriptStdout, () => $`echo.js ${'a'}\u{63}${'b'}`, 'acb');210test('$ concatenates tokens - \\u{63}', testScriptStdout, () => $`echo.js \u{63}a\u{63} b`, 'cac\nb');211test('$ concatenates expressions - \\u{63}', testScriptStdout, () => $`echo.js \u{63}${'a'}\u{63} b`, 'cac\nb');212test('$ handles tokens - \\u{063}', testScriptStdout, () => $`echo.js \u{063}`, 'c');213test('$ splits tokens - \\u{063}', testScriptStdout, () => $`echo.js a\u{063}b`, 'acb');214test('$ splits expressions - \\u{063}', testScriptStdout, () => $`echo.js ${'a'}\u{063}${'b'}`, 'acb');215test('$ concatenates tokens - \\u{063}', testScriptStdout, () => $`echo.js \u{063}a\u{063} b`, 'cac\nb');216test('$ concatenates expressions - \\u{063}', testScriptStdout, () => $`echo.js \u{063}${'a'}\u{063} b`, 'cac\nb');217test('$ handles tokens - \\u{0063}', testScriptStdout, () => $`echo.js \u{0063}`, 'c');218test('$ splits tokens - \\u{0063}', testScriptStdout, () => $`echo.js a\u{0063}b`, 'acb');219test('$ splits expressions - \\u{0063}', testScriptStdout, () => $`echo.js ${'a'}\u{0063}${'b'}`, 'acb');220test('$ concatenates tokens - \\u{0063}', testScriptStdout, () => $`echo.js \u{0063}a\u{0063} b`, 'cac\nb');221test('$ concatenates expressions - \\u{0063}', testScriptStdout, () => $`echo.js \u{0063}${'a'}\u{0063} b`, 'cac\nb');222test('$ handles tokens - \\u{00063}', testScriptStdout, () => $`echo.js \u{00063}`, 'c');223test('$ splits tokens - \\u{00063}', testScriptStdout, () => $`echo.js a\u{00063}b`, 'acb');224test('$ splits expressions - \\u{00063}', testScriptStdout, () => $`echo.js ${'a'}\u{00063}${'b'}`, 'acb');225test('$ concatenates tokens - \\u{00063}', testScriptStdout, () => $`echo.js \u{00063}a\u{00063} b`, 'cac\nb');226test('$ concatenates expressions - \\u{00063}', testScriptStdout, () => $`echo.js \u{00063}${'a'}\u{00063} b`, 'cac\nb');227test('$ handles tokens - \\u{000063}', testScriptStdout, () => $`echo.js \u{000063}`, 'c');228test('$ splits tokens - \\u{000063}', testScriptStdout, () => $`echo.js a\u{000063}b`, 'acb');229test('$ splits expressions - \\u{000063}', testScriptStdout, () => $`echo.js ${'a'}\u{000063}${'b'}`, 'acb');230test('$ concatenates tokens - \\u{000063}', testScriptStdout, () => $`echo.js \u{000063}a\u{000063} b`, 'cac\nb');231test('$ concatenates expressions - \\u{000063}', testScriptStdout, () => $`echo.js \u{000063}${'a'}\u{000063} b`, 'cac\nb');232test('$ handles tokens - \\u{0000063}', testScriptStdout, () => $`echo.js \u{0000063}`, 'c');233test('$ splits tokens - \\u{0000063}', testScriptStdout, () => $`echo.js a\u{0000063}b`, 'acb');234test('$ splits expressions - \\u{0000063}', testScriptStdout, () => $`echo.js ${'a'}\u{0000063}${'b'}`, 'acb');235test('$ concatenates tokens - \\u{0000063}', testScriptStdout, () => $`echo.js \u{0000063}a\u{0000063} b`, 'cac\nb');236test('$ concatenates expressions - \\u{0000063}', testScriptStdout, () => $`echo.js \u{0000063}${'a'}\u{0000063} b`, 'cac\nb');237test('$ handles tokens - \\u{0063}}', testScriptStdout, () => $`echo.js \u{0063}}`, 'c}');238test('$ splits tokens - \\u{0063}}', testScriptStdout, () => $`echo.js a\u{0063}}b`, 'ac}b');239test('$ splits expressions - \\u{0063}}', testScriptStdout, () => $`echo.js ${'a'}\u{0063}}${'b'}`, 'ac}b');240test('$ concatenates tokens - \\u{0063}}', testScriptStdout, () => $`echo.js \u{0063}}a\u{0063}} b`, 'c}ac}\nb');241test('$ concatenates expressions - \\u{0063}}', testScriptStdout, () => $`echo.js \u{0063}}${'a'}\u{0063}} b`, 'c}ac}\nb');Split files (#791)ehmickybefore adoption932fb26
line 242why, one step back242Allow newlines in `$` (#843)ehmickybefore adoption1315486
lines 243–246why, one step back243const testScriptStdoutSync = (t, getChildProcess, expectedStdout) => {244 const {stdout} = getChildProcess();245 t.is(stdout, expectedStdout);246};Split files (#791)ehmickybefore adoption932fb26
line 247why, one step back247Allow newlines in `$` (#843)ehmickybefore adoption1315486
lines 248–250why, one step back248test('$.sync', testScriptStdoutSync, () => $.sync`echo.js foo bar`, 'foo\nbar');249test('$.sync can be called $.s', testScriptStdoutSync, () => $.s`echo.js foo bar`, 'foo\nbar');250test('$.sync accepts options', testScriptStdoutSync, () => $({stripFinalNewline: true}).sync`noop.js foo`, 'foo');Split files (#791)ehmickybefore adoption932fb26
line 251why, one step back251Allow newlines in `$` (#843)ehmickybefore adoption1315486
lines 252–256why, one step back252const testReturnInterpolate = async (t, getChildProcess, expectedStdout, options = {}) => {253 const foo = await $(options)`echo.js foo`;254 const {stdout} = await getChildProcess(foo);255 t.is(stdout, expectedStdout);256};Split files (#791)ehmickybefore adoption932fb26
line 257why, one step back257Allow newlines in `$` (#843)ehmickybefore adoption1315486
lines 258–261why, one step back258test('$ allows execa return value interpolation', testReturnInterpolate, foo => $`echo.js ${foo} bar`, 'foo\nbar');259test('$ allows execa return value buffer interpolation', testReturnInterpolate, foo => $`echo.js ${foo} bar`, 'foo\nbar', {encoding: 'buffer'});260test('$ allows execa return value array interpolation', testReturnInterpolate, foo => $`echo.js ${[foo, 'bar']}`, 'foo\nbar');261test('$ allows execa return value buffer array interpolation', testReturnInterpolate, foo => $`echo.js ${[foo, 'bar']}`, 'foo\nbar', {encoding: 'buffer'});Split files (#791)ehmickybefore adoption932fb26
line 262why, one step back262Allow newlines in `$` (#843)ehmickybefore adoption1315486
lines 263–267why, one step back263const testReturnInterpolateSync = (t, getChildProcess, expectedStdout, options = {}) => {264 const foo = $(options).sync`echo.js foo`;265 const {stdout} = getChildProcess(foo);266 t.is(stdout, expectedStdout);267};Split files (#791)ehmickybefore adoption932fb26
line 268why, one step back268Allow newlines in `$` (#843)ehmickybefore adoption1315486
lines 269–272why, one step back269test('$.sync allows execa return value interpolation', testReturnInterpolateSync, foo => $.sync`echo.js ${foo} bar`, 'foo\nbar');270test('$.sync allows execa return value buffer interpolation', testReturnInterpolateSync, foo => $.sync`echo.js ${foo} bar`, 'foo\nbar', {encoding: 'buffer'});271test('$.sync allows execa return value array interpolation', testReturnInterpolateSync, foo => $.sync`echo.js ${[foo, 'bar']}`, 'foo\nbar');272test('$.sync allows execa return value buffer array interpolation', testReturnInterpolateSync, foo => $.sync`echo.js ${[foo, 'bar']}`, 'foo\nbar', {encoding: 'buffer'});Split files (#791)ehmickybefore adoption932fb26
line 273why, one step back273Allow newlines in `$` (#843)ehmickybefore adoption1315486
lines 274–276why, one step back274const testInvalidSequence = (t, getChildProcess) => {275 t.throws(getChildProcess, {message: /Invalid backslash sequence/});276};Split files (#791)ehmickybefore adoption932fb26
line 277why, one step back277Allow newlines in `$` (#843)ehmickybefore adoption1315486
lines 278–291why, one step back278test('$ handles invalid escape sequence - \\1', testInvalidSequence, () => $`echo.js \1`);279test('$ handles invalid escape sequence - \\u', testInvalidSequence, () => $`echo.js \u`);280test('$ handles invalid escape sequence - \\u0', testInvalidSequence, () => $`echo.js \u0`);281test('$ handles invalid escape sequence - \\u00', testInvalidSequence, () => $`echo.js \u00`);282test('$ handles invalid escape sequence - \\u000', testInvalidSequence, () => $`echo.js \u000`);283test('$ handles invalid escape sequence - \\ug', testInvalidSequence, () => $`echo.js \ug`);284test('$ handles invalid escape sequence - \\u{', testInvalidSequence, () => $`echo.js \u{`);285test('$ handles invalid escape sequence - \\u{0000', testInvalidSequence, () => $`echo.js \u{0000`);286test('$ handles invalid escape sequence - \\u{g}', testInvalidSequence, () => $`echo.js \u{g}`);287/* eslint-disable unicorn/no-hex-escape */288test('$ handles invalid escape sequence - \\x', testInvalidSequence, () => $`echo.js \x`);289test('$ handles invalid escape sequence - \\x0', testInvalidSequence, () => $`echo.js \x0`);290test('$ handles invalid escape sequence - \\xgg', testInvalidSequence, () => $`echo.js \xgg`);291/* eslint-enable unicorn/no-hex-escape */Split files (#791)ehmickybefore adoption932fb26
line 292why, one step back292Allow newlines in `$` (#843)ehmickybefore adoption1315486
lines 293–295why, one step back293const testEmptyScript = (t, getChildProcess) => {294 t.throws(getChildProcess, {message: /Template script must not be empty/});295};Split files (#791)ehmickybefore adoption932fb26
line 296why, one step back296Allow newlines in `$` (#843)ehmickybefore adoption1315486
lines 297–302why, one step back297test('$``', testEmptyScript, () => $``);298test('$` `', testEmptyScript, () => $` `);299test('$` ` (2 spaces)', testEmptyScript, () => $` `);300test('$`\\t`', testEmptyScript, () => $` `);301test('$`\\n`', testEmptyScript, () => $`302`);Split files (#791)ehmickybefore adoption932fb26
line 303why, one step back303Allow newlines in `$` (#843)ehmickybefore adoption1315486
lines 304–305why, one step back304test('$.sync must be used after options binding, not before', t => {305 t.throws(() => $.sync({})`noop.js`, {message: /Please use/});Split files (#791)ehmickybefore adoption932fb26
lines 306–307why, one step back306});307Improve input validation (#838)ehmickybefore adoption8ee137c
lines 308–313why, one step back308test('$ must only use options or templates', t => {309 t.throws(() => $(true)`noop.js`, {message: /Please use either/});310});311312test('$.sync must only templates', t => {313 t.throws(() => $.sync(true)`noop.js`, {message: /A template string must be used/});Split files (#791)ehmickybefore adoption932fb26
lines 314–315why, one step back314});315Allow newlines in `$` (#843)ehmickybefore adoption1315486
lines 316–322why, one step back316const testInvalidExpression = (t, invalidExpression, execaMethod) => {317 const expression = typeof invalidExpression === 'function' ? invalidExpression() : invalidExpression;318 t.throws(319 () => execaMethod`echo.js ${expression}`,320 {message: /in template expression/},321 );322};Split files (#791)ehmickybefore adoption932fb26
line 323why, one step back323Allow newlines in `$` (#843)ehmickybefore adoption1315486
lines 324–345why, one step back324test('$ throws on invalid expression - undefined', testInvalidExpression, undefined, $);325test('$ throws on invalid expression - null', testInvalidExpression, null, $);326test('$ throws on invalid expression - true', testInvalidExpression, true, $);327test('$ throws on invalid expression - {}', testInvalidExpression, {}, $);328test('$ throws on invalid expression - {foo: "bar"}', testInvalidExpression, {foo: 'bar'}, $);329test('$ throws on invalid expression - {stdout: undefined}', testInvalidExpression, {stdout: undefined}, $);330test('$ throws on invalid expression - {stdout: 1}', testInvalidExpression, {stdout: 1}, $);331test('$ throws on invalid expression - Promise.resolve()', testInvalidExpression, Promise.resolve(), $);332test('$ throws on invalid expression - Promise.resolve({stdout: "foo"})', testInvalidExpression, Promise.resolve({foo: 'bar'}), $);333test('$ throws on invalid expression - $', testInvalidExpression, () => $`noop.js`, $);334test('$ throws on invalid expression - $(options).sync', testInvalidExpression, () => $({stdio: 'ignore'}).sync`noop.js`, $);335test('$ throws on invalid expression - [undefined]', testInvalidExpression, [undefined], $);336test('$ throws on invalid expression - [null]', testInvalidExpression, [null], $);337test('$ throws on invalid expression - [true]', testInvalidExpression, [true], $);338test('$ throws on invalid expression - [{}]', testInvalidExpression, [{}], $);339test('$ throws on invalid expression - [{foo: "bar"}]', testInvalidExpression, [{foo: 'bar'}], $);340test('$ throws on invalid expression - [{stdout: undefined}]', testInvalidExpression, [{stdout: undefined}], $);341test('$ throws on invalid expression - [{stdout: 1}]', testInvalidExpression, [{stdout: 1}], $);342test('$ throws on invalid expression - [Promise.resolve()]', testInvalidExpression, [Promise.resolve()], $);343test('$ throws on invalid expression - [Promise.resolve({stdout: "foo"})]', testInvalidExpression, [Promise.resolve({stdout: 'foo'})], $);344test('$ throws on invalid expression - [$]', testInvalidExpression, () => [$`noop.js`], $);345test('$ throws on invalid expression - [$(options).sync]', testInvalidExpression, () => [$({stdio: 'ignore'}).sync`noop.js`], $);Split files (#791)ehmickybefore adoption932fb26
lines 346–359why, one step back346347test('$ stdin defaults to "inherit"', async t => {348 const {stdout} = await $({input: 'foo'})`stdin-script.js`;349 t.is(stdout, 'foo');350});351352test('$.sync stdin defaults to "inherit"', t => {353 const {stdout} = $({input: 'foo'}).sync`stdin-script.js`;354 t.is(stdout, 'foo');355});356357test('$ stdin has no default value when stdio is set', t => {358 t.true(isStream($({stdio: 'pipe'})`noop.js`.stdin));359});`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562
lines 360–365why, one step back360361test('$.pipe(childProcess)', async t => {362 const {stdout} = await $`noop.js ${foobarString}`.pipe($({stdin: 'pipe'})`stdin.js`);363 t.is(stdout, foobarString);364});365Fix calling script `.pipe` multiple times (#846)ehmickybefore adoptionbd547e4
lines 366–372why, one step back366test('$.pipe.pipe(childProcess)', async t => {367 const {stdout} = await $`noop.js ${foobarString}`368 .pipe($({stdin: 'pipe'})`stdin.js`)369 .pipe($({stdin: 'pipe'})`stdin.js`);370 t.is(stdout, foobarString);371});372`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562
lines 373–377why, one step back373test('$.pipe`command`', async t => {374 const {stdout} = await $`noop.js ${foobarString}`.pipe`stdin.js`;375 t.is(stdout, foobarString);376});377Fix calling script `.pipe` multiple times (#846)ehmickybefore adoptionbd547e4
lines 378–384why, one step back378test('$.pipe.pipe`command`', async t => {379 const {stdout} = await $`noop.js ${foobarString}`380 .pipe`stdin.js`381 .pipe`stdin.js`;382 t.is(stdout, foobarString);383});384`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562
lines 385–389why, one step back385test('$.pipe(childProcess, pipeOptions)', async t => {386 const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});387 t.is(stdout, foobarString);388});389Fix calling script `.pipe` multiple times (#846)ehmickybefore adoptionbd547e4
lines 390–396why, one step back390test('$.pipe.pipe(childProcess, pipeOptions)', async t => {391 const {stdout} = await $`noop-fd.js 2 ${foobarString}`392 .pipe($({stdin: 'pipe'})`noop-stdin-fd.js 2`, {from: 'stderr'})393 .pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});394 t.is(stdout, foobarString);395});396`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562
lines 397–401why, one step back397test('$.pipe(pipeOptions)`command`', async t => {398 const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe({from: 'stderr'})`stdin.js`;399 t.is(stdout, foobarString);400});401Fix calling script `.pipe` multiple times (#846)ehmickybefore adoptionbd547e4
lines 402–408why, one step back402test('$.pipe.pipe(pipeOptions)`command`', async t => {403 const {stdout} = await $`noop-fd.js 2 ${foobarString}`404 .pipe({from: 'stderr'})`noop-stdin-fd.js 2`405 .pipe({from: 'stderr'})`stdin.js`;406 t.is(stdout, foobarString);407});408`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562
lines 409–413why, one step back409test('$.pipe(options)`command`', async t => {410 const {stdout} = await $`noop.js ${foobarString}`.pipe({stripFinalNewline: false})`stdin.js`;411 t.is(stdout, `${foobarString}\n`);412});413Fix calling script `.pipe` multiple times (#846)ehmickybefore adoptionbd547e4
lines 414–420why, one step back414test('$.pipe.pipe(options)`command`', async t => {415 const {stdout} = await $`noop.js ${foobarString}`416 .pipe({})`stdin.js`417 .pipe({stripFinalNewline: false})`stdin.js`;418 t.is(stdout, `${foobarString}\n`);419});420`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562
lines 421–425why, one step back421test('$.pipe(pipeAndProcessOptions)`command`', async t => {422 const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`.pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;423 t.is(stdout, `${foobarString}\n`);424});425Fix calling script `.pipe` multiple times (#846)ehmickybefore adoptionbd547e4
lines 426–432why, one step back426test('$.pipe.pipe(pipeAndProcessOptions)`command`', async t => {427 const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`428 .pipe({from: 'stderr'})`noop-stdin-fd.js 2`429 .pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;430 t.is(stdout, `${foobarString}\n`);431});432`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562
lines 433–434why, one step back433test('$.pipe(options)(secondOptions)`command`', async t => {434 const {stdout} = await $`noop.js ${foobarString}`.pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;Fix calling script `.pipe` multiple times (#846)ehmickybefore adoptionbd547e4
lines 435–441why, one step back435 t.is(stdout, foobarString);436});437438test('$.pipe.pipe(options)(secondOptions)`command`', async t => {439 const {stdout} = await $`noop.js ${foobarString}`440 .pipe({})({})`stdin.js`441 .pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562
lines 442–458why, one step back442 t.is(stdout, foobarString);443});444445test('$.pipe(options)(childProcess) fails', t => {446 t.throws(() => {447 $`empty.js`.pipe({stdout: 'pipe'})($`empty.js`);448 }, {message: /Please use \.pipe/});449});450451const testInvalidPipe = (t, ...args) => {452 t.throws(() => {453 $`empty.js`.pipe(...args);454 }, {message: /must be a template string/});455};456457test('$.pipe(nonExecaChildProcess) fails', testInvalidPipe, spawn('node', ['--version']));458test('$.pipe(false) fails', testInvalidPipe, false);