Skip to content
Myr

Fix lint issues

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

authored by Sindre Sorhus · committed by Sindre Sorhus · parent f8397ba · Browse files · 4 files+81 added−92 removed
This commit

State

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

Diff stats

4 files+81 added−92 removed

  • other:+81 added−92 removed

4 files+81 added−92 removed

modified:lib/errname.js+2 added-2 removed
modified:index.js+29 added-29 removed
143 unmodified lines
144 } else {145 ret = _getStream.buffer(process[stream], {maxBuffer});146 }147148 return ret.catch(err => {149 err.stream = stream;150 err.message = `${stream} ${err.message}`;151 throw err;148 return ret.catch(error => {149 error.stream = stream;150 error.message = `${stream} ${error.message}`;151 throw error;152 });153}154155function makeError(result, options) {156 const {stdout, stderr} = result;157158 let err = result.error;158 let {error} = result;159 const {code, signal} = result;160161 const {parsed, joinedCmd} = options;162 const timedOut = options.timedOut || false;163164 if (!err) {164 if (!error) {165 let output = '';166167 if (Array.isArray(parsed.opts.stdio)) {168 if (parsed.opts.stdio[2] !== 'inherit') {
6 unmodified lines
175 } else if (parsed.opts.stdio !== 'inherit') {176 output = `\n${stderr}${stdout}`;177 }178179 err = new Error(`Command failed: ${joinedCmd}${output}`);180 err.code = code < 0 ? errname(code) : code;179 error = new Error(`Command failed: ${joinedCmd}${output}`);180 error.code = code < 0 ? errname(code) : code;181 }182183 err.stdout = stdout;184 err.stderr = stderr;185 err.failed = true;186 err.signal = signal || null;187 err.cmd = joinedCmd;188 err.timedOut = timedOut;183 error.stdout = stdout;184 error.stderr = stderr;185 error.failed = true;186 error.signal = signal || null;187 error.cmd = joinedCmd;188 error.timedOut = timedOut;189190 return err;190 return error;191}192193function joinCmd(cmd, args) {194 let joinedCmd = cmd;
12 unmodified lines
207208 let spawned;209 try {210 spawned = childProcess.spawn(parsed.cmd, parsed.args, parsed.opts);211 } catch (err) {212 return Promise.reject(err);211 } catch (error) {212 return Promise.reject(error);213 }214215 let removeExitHandler;216 if (parsed.opts.cleanup) {
29 unmodified lines
246 cleanup();247 resolve({code, signal});248 });249250 spawned.on('error', err => {250 spawned.on('error', error => {251 cleanup();252 resolve({error: err});252 resolve({error});253 });254255 if (spawned.stdin) {256 spawned.stdin.on('error', err => {256 spawned.stdin.on('error', error => {257 cleanup();258 resolve({error: err});258 resolve({error});259 });260 }261 });262
16 unmodified lines
279 result.stdout = arr[1];280 result.stderr = arr[2];281282 if (result.error || result.code !== 0 || result.signal !== null) {283 const err = makeError(result, {283 const error = makeError(result, {284 joinedCmd,285 parsed,286 timedOut287 });288289 // TODO: missing some timeout logic for killed290 // https://github.com/nodejs/node/blob/master/lib/child_process.js#L203291 // err.killed = spawned.killed || killed;292 err.killed = err.killed || spawned.killed;291 // error.killed = spawned.killed || killed;292 error.killed = error.killed || spawned.killed;293294 if (!parsed.opts.reject) {295 return err;295 return error;296 }297298 throw err;298 throw error;299 }300301 return {302 stdout: handleOutput(parsed.opts, result.stdout),
36 unmodified lines
339 const result = childProcess.spawnSync(parsed.cmd, parsed.args, parsed.opts);340 result.code = result.status;341342 if (result.error || result.status !== 0 || result.signal !== null) {343 const err = makeError(result, {343 const error = makeError(result, {344 joinedCmd,345 parsed346 });347348 if (!parsed.opts.reject) {349 return err;349 return error;350 }351352 throw err;352 throw error;353 }354355 return {356 stdout: handleOutput(parsed.opts, result.stdout),
10 unmodified lines
modified:package.json+2 added-2 removed
modified:test.js+48 added-59 removed
260 unmodified lines
261 t.is(stderr, '.........\n');262});263264test('skip throwing when using reject option', async t => {265 const err = await m('exit', ['2'], {reject: false});266 t.is(typeof err.stdout, 'string');267 t.is(typeof err.stderr, 'string');265 const error = await m('exit', ['2'], {reject: false});266 t.is(typeof error.stdout, 'string');267 t.is(typeof error.stderr, 'string');268});269270test('execa() returns code and failed properties', async t => {271 const {code, failed} = await m('noop', ['foo']);272 const err = await t.throws(m('exit', ['2']));272 const error = await t.throws(m('exit', ['2']));273 t.is(code, 0);274 t.false(failed);275 t.is(err.code, 2);276 t.true(err.failed);275 t.is(error.code, 2);276 t.true(error.failed);277});278279test(`use relative path with '..' chars`, async t => {279test('use relative path with \'..\' chars', async t => {280 const pathViaParentDir = path.join('..', path.basename(__dirname), 'fixtures', 'noop');281 const {stdout} = await m(pathViaParentDir, ['foo']);282 t.is(stdout, 'foo');283});
4 unmodified lines
288 await t.throws(cp);289 });290}291292test('err.killed is true if process was killed directly', async t => {292test('error.killed is true if process was killed directly', async t => {293 const cp = m('forever');294295 setTimeout(() => {296 cp.kill();297 }, 100);298299 const err = await t.throws(cp);300301 t.true(err.killed);299 const error = await t.throws(cp);300 t.true(error.killed);301});302303// TODO: Should this really be the case, or should we improve on child_process?305test('err.killed is false if process was killed indirectly', async t => {304test('error.killed is false if process was killed indirectly', async t => {305 const cp = m('forever');306307 setTimeout(() => {308 process.kill(cp.pid, 'SIGINT');309 }, 100);310312 const err = await t.throws(cp);313314 t.false(err.killed);311 const error = await t.throws(cp);312 t.false(error.killed);313});314315if (process.platform === 'darwin') {316 test.cb('sanity check: child_process.exec also has killed.false if killed indirectly', t => {319 const cp = childProcess.exec('forever', err => {320 t.truthy(err);321 t.false(err.killed);317 const cp = childProcess.exec('forever', error => {318 t.truthy(error);319 t.false(error.killed);320 t.end();321 });322323 setTimeout(() => {
2 unmodified lines
326 });327}328329if (process.platform !== 'win32') {332 test('err.signal is SIGINT', async t => {330 test('error.signal is SIGINT', async t => {331 const cp = m('forever');332333 setTimeout(() => {334 process.kill(cp.pid, 'SIGINT');335 }, 100);336339 const err = await t.throws(cp);340341 t.is(err.signal, 'SIGINT');337 const error = await t.throws(cp);338 t.is(error.signal, 'SIGINT');339 });340344 test('err.signal is SIGTERM', async t => {341 test('error.signal is SIGTERM', async t => {342 const cp = m('forever');343344 setTimeout(() => {345 process.kill(cp.pid, 'SIGTERM');346 }, 100);347351 const err = await t.throws(cp);352353 t.is(err.signal, 'SIGTERM');348 const error = await t.throws(cp);349 t.is(error.signal, 'SIGTERM');350 });351356 test('custom err.signal', async t => {357 const err = await t.throws(m('delay', ['3000', '0'], {killSignal: 'SIGHUP', timeout: 1500}));358359 t.is(err.signal, 'SIGHUP');352 test('custom error.signal', async t => {353 const error = await t.throws(m('delay', ['3000', '0'], {killSignal: 'SIGHUP', timeout: 1500}));354 t.is(error.signal, 'SIGHUP');355 });356}357358test('result.signal is null for successful execution', async t => {359 t.is((await m('noop')).signal, null);360});361362test('result.signal is null if process failed, but was not killed', async t => {368 const err = await t.throws(m('exit', [2]));369 t.is(err.signal, null);363 const error = await t.throws(m('exit', [2]));364 t.is(error.signal, null);365});366367async function code(t, num) {373 const err = await t.throws(m('exit', [`${num}`]));374375 t.is(err.code, num);368 const error = await t.throws(m('exit', [`${num}`]));369 t.is(error.code, num);370}371378test('err.code is 2', code, 2);379test('err.code is 3', code, 3);380test('err.code is 4', code, 4);372test('error.code is 2', code, 2);373test('error.code is 3', code, 3);374test('error.code is 4', code, 4);375376test('timeout will kill the process early', async t => {383 const err = await t.throws(m('delay', ['60000', '0'], {timeout: 1500}));377 const error = await t.throws(m('delay', ['60000', '0'], {timeout: 1500}));378385 t.true(err.timedOut);386 t.not(err.code, 22);379 t.true(error.timedOut);380 t.not(error.code, 22);381});382383test('timeout will not kill the process early', async t => {390 const err = await t.throws(m('delay', ['3000', '22'], {timeout: 30000}));384 const error = await t.throws(m('delay', ['3000', '22'], {timeout: 30000}));385392 t.false(err.timedOut);393 t.is(err.code, 22);386 t.false(error.timedOut);387 t.is(error.code, 22);388});389390test('timedOut will be false if no timeout was set and zero exit code', async t => {391 const result = await m('delay', ['1000', '0']);398392 t.false(result.timedOut);393});394395test('timedOut will be false if no timeout was set and non-zero exit code', async t => {403 const err = await t.throws(m('delay', ['1000', '3']));404405 t.false(err.timedOut);396 const error = await t.throws(m('delay', ['1000', '3']));397 t.false(error.timedOut);398});399400async function errorMessage(t, expected, ...args) {409 const err = await t.throws(m('exit', args));410411 t.regex(err.message, expected);401 const error = await t.throws(m('exit', args));402 t.regex(error.message, expected);403}404414errorMessage.title = (message, expected) => `err.message matches: ${expected}`;405errorMessage.title = (message, expected) => `error.message matches: ${expected}`;406407test(errorMessage, /Command failed: exit 2 foo bar/, 2, 'foo', 'bar');408test(errorMessage, /Command failed: exit 3 baz quz/, 3, 'baz', 'quz');409410async function cmd(t, expected, ...args) {420 const err = await t.throws(m('fail', args));411 const error = await t.throws(m('fail', args));412 t.is(error.cmd, `fail${expected}`);413422 t.is(err.cmd, `fail${expected}`);423414 const result = await m('noop', args);425415 t.is(result.cmd, `noop${expected}`);416}417418cmd.title = (message, expected) => `cmd is: ${JSON.stringify(expected)}`;
50 unmodified lines
469 // Sometimes process can manage to accept input before exiting470 try {471 await m(`fast-exit-${process.platform}`, [], {input: 'data'});472 t.pass();484 } catch (err) {485 t.is(err.code, 'EPIPE');473 } catch (error) {474 t.is(error.code, 'EPIPE');475 }476 });477}478
52 unmodified lines
531 child.on('error', reject);532 child.on('exit', resolve);533 });534546 const included = ee.listeners('exit').indexOf(listener) !== -1;535 const included = ee.listeners('exit').includes(listener);536 t.false(included);537});