From d766aa0e4be53d71635bc40d1fc0d65a9c7a43de 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 --- .../__snapshots__/jestChangedFiles.test.ts.snap | 2 -- e2e/runJest.ts | 14 +++++++++----- packages/jest-changed-files/src/git.ts | 13 +++++++++++-- packages/jest-changed-files/src/hg.ts | 13 +++++++++++-- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/e2e/__tests__/__snapshots__/jestChangedFiles.test.ts.snap b/e2e/__tests__/__snapshots__/jestChangedFiles.test.ts.snap index 52436014c7ec..cbbd571d60a3 100644 --- a/e2e/__tests__/__snapshots__/jestChangedFiles.test.ts.snap +++ b/e2e/__tests__/__snapshots__/jestChangedFiles.test.ts.snap @@ -7,7 +7,6 @@ exports[`handles a bad revision for "changedSince", for git 1`] = ` fatal: bad revision '^blablabla' - `; exports[`handles a bad revision for "changedSince", for hg 1`] = ` @@ -17,5 +16,4 @@ exports[`handles a bad revision for "changedSince", for hg 1`] = ` abort: unknown revision 'blablabla'! - `; diff --git a/e2e/runJest.ts b/e2e/runJest.ts index bbe6e38ecb03..893c87a0c253 100644 --- a/e2e/runJest.ts +++ b/e2e/runJest.ts @@ -9,7 +9,11 @@ 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 +43,7 @@ function spawnJest( args?: Array, options?: RunJestOptions, spawnAsync?: false, -): ExecaReturns; +): ExecaReturnValue; function spawnJest( dir: string, args?: Array, @@ -53,7 +57,7 @@ function spawnJest( args?: Array, options: RunJestOptions = {}, spawnAsync: boolean = false, -): ExecaReturnValue | ExecaChildProcess { +): ExecaSyncReturnValue | ExecaChildProcess { const isRelative = !path.isAbsolute(dir); if (isRelative) { @@ -91,7 +95,7 @@ function spawnJest( ); } -type RunJestResult = ExecaReturns & { +interface RunJestResult extends ExecaReturnValue { status?: number; code?: number; json?: ( @@ -99,7 +103,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..6564c8e1f694 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,16 @@ 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) { + // TODO: Should we keep the original `message`? + e.message = e.stderr; + + 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..54e354ba299d 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,16 @@ 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) { + // TODO: Should we keep the original `message`? + e.message = e.stderr; + + throw e; + } return result.stdout .split('\n')