Skip to content

Commit

Permalink
re-use ExecReturnType
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Mar 30, 2020
1 parent e3dc225 commit c0fd0ed
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/runWithOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { BackportOptions } from './options/options';
import { commitsWithPullRequestsMock } from './services/github/mocks/commitsByAuthorMock';
import { runWithOptions } from './runWithOptions';
import * as childProcess from './services/child-process-promisified';
import { PromiseReturnType } from './types/PromiseReturnType';

type ExecReturnType = PromiseReturnType<typeof childProcess.exec>;

describe('runWithOptions', () => {
let rpcExecMock: jest.SpyInstance;
Expand Down Expand Up @@ -56,7 +59,7 @@ describe('runWithOptions', () => {

rpcExecMock = jest
.spyOn(childProcess, 'exec')
.mockResolvedValue({ stdout: 'success' } as any);
.mockResolvedValue({ stdout: 'success' } as ExecReturnType);
rpcExecOriginalMock = jest.spyOn(childProcess, 'execAsCallback');

jest.spyOn(fs, 'writeFile').mockResolvedValue(undefined);
Expand Down
3 changes: 0 additions & 3 deletions src/services/child-process-promisified.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import child_process from 'child_process';
import { promisify } from 'util';
import { logger } from './logger';
import { PromiseReturnType } from '../types/PromiseReturnType';

export type ExecReturnType = PromiseReturnType<typeof exec>;

export const exec = (cmd: string, options: child_process.ExecOptions = {}) => {
logger.info(`exec: ${cmd}`);
Expand Down
3 changes: 2 additions & 1 deletion src/services/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {
createFeatureBranch,
} from '../services/git';
import * as childProcess from '../services/child-process-promisified';
import { PromiseReturnType } from '../types/PromiseReturnType';

type ExecReturnType = childProcess.ExecReturnType;
type ExecReturnType = PromiseReturnType<typeof childProcess.exec>;

describe('getUnstagedFiles', () => {
it('should split by linebreak and remove empty items', async () => {
Expand Down
16 changes: 8 additions & 8 deletions src/services/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ export async function cherrypickContinue(options: BackportOptions) {
});
} catch (e) {
const isCherrypickError = e.code === 128;
if (isCherrypickError) {
logger.info(
`Cherry pick continue failed. Probably because the cherry pick operation was manually completed. ${JSON.stringify(
e
)}`
);
return;
if (!isCherrypickError) {
throw e;
}
throw e;

logger.info(
`Cherry pick continue failed. Probably because the cherry pick operation was manually completed. ${JSON.stringify(
e
)}`
);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/ui/cherrypickAndCreatePullRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import * as childProcess from '../services/child-process-promisified';
import * as logger from '../services/logger';
import dedent from 'dedent';
import ora from 'ora';
import { PromiseReturnType } from '../types/PromiseReturnType';

type ExecReturnType = PromiseReturnType<typeof childProcess.exec>;

describe('cherrypickAndCreatePullRequest', () => {
let axiosPostMock: jest.SpyInstance;
Expand Down Expand Up @@ -35,7 +38,7 @@ describe('cherrypickAndCreatePullRequest', () => {
beforeEach(async () => {
execSpy = jest
.spyOn(childProcess, 'exec')
.mockResolvedValue({ stdout: '' } as any);
.mockResolvedValue({ stdout: '' } as ExecReturnType);

const options = {
githubApiBaseUrlV3: 'https://api.github.com',
Expand Down

0 comments on commit c0fd0ed

Please sign in to comment.