From 52e47dee103fd7fbed673bae05c0bed97b58fc76 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 20 Aug 2019 12:59:34 +0200 Subject: [PATCH] update error from execa in jest-changed-files --- e2e/runJest.ts | 10 +++++----- packages/jest-changed-files/src/git.ts | 12 ++++++++++-- packages/jest-changed-files/src/hg.ts | 12 ++++++++++-- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/e2e/runJest.ts b/e2e/runJest.ts index bbe6e38ecb03..347fe6d509da 100644 --- a/e2e/runJest.ts +++ b/e2e/runJest.ts @@ -9,7 +9,7 @@ import * as path from 'path'; import * as fs from 'fs'; import {Writable} from 'stream'; -import execa, {ExecaChildProcess, ExecaReturnValue} from 'execa'; +import execa, {ExecaChildProcess, ExecaReturnValue, ExecaSyncReturnValue} from 'execa'; import stripAnsi from 'strip-ansi'; import {normalizeIcons} from './Utils'; @@ -39,7 +39,7 @@ function spawnJest( args?: Array, options?: RunJestOptions, spawnAsync?: false, -): ExecaReturns; +): ExecaReturnValue; function spawnJest( dir: string, args?: Array, @@ -53,7 +53,7 @@ function spawnJest( args?: Array, options: RunJestOptions = {}, spawnAsync: boolean = false, -): ExecaReturnValue | ExecaChildProcess { +): ExecaSyncReturnValue | ExecaChildProcess { const isRelative = !path.isAbsolute(dir); if (isRelative) { @@ -91,7 +91,7 @@ function spawnJest( ); } -type RunJestResult = ExecaReturns & { +interface RunJestResult extends ExecaReturnValue { status?: number; code?: number; json?: ( @@ -99,7 +99,7 @@ type RunJestResult = ExecaReturns & { args: Array | undefined, options: RunJestOptions, ) => RunJestResult; -}; +} function normalizeResult(result: RunJestResult, options: RunJestOptions) { // For compat with cross-spawn diff --git a/packages/jest-changed-files/src/git.ts b/packages/jest-changed-files/src/git.ts index e2d5ae0f84a2..c0b36d6f25c5 100644 --- a/packages/jest-changed-files/src/git.ts +++ b/packages/jest-changed-files/src/git.ts @@ -7,7 +7,7 @@ */ import * as path from 'path'; -import execa from 'execa'; +import execa, {ExecaReturnValue} from 'execa'; import {Config} from '@jest/types'; import {SCMAdapter} from './types'; @@ -16,7 +16,15 @@ const findChangedFilesUsingCommand = async ( args: Array, cwd: Config.Path, ): Promise> => { - const result = await execa('git', args, {cwd}); + let result: ExecaReturnValue; + + try { + result = await execa('git', args, {cwd}); + } catch (e) { + e.message = e.stderr + '\n\n' + e.message; + + throw e; + } return result.stdout .split('\n') diff --git a/packages/jest-changed-files/src/hg.ts b/packages/jest-changed-files/src/hg.ts index 1315af7ea379..3812fe5fe8be 100644 --- a/packages/jest-changed-files/src/hg.ts +++ b/packages/jest-changed-files/src/hg.ts @@ -7,7 +7,7 @@ */ import * as path from 'path'; -import execa from 'execa'; +import execa, {ExecaReturnValue} from 'execa'; import {Config} from '@jest/types'; import {SCMAdapter} from './types'; @@ -29,7 +29,15 @@ const adapter: SCMAdapter = { } args.push(...includePaths); - const result = await execa('hg', args, {cwd, env}); + let result: ExecaReturnValue; + + try { + result = await execa('hg', args, {cwd, env}); + } catch (e) { + e.message = e.stderr + '\n\n' + e.message; + + throw e; + } return result.stdout .split('\n')