Skip to content
Myr

fix tests on Windows 💩

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

FML...

authored by Sindre Sorhus · committed by Sindre Sorhus · parent 8c705e9 · Browse files · 5 files+27 added−11 removed
This commit

State

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

Diff stats

5 files+27 added−11 removed

  • other:+27 added−11 removed

5 files+27 added−11 removed

added:fixtures/exit+3 added
1#!/usr/bin/env node2'use strict';3process.exit(Number(process.argv[2]));
added:fixtures/noop+3 added
1#!/usr/bin/env node2'use strict';3console.log(process.argv[2]);
modified:index.js+3 added-2 removed
modified:package.json+1 added
modified:test.js+17 added-9 removed
1import path from 'path';2import test from 'ava';3import getStream from 'get-stream';4import m from './';56process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;78test('execa()', async t => {6 const {stdout} = await m('echo', ['foo']);9 const {stdout} = await m('noop', ['foo']);10 t.is(stdout, 'foo');11});1213test('buffer', async t => {11 const {stdout} = await m('echo', ['foo'], {encoding: null});14 const {stdout} = await m('noop', ['foo'], {encoding: null});15 t.true(Buffer.isBuffer(stdout));16 t.is(stdout.toString(), 'foo');17});18
8 unmodified lines
27 t.true(err.message.indexOf('stdout') !== -1);28});2930test('execa.shell()', async t => {28 const {stdout} = await m.shell('echo foo');31 const {stdout} = await m.shell('node fixtures/noop foo');32 t.is(stdout, 'foo');33});3435test('execa.spawn()', async t => {33 t.is(typeof m.spawn('echo').pid, 'number');34 t.is((await getStream(m.spawn('echo', ['foo']).stdout)).trim(), 'foo');36 t.is(typeof m.spawn('noop').pid, 'number');37 t.is((await getStream(m.spawn('noop', ['foo']).stdout)).trim(), 'foo');38});3940test('execa.sync()', t => {38 const stdout = m.sync('echo', ['foo']);41 const stdout = m.sync('noop', ['foo']);42 t.is(stdout, 'foo');43});4445test('stripEof option', async t => {43 const {stdout} = await m('echo', ['foo'], {stripEof: false});46 const {stdout} = await m('noop', ['foo'], {stripEof: false});47 t.is(stdout, 'foo\n');48});4950test.serial('preferLocal option', async t => {51 t.true((await m('cat-names')).stdout.length > 2);5253 if (process.platform === 'win32') {54 // TODO: figure out how to make the below not hang on Windows55 return;56 }5758 // account for npm adding local binaries to the PATH59 const _path = process.env.PATH;60 process.env.PATH = '';53 await t.throws(m('cat-names', {preferLocal: false}), /spawn cat-names ENOENT/);61 await t.throws(m('cat-names', {preferLocal: false}), /spawn .* ENOENT/);62 process.env.PATH = _path;63});6465test('execa() returns a promise with kill() and pid', t => {58 const promise = m('echo', ['foo']);66 const promise = m('noop', ['foo']);67 t.is(typeof promise.kill, 'function');68 t.is(typeof promise.pid, 'number');69});