Skip to content

Commit

Permalink
update tests and pack
Browse files Browse the repository at this point in the history
  • Loading branch information
neveenatik committed Jun 15, 2022
1 parent 0ff444b commit 6eceb90
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 3 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import runTasks from '../src/runTasks';
import {
NO_TOKEN_FAIL_MESSAGE,
DEFAULT_TEST_COMMAND,
DEFAULT_COMMENT_PREFIX,
} from '../src/tasks/gatherAllInputs';
import { JEST_ERROR_MESSAGE } from '../src/tasks/runJest';

Expand Down Expand Up @@ -103,7 +104,8 @@ describe('Main Tests', () => {

expect(postCommentMock).toHaveBeenCalledWith(
expect.objectContaining({ details: simpleExpectation }),
expect.stringMatching(GITHUB_TOKEN)
expect.stringMatching(GITHUB_TOKEN),
expect.stringMatching(DEFAULT_COMMENT_PREFIX)
);
expect(setFailedSpy).not.toHaveBeenCalled();
});
Expand Down
21 changes: 13 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,14 @@ const runTasks = (getInputParam, execSyncParam, postComment = postComment_1.defa
if (!inputs) {
return;
}
const { githubToken, testCommand, reporter } = inputs;
const { githubToken, testCommand, reporter, commentPrefix } = inputs;
core_1.info('Inputs have been gathered');
const formattedCoverage = runJest_1.default(testCommand, reporter, execSyncParam);
core_1.info('Jest has been ran and coverage collected');
if (!formattedCoverage) {
return;
}
yield postComment(formattedCoverage, githubToken);
yield postComment(formattedCoverage, githubToken, commentPrefix);
core_1.info('Comment has been posted to the PR');
}
catch (err) {
Expand Down Expand Up @@ -4474,12 +4474,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.COMMENT_PREFIX = void 0;
/* istanbul ignore file */
const core_1 = __webpack_require__(470);
const github_1 = __webpack_require__(469);
exports.COMMENT_PREFIX = '## Jest Coverage';
const postComment = (formattedCoverage, githubToken, getOctokitParam) => __awaiter(void 0, void 0, void 0, function* () {
const postComment = (formattedCoverage, githubToken, commentPrefix, getOctokitParam) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c, _d;
try {
const prNumber = (_a = github_1.context === null || github_1.context === void 0 ? void 0 : github_1.context.issue) === null || _a === void 0 ? void 0 : _a.number;
Expand All @@ -4497,8 +4495,8 @@ const postComment = (formattedCoverage, githubToken, getOctokitParam) => __await
repo,
owner,
});
const existingComment = (_d = prComments === null || prComments === void 0 ? void 0 : prComments.data) === null || _d === void 0 ? void 0 : _d.find((comment) => { var _a; return (_a = comment === null || comment === void 0 ? void 0 : comment.body) === null || _a === void 0 ? void 0 : _a.startsWith(exports.COMMENT_PREFIX); });
const commentBody = `${exports.COMMENT_PREFIX}
const existingComment = (_d = prComments === null || prComments === void 0 ? void 0 : prComments.data) === null || _d === void 0 ? void 0 : _d.find((comment) => { var _a; return (_a = comment === null || comment === void 0 ? void 0 : comment.body) === null || _a === void 0 ? void 0 : _a.startsWith(commentPrefix); });
const commentBody = `${commentPrefix}
${(formattedCoverage === null || formattedCoverage === void 0 ? void 0 : formattedCoverage.summary) ? formattedCoverage.summary : ''}
Expand Down Expand Up @@ -6091,11 +6089,12 @@ function removeHook(state, name, method) {
"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.POSSIBLE_REPORTERS = exports.DEFAULT_REPORTER = exports.DEFAULT_TEST_COMMAND = exports.NO_TOKEN_FAIL_MESSAGE = void 0;
exports.POSSIBLE_REPORTERS = exports.DEFAULT_COMMENT_PREFIX = exports.DEFAULT_REPORTER = exports.DEFAULT_TEST_COMMAND = exports.NO_TOKEN_FAIL_MESSAGE = void 0;
const core_1 = __webpack_require__(470);
exports.NO_TOKEN_FAIL_MESSAGE = 'No github token provided (input: github_token)';
exports.DEFAULT_TEST_COMMAND = 'npx jest --coverage';
exports.DEFAULT_REPORTER = 'text';
exports.DEFAULT_COMMENT_PREFIX = '## Jest Coverage';
exports.POSSIBLE_REPORTERS = ['text', 'text-summary'];
const gatherAllInputs = (getInputParam) => {
try {
Expand All @@ -6107,6 +6106,11 @@ const gatherAllInputs = (getInputParam) => {
}
const testCommand = determineValue([getInput('test_command')], exports.DEFAULT_TEST_COMMAND);
core_1.debug(`Input - test_command: ${testCommand}`);
const commentPrefix = determineValue([
getInput('comment_prefix'),
exports.DEFAULT_COMMENT_PREFIX,
]);
core_1.debug(`Input - comment_prefix: ${commentPrefix}`);
const reporter = determineValue([getInput('reporter')], exports.DEFAULT_REPORTER);
core_1.debug(`Input - reporter: ${reporter}`);
if (!exports.POSSIBLE_REPORTERS.includes(reporter)) {
Expand All @@ -6116,6 +6120,7 @@ const gatherAllInputs = (getInputParam) => {
githubToken,
testCommand,
reporter,
commentPrefix,
};
}
catch (err) {
Expand Down

0 comments on commit 6eceb90

Please sign in to comment.