Skip to content

Commit

Permalink
update error from execa in jest-changed-files
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Aug 20, 2019
1 parent 7bdf929 commit 52e47de
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
10 changes: 5 additions & 5 deletions e2e/runJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -39,7 +39,7 @@ function spawnJest(
args?: Array<string>,
options?: RunJestOptions,
spawnAsync?: false,
): ExecaReturns;
): ExecaReturnValue;
function spawnJest(
dir: string,
args?: Array<string>,
Expand All @@ -53,7 +53,7 @@ function spawnJest(
args?: Array<string>,
options: RunJestOptions = {},
spawnAsync: boolean = false,
): ExecaReturnValue | ExecaChildProcess {
): ExecaSyncReturnValue | ExecaChildProcess {
const isRelative = !path.isAbsolute(dir);

if (isRelative) {
Expand Down Expand Up @@ -91,15 +91,15 @@ function spawnJest(
);
}

type RunJestResult = ExecaReturns & {
interface RunJestResult extends ExecaReturnValue {
status?: number;
code?: number;
json?: (
dir: string,
args: Array<string> | undefined,
options: RunJestOptions,
) => RunJestResult;
};
}

function normalizeResult(result: RunJestResult, options: RunJestOptions) {
// For compat with cross-spawn
Expand Down
12 changes: 10 additions & 2 deletions packages/jest-changed-files/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -16,7 +16,15 @@ const findChangedFilesUsingCommand = async (
args: Array<string>,
cwd: Config.Path,
): Promise<Array<Config.Path>> => {
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')
Expand Down
12 changes: 10 additions & 2 deletions packages/jest-changed-files/src/hg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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')
Expand Down

0 comments on commit 52e47de

Please sign in to comment.