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 099c976 commit d766aa0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
2 changes: 0 additions & 2 deletions e2e/__tests__/__snapshots__/jestChangedFiles.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `
Expand All @@ -17,5 +16,4 @@ exports[`handles a bad revision for "changedSince", for hg 1`] = `
abort: unknown revision 'blablabla'!
`;
14 changes: 9 additions & 5 deletions e2e/runJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -39,7 +43,7 @@ function spawnJest(
args?: Array<string>,
options?: RunJestOptions,
spawnAsync?: false,
): ExecaReturns;
): ExecaReturnValue;
function spawnJest(
dir: string,
args?: Array<string>,
Expand All @@ -53,7 +57,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 +95,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
13 changes: 11 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,16 @@ 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) {
// TODO: Should we keep the original `message`?
e.message = e.stderr;

throw e;
}

return result.stdout
.split('\n')
Expand Down
13 changes: 11 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,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')
Expand Down

0 comments on commit d766aa0

Please sign in to comment.