Skip to content

Commit ceabd69

Browse files
chore: add env to test git command
1 parent 2751e4d commit ceabd69

File tree

4 files changed

+61
-8
lines changed

4 files changed

+61
-8
lines changed

__tests__/git-helper.test.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -902,13 +902,13 @@ describe('GitHelper without params', () => {
902902
});
903903
});
904904

905-
describe('ACTIONS_STEP_DEBUG test', () => {
905+
describe('Debug', () => {
906906
testEnv();
907907
testChildProcess();
908908

909909
const helper = new GitHelper(new Logger(), {token: 'token1'});
910910

911-
it('should add suppress error command', async() => {
911+
it('should add command to suppress error and output', async() => {
912912
const mockExec = spyOnSpawn();
913913
const mockStdout = spyOnStdout();
914914
mockExec.mockImplementation(() => {
@@ -929,7 +929,29 @@ describe('ACTIONS_STEP_DEBUG test', () => {
929929
]);
930930
});
931931

932-
it('should not add suppress error command', async() => {
932+
it('should not add command to suppress error', async() => {
933+
process.env.ACTIONS_UTILS_DEBUG = 'true';
934+
const mockExec = spyOnSpawn();
935+
const mockStdout = spyOnStdout();
936+
mockExec.mockImplementation(() => {
937+
const error: ExecException = new Error('test error');
938+
error.code = 123;
939+
throw error;
940+
});
941+
942+
await expect(helper.addOrigin(workDir, context())).rejects.toThrow('command [git remote add origin] exited with code 123.');
943+
944+
execCalledWith(mockExec, [
945+
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1',
946+
]);
947+
stdoutCalledWith(mockStdout, [
948+
'[command]git remote add origin',
949+
'undefined',
950+
'{}',
951+
]);
952+
});
953+
954+
it('should not add command to suppress error output', async() => {
933955
process.env.ACTIONS_STEP_DEBUG = 'true';
934956
const mockExec = spyOnSpawn();
935957
const mockStdout = spyOnStdout();
@@ -942,7 +964,7 @@ describe('ACTIONS_STEP_DEBUG test', () => {
942964
await expect(helper.addOrigin(workDir, context())).rejects.toThrow('command [git remote add origin] exited with code 123.');
943965

944966
execCalledWith(mockExec, [
945-
'git remote add origin \'https://octocat:[email protected]/hello/world.git\'',
967+
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' || :',
946968
]);
947969
stdoutCalledWith(mockStdout, [
948970
'[command]git remote add origin',

__tests__/utils2.test.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import {testEnv} from '@technote-space/github-action-test-helper';
33
import {Utils} from '../src';
44

5-
const {generateNewPatchVersion, generateNewMinorVersion, generateNewMajorVersion, arrayChunk, versionCompare, mask, isActionsStepDebug} = Utils;
6-
const {isBranch, isTagRef, normalizeRef, trimRef, getTag, getRefspec, getRemoteRefspec, getLocalRefspec, getOctokit, replaceVariables} = Utils;
5+
const {generateNewPatchVersion, generateNewMinorVersion, generateNewMajorVersion, arrayChunk, versionCompare, mask, isActionsStepDebug} = Utils;
6+
const {isBranch, isTagRef, normalizeRef, trimRef, getTag, getRefspec, getRemoteRefspec, getLocalRefspec, getOctokit, replaceVariables, isDebug} = Utils;
77

88
jest.useFakeTimers();
99

@@ -264,6 +264,34 @@ describe('replaceVariables', () => {
264264
});
265265
});
266266

267+
describe('isDebug', () => {
268+
testEnv();
269+
270+
it('should return true', () => {
271+
process.env.ACTIONS_UTILS_DEBUG = 'true';
272+
expect(isDebug()).toBe(true);
273+
});
274+
275+
it('should return false 1', () => {
276+
expect(isDebug()).toBe(false);
277+
});
278+
279+
it('should return false 2', () => {
280+
process.env.ACTIONS_UTILS_DEBUG = '';
281+
expect(isDebug()).toBe(false);
282+
});
283+
284+
it('should return false 3', () => {
285+
process.env.ACTIONS_UTILS_DEBUG = '1';
286+
expect(isDebug()).toBe(false);
287+
});
288+
289+
it('should return false 4', () => {
290+
process.env.ACTIONS_UTILS_DEBUG = 'abc';
291+
expect(isDebug()).toBe(false);
292+
});
293+
});
294+
267295
describe('isActionsStepDebug', () => {
268296
testEnv();
269297

src/git-helper.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
getAccessToken,
1616
generateNewMinorVersion,
1717
generateNewMajorVersion,
18+
isDebug,
1819
isActionsStepDebug,
1920
} from './utils';
2021
import {getGitUrlWithToken} from './context-helper';
@@ -67,12 +68,12 @@ export default class GitHelper {
6768
/**
6869
* @return {boolean} should suppress error
6970
*/
70-
private shouldSuppressError = (): boolean => !isActionsStepDebug();
71+
private shouldSuppressError = (): boolean => !isDebug();
7172

7273
/**
7374
* @return {boolean} is quiet?
7475
*/
75-
private isQuiet = (): boolean => this.shouldSuppressError() && (!this.origin || this.quietIfNotOrigin);
76+
private isQuiet = (): boolean => !isActionsStepDebug() && (!this.origin || this.quietIfNotOrigin);
7677

7778
/**
7879
* @param {string} workDir work dir

src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,6 @@ export const replaceVariables = async(string: string, variables: { key: string;
253253
return replaced;
254254
};
255255

256+
export const isDebug = (): boolean => process.env.ACTIONS_UTILS_DEBUG === 'true';
257+
256258
export const isActionsStepDebug = (): boolean => process.env.ACTIONS_STEP_DEBUG === 'true';

0 commit comments

Comments
 (0)