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
Provenance
- Commit
14f16df- Tree
a8b2ae5- Author
Sindre Sorhus <sindresorhus@gmail.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
8c705e9
5 files changed+27 added−11 removed
added:fixtures/exit+3 added
1+#!/usr/bin/env node2+'use strict';3+process.exit(Number(process.argv[2]));added:fixtures/noop+3 added
1+#!/usr/bin/env node2+'use strict';3+console.log(process.argv[2]);modified:index.js+3 added-2 removed
2 unmodified lines3456789101119 unmodified lines3132333434353636373839404182 unmodified lines2 unmodified linesvar crossSpawnAsync = require('cross-spawn-async');var stripEof = require('strip-eof');var objectAssign = require('object-assign');var npmRunPath = require('npm-run-path');var pathKey = require('path-key')();var TEN_MEBIBYTE = 1024 * 1024 * 10;
function handleArgs(cmd, args, opts) { var parsed;19 unmodified lines }, parsed.options);
if (opts.preferLocal) { opts.env = objectAssign({}, opts.env || process.env); opts.env.PATH = npmRunPath({ opts.env[pathKey] = npmRunPath({ cwd: opts.cwd, path: opts.env.PATH path: opts.env[pathKey] }); }
return {82 unmodified linesmodified:package.json+1 added
37 unmodified lines3839404142434445465 unmodified lines37 unmodified lines "dependencies": { "cross-spawn-async": "^2.1.1", "npm-run-path": "^1.0.0", "object-assign": "^4.0.1", "path-key": "^1.0.0", "strip-eof": "^1.0.0" }, "devDependencies": { "ava": "*",5 unmodified linesmodified:test.js+17 added-9 removed
1+import path from 'path';2 import test from 'ava';3 import getStream from 'get-stream';4 import m from './';5 6+process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;7+8 test('execa()', async t => {6- const {stdout} = await m('echo', ['foo']);9+ const {stdout} = await m('noop', ['foo']);10 t.is(stdout, 'foo');11 });12 13 test('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 lines27 t.true(err.message.indexOf('stdout') !== -1);28 });29 30 test('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 });34 35 test('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 });39 40 test('execa.sync()', t => {38- const stdout = m.sync('echo', ['foo']);41+ const stdout = m.sync('noop', ['foo']);42 t.is(stdout, 'foo');43 });44 45 test('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 });49 50 test.serial('preferLocal option', async t => {51 t.true((await m('cat-names')).stdout.length > 2);52 53+ if (process.platform === 'win32') {54+ // TODO: figure out how to make the below not hang on Windows55+ return;56+ }57+58 // 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 });64 65 test('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 });