Skip to content

Commit 12dba96

Browse files
committed
Move env setup to setup.ts
1 parent 656467b commit 12dba96

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

.github/libs/CONST.ts

-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)');
22

3-
// Needed for tests to have the necessary environment variables set
4-
if (!('GITHUB_REPOSITORY' in process.env)) {
5-
process.env.GITHUB_REPOSITORY_OWNER = 'Expensify';
6-
process.env.GITHUB_REPOSITORY = 'Expensify/App';
7-
}
8-
93
const GIT_CONST = {
104
GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER,
115
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

jest/setup.ts

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import 'setimmediate';
99
import mockFSLibrary from './setupMockFullstoryLib';
1010
import setupMockImages from './setupMockImages';
1111

12+
// Needed for tests to have the necessary environment variables set
13+
if (!('GITHUB_REPOSITORY' in process.env)) {
14+
process.env.GITHUB_REPOSITORY_OWNER = 'Expensify';
15+
process.env.GITHUB_REPOSITORY = 'Expensify/App';
16+
}
17+
1218
setupMockImages();
1319
mockFSLibrary();
1420

tests/unit/postTestBuildComment.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as core from '@actions/core';
22
import type {RestEndpointMethods} from '@octokit/plugin-rest-endpoint-methods/dist-types/generated/method-types';
33
import {when} from 'jest-when';
44
import ghAction from '@github/actions/javascript/postTestBuildComment/postTestBuildComment';
5+
import CONST from '@github/libs/CONST';
56
import type {CreateCommentResponse} from '@github/libs/GithubUtils';
67
import GithubUtils from '@github/libs/GithubUtils';
78
import asMutable from '@src/types/utils/asMutable';
@@ -31,8 +32,9 @@ Object.defineProperty(GithubUtils, 'graphql', {
3132
jest.mock('@actions/github', () => ({
3233
context: {
3334
repo: {
34-
owner: 'Expensify',
35-
repo: 'App',
35+
owner: process.env.GITHUB_REPOSITORY_OWNER,
36+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
37+
repo: process.env.GITHUB_REPOSITORY.split('/').at(1)!,
3638
},
3739
runId: 1234,
3840
},
@@ -116,7 +118,7 @@ describe('Post test build comments action tests', () => {
116118
}
117119
`);
118120
expect(createCommentMock).toBeCalledTimes(1);
119-
expect(createCommentMock).toBeCalledWith('App', 12, message);
121+
expect(createCommentMock).toBeCalledWith(CONST.APP_REPO, 12, message);
120122
});
121123

122124
test('Test GH action when input is not complete', async () => {
@@ -148,6 +150,6 @@ describe('Post test build comments action tests', () => {
148150
}
149151
`);
150152
expect(createCommentMock).toBeCalledTimes(1);
151-
expect(createCommentMock).toBeCalledWith('App', 12, onlyAndroidMessage);
153+
expect(createCommentMock).toBeCalledWith(CONST.APP_REPO, 12, onlyAndroidMessage);
152154
});
153155
});

0 commit comments

Comments
 (0)