Skip to content

Commit

Permalink
truncate output text
Browse files Browse the repository at this point in the history
  • Loading branch information
willcaul committed Sep 10, 2021
1 parent 1a6e899 commit 4a17bd6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-github-action",
"version": "1.0.0",
"version": "1.0.1",
"description": "Jest action adding checks to your pull requests",
"main": "lib/run.js",
"scripts": {
Expand Down
17 changes: 14 additions & 3 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { getOctokit, context } from "@actions/github"
import type { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods"
import flatMap from "lodash/flatMap"
import filter from "lodash/filter"
import map from "lodash/map"
import strip from "strip-ansi"
import { createCoverageMap, CoverageMapData, CoverageSummary } from "istanbul-lib-coverage"
import type { FormattedTestResults } from "@jest/test-result/build/types"

const ACTION_NAME = "jest-github-action"
const COVERAGE_HEADER = "# :open_umbrella: Code Coverage";
const CHAR_LIMIT = 60000;

const rootPath = process.cwd();

Expand Down Expand Up @@ -66,7 +66,7 @@ export async function run() {
}
} catch (error) {
console.error(error)
core.setFailed(error.message)
core.setFailed(error instanceof Error ? error.message : String(error))
}
}

Expand Down Expand Up @@ -153,6 +153,17 @@ function truncateLeft(str: string, len: number): string
return `...${subStr}`;
}

function truncateRight(str: string, len: number): string
{
if(len > str.length) {
return str;
}

const subStr = str.substring(0, len);

return `${subStr}...`;
}

export function getCoverageTable(
results: FormattedTestResults,
cwd: string,
Expand Down Expand Up @@ -221,7 +232,7 @@ function getCheckPayload(results: FormattedTestResults, cwd: string, {out, err}:
conclusion: results.success ? "success" : "failure",
output: {
title: results.success ? "Jest tests passed" : "Jest tests failed",
text: `${out ? out : ''}${err ? `\n\n${err}` : ''}`,
text: truncateRight(`${out ? out : ''}${err ? `\n\n${err}` : ''}`, CHAR_LIMIT),
summary: results.success
? `${results.numPassedTests} tests passing in ${
results.numPassedTestSuites
Expand Down

0 comments on commit 4a17bd6

Please sign in to comment.