Skip to content
Myr

Simplify tests (#552)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent 950d1e6 · Browse files · 6 files+48 added−48 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+48 added−48 removed

  • tests:+48 added−48 removed

6 files+48 added−48 removed

modified:test/fixtures/detach.js+1 added-1 removed
modified:test/fixtures/sub-process-exit.js+1 added-1 removed
modified:test/fixtures/sub-process.js+1 added-1 removed
modified:test/command.js+38 added-38 removed
51 unmodified lines
52 t.is(stdout, 'foo\nbar');53});5455test('execaCommand()', async t => {56 const {stdout} = await execaCommand('node test/fixtures/echo.js foo bar');56 const {stdout} = await execaCommand('echo.js foo bar');57 t.is(stdout, 'foo\nbar');58});5960test('execaCommand() ignores consecutive spaces', async t => {61 const {stdout} = await execaCommand('node test/fixtures/echo.js foo bar');61 const {stdout} = await execaCommand('echo.js foo bar');62 t.is(stdout, 'foo\nbar');63});6465test('execaCommand() allows escaping spaces in commands', async t => {
1 unmodified line
67 t.is(stdout, 'foo\nbar');68});6970test('execaCommand() allows escaping spaces in arguments', async t => {71 const {stdout} = await execaCommand('node test/fixtures/echo.js foo\\ bar');71 const {stdout} = await execaCommand('echo.js foo\\ bar');72 t.is(stdout, 'foo bar');73});7475test('execaCommand() escapes other whitespaces', async t => {76 const {stdout} = await execaCommand('node test/fixtures/echo.js foo\tbar');76 const {stdout} = await execaCommand('echo.js foo\tbar');77 t.is(stdout, 'foo\tbar');78});7980test('execaCommand() trims', async t => {81 const {stdout} = await execaCommand(' node test/fixtures/echo.js foo bar ');81 const {stdout} = await execaCommand(' echo.js foo bar ');82 t.is(stdout, 'foo\nbar');83});8485test('execaCommandSync()', t => {86 const {stdout} = execaCommandSync('node test/fixtures/echo.js foo bar');86 const {stdout} = execaCommandSync('echo.js foo bar');87 t.is(stdout, 'foo\nbar');88});8990test('$', async t => {91 const {stdout} = await $`node test/fixtures/echo.js foo bar`;91 const {stdout} = await $`echo.js foo bar`;92 t.is(stdout, 'foo\nbar');93});9495test('$ accepts options', async t => {
1 unmodified line
97 t.is(stdout, 'foo');98});99100test('$ allows string interpolation', async t => {101 const {stdout} = await $`node test/fixtures/echo.js foo ${'bar'}`;101 const {stdout} = await $`echo.js foo ${'bar'}`;102 t.is(stdout, 'foo\nbar');103});104105test('$ allows number interpolation', async t => {106 const {stdout} = await $`node test/fixtures/echo.js 1 ${2}`;106 const {stdout} = await $`echo.js 1 ${2}`;107 t.is(stdout, '1\n2');108});109110test('$ allows array interpolation', async t => {111 const {stdout} = await $`node test/fixtures/echo.js ${['foo', 'bar']}`;111 const {stdout} = await $`echo.js ${['foo', 'bar']}`;112 t.is(stdout, 'foo\nbar');113});114115test('$ allows execa return value interpolation', async t => {116 const foo = await $`node test/fixtures/echo.js foo`;117 const {stdout} = await $`node test/fixtures/echo.js ${foo} bar`;116 const foo = await $`echo.js foo`;117 const {stdout} = await $`echo.js ${foo} bar`;118 t.is(stdout, 'foo\nbar');119});120121test('$ allows execa return value array interpolation', async t => {122 const foo = await $`node test/fixtures/echo.js foo`;123 const {stdout} = await $`node test/fixtures/echo.js ${[foo, 'bar']}`;122 const foo = await $`echo.js foo`;123 const {stdout} = await $`echo.js ${[foo, 'bar']}`;124 t.is(stdout, 'foo\nbar');125});126127test('$ allows execa return value buffer interpolation', async t => {128 const foo = await $({encoding: null})`node test/fixtures/echo.js foo`;129 const {stdout} = await $`node test/fixtures/echo.js ${foo} bar`;128 const foo = await $({encoding: null})`echo.js foo`;129 const {stdout} = await $`echo.js ${foo} bar`;130 t.is(stdout, 'foo\nbar');131});132133test('$ allows execa return value buffer array interpolation', async t => {134 const foo = await $({encoding: null})`node test/fixtures/echo.js foo`;135 const {stdout} = await $`node test/fixtures/echo.js ${[foo, 'bar']}`;134 const foo = await $({encoding: null})`echo.js foo`;135 const {stdout} = await $`echo.js ${[foo, 'bar']}`;136 t.is(stdout, 'foo\nbar');137});138139test('$ ignores consecutive spaces', async t => {140 const {stdout} = await $`node test/fixtures/echo.js foo bar`;140 const {stdout} = await $`echo.js foo bar`;141 t.is(stdout, 'foo\nbar');142});143144test('$ allows escaping spaces with interpolation', async t => {145 const {stdout} = await $`node test/fixtures/echo.js ${'foo bar'}`;145 const {stdout} = await $`echo.js ${'foo bar'}`;146 t.is(stdout, 'foo bar');147});148149test('$ disallows escaping spaces with backslashes', async t => {150 const {stdout} = await $`node test/fixtures/echo.js foo\\ bar`;150 const {stdout} = await $`echo.js foo\\ bar`;151 t.is(stdout, 'foo\\\nbar');152});153154test('$ allows space escaped values in array interpolation', async t => {155 const {stdout} = await $`node test/fixtures/echo.js ${['foo', 'bar baz']}`;155 const {stdout} = await $`echo.js ${['foo', 'bar baz']}`;156 t.is(stdout, 'foo\nbar baz');157});158159test('$ passes newline escape sequence as one argument', async t => {160 const {stdout} = await $`node test/fixtures/echo.js \n`;160 const {stdout} = await $`echo.js \n`;161 t.is(stdout, '\n');162});163164test('$ passes newline escape sequence in interpolation as one argument', async t => {165 const {stdout} = await $`node test/fixtures/echo.js ${'\n'}`;165 const {stdout} = await $`echo.js ${'\n'}`;166 t.is(stdout, '\n');167});168169test('$ handles invalid escape sequence', async t => {170 const {stdout} = await $`node test/fixtures/echo.js \u`;170 const {stdout} = await $`echo.js \u`;171 t.is(stdout, '\\u');172});173174test('$ allows escaping spaces in commands with interpolation', async t => {
1 unmodified line
176 t.is(stdout, 'foo\nbar');177});178179test('$ escapes other whitespaces', async t => {180 const {stdout} = await $`node test/fixtures/echo.js foo\tbar`;180 const {stdout} = await $`echo.js foo\tbar`;181 t.is(stdout, 'foo\tbar');182});183184test('$ trims', async t => {185 const {stdout} = await $` node test/fixtures/echo.js foo bar `;185 const {stdout} = await $` echo.js foo bar `;186 t.is(stdout, 'foo\nbar');187});188189test('$.sync', t => {190 const {stdout} = $.sync`node test/fixtures/echo.js foo bar`;190 const {stdout} = $.sync`echo.js foo bar`;191 t.is(stdout, 'foo\nbar');192});193194test('$.sync accepts options', t => {
1 unmodified line
196 t.is(stdout, 'foo');197});198199test('$.sync allows execa return value interpolation', t => {200 const foo = $.sync`node test/fixtures/echo.js foo`;201 const {stdout} = $.sync`node test/fixtures/echo.js ${foo} bar`;200 const foo = $.sync`echo.js foo`;201 const {stdout} = $.sync`echo.js ${foo} bar`;202 t.is(stdout, 'foo\nbar');203});204205test('$.sync allows execa return value array interpolation', t => {206 const foo = $.sync`node test/fixtures/echo.js foo`;207 const {stdout} = $.sync`node test/fixtures/echo.js ${[foo, 'bar']}`;206 const foo = $.sync`echo.js foo`;207 const {stdout} = $.sync`echo.js ${[foo, 'bar']}`;208 t.is(stdout, 'foo\nbar');209});210211test('$.sync allows execa return value buffer interpolation', t => {212 const foo = $({encoding: null}).sync`node test/fixtures/echo.js foo`;213 const {stdout} = $.sync`node test/fixtures/echo.js ${foo} bar`;212 const foo = $({encoding: null}).sync`echo.js foo`;213 const {stdout} = $.sync`echo.js ${foo} bar`;214 t.is(stdout, 'foo\nbar');215});216217test('$.sync allows execa return value buffer array interpolation', t => {218 const foo = $({encoding: null}).sync`node test/fixtures/echo.js foo`;219 const {stdout} = $.sync`node test/fixtures/echo.js ${[foo, 'bar']}`;218 const foo = $({encoding: null}).sync`echo.js foo`;219 const {stdout} = $.sync`echo.js ${[foo, 'bar']}`;220 t.is(stdout, 'foo\nbar');221});222223const invalidExpression = test.macro({224 async exec(t, input, expected) {225 await t.throwsAsync(226 async () => $`node test/fixtures/echo.js ${input}`,226 async () => $`echo.js ${input}`,227 {instanceOf: TypeError, message: expected},228 );229230 t.throws(231 () => $.sync`node test/fixtures/echo.js ${input}`,231 () => $.sync`echo.js ${input}`,232 {instanceOf: TypeError, message: expected},233 );234 },235 title(prettyInput, input, expected) {
36 unmodified lines
modified:test/kill.js+5 added-5 removed
8 unmodified lines
910const TIMEOUT_REGEXP = /timed out after/;1112test('kill("SIGKILL") should terminate cleanly', async t => {13 const subprocess = execa('node', ['./test/fixtures/no-killable.js'], {stdio: ['ipc']});13 const subprocess = execa('no-killable.js', {stdio: ['ipc']});14 await pEvent(subprocess, 'message');1516 subprocess.kill('SIGKILL');17
4 unmodified lines
22// `SIGTERM` cannot be caught on Windows, and it always aborts the process (like `SIGKILL` on Unix).23// Therefore, this feature and those tests do not make sense on Windows.24if (process.platform !== 'win32') {25 test('`forceKillAfterTimeout: false` should not kill after a timeout', async t => {26 const subprocess = execa('node', ['./test/fixtures/no-killable.js'], {stdio: ['ipc']});26 const subprocess = execa('no-killable.js', {stdio: ['ipc']});27 await pEvent(subprocess, 'message');2829 subprocess.kill('SIGTERM', {forceKillAfterTimeout: false});30
1 unmodified line
32 subprocess.kill('SIGKILL');33 });3435 test('`forceKillAfterTimeout: number` should kill after a timeout', async t => {36 const subprocess = execa('node', ['./test/fixtures/no-killable.js'], {stdio: ['ipc']});36 const subprocess = execa('no-killable.js', {stdio: ['ipc']});37 await pEvent(subprocess, 'message');3839 subprocess.kill('SIGTERM', {forceKillAfterTimeout: 50});40
1 unmodified line
42 t.is(signal, 'SIGKILL');43 });4445 test('`forceKillAfterTimeout: true` should kill after a timeout', async t => {46 const subprocess = execa('node', ['./test/fixtures/no-killable.js'], {stdio: ['ipc']});46 const subprocess = execa('no-killable.js', {stdio: ['ipc']});47 await pEvent(subprocess, 'message');4849 subprocess.kill('SIGTERM', {forceKillAfterTimeout: true});50
1 unmodified line
52 t.is(signal, 'SIGKILL');53 });5455 test('kill() with no arguments should kill after a timeout', async t => {56 const subprocess = execa('node', ['./test/fixtures/no-killable.js'], {stdio: ['ipc']});56 const subprocess = execa('no-killable.js', {stdio: ['ipc']});57 await pEvent(subprocess, 'message');5859 subprocess.kill();60
250 unmodified lines
modified:test/stream.js+2 added-2 removed
17 unmodified lines
18});1920test('pass `stdout` to a file descriptor', async t => {21 const file = tempfile('.txt');22 await execa('test/fixtures/noop.js', ['foo bar'], {stdout: fs.openSync(file, 'w')});22 await execa('noop.js', ['foo bar'], {stdout: fs.openSync(file, 'w')});23 t.is(fs.readFileSync(file, 'utf8'), 'foo bar\n');24});2526test('pass `stderr` to a file descriptor', async t => {27 const file = tempfile('.txt');28 await execa('test/fixtures/noop-err.js', ['foo bar'], {stderr: fs.openSync(file, 'w')});28 await execa('noop-err.js', ['foo bar'], {stderr: fs.openSync(file, 'w')});29 t.is(fs.readFileSync(file, 'utf8'), 'foo bar\n');30});3132test.serial('result.all shows both `stdout` and `stderr` intermixed', async t => {
200 unmodified lines