UNPKG

@estruyf/github-actions-reporter

Version:
78 lines (77 loc) 4 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { summary } from "@actions/core"; import { existsSync, unlinkSync, writeFileSync } from "fs"; import { basename, join } from "path"; import { getHtmlTable } from "./getHtmlTable.js"; import { getSuiteStatusIcon } from "./getSuiteStatusIcon.js"; import { getTableRows } from "./getTableRows.js"; import { getSummaryTitle } from "./getSummaryTitle.js"; import { getSummaryDetails } from "./getSummaryDetails.js"; import { getTestsPerFile } from "./getTestsPerFile.js"; import { getTestHeading } from "./getTestHeading.js"; const SUMMARY_ENV_VAR = "GITHUB_STEP_SUMMARY"; export const processResults = (suite, options) => __awaiter(void 0, void 0, void 0, function* () { if (process.env.NODE_ENV === "development") { const summaryFile = join(__dirname, "../../summary.html"); if (existsSync(summaryFile)) { unlinkSync(summaryFile); } writeFileSync(summaryFile, "", "utf-8"); process.env[SUMMARY_ENV_VAR] = summaryFile; process.env.GITHUB_ACTIONS = "true"; } if (process.env.GITHUB_ACTIONS && suite) { const os = process.platform; let blobService = undefined; if (options.azureStorageSAS && options.azureStorageUrl) { blobService = {}; blobService.azure = {}; blobService.azure.azureStorageSAS = options.azureStorageSAS; blobService.azure.azureStorageUrl = options.azureStorageUrl; } if (options.showArtifactsLink) { summary.addLink("Go to artifacts", "#artifacts"); } const summaryTitle = getSummaryTitle(options.title); if (summaryTitle) { summary.addHeading(summaryTitle, 1); } const headerText = getSummaryDetails(suite); summary.addRaw(headerText.join(` - `)); if (options.useDetails) { summary.addSeparator(); } for (const crntSuite of suite === null || suite === void 0 ? void 0 : suite.suites) { const project = crntSuite.project(); const tests = getTestsPerFile(crntSuite); for (const filePath of Object.keys(tests)) { const fileName = basename(filePath); if (options.useDetails) { const content = yield getHtmlTable(tests[filePath], options.showAnnotations, options.showTags, !!options.showError, options.includeResults, options.showAnnotationsInColumn, blobService); if (!content) { continue; } // Check if there are any failed tests const testStatusIcon = getSuiteStatusIcon(tests[filePath]); summary.addDetails(`${testStatusIcon} ${getTestHeading(fileName, os, project)}`, content); } else { const tableRows = yield getTableRows(tests[filePath], options.showAnnotations, options.showTags, !!options.showError, options.includeResults, options.showAnnotationsInColumn, blobService); if (tableRows.length !== 0) { summary.addHeading(getTestHeading(fileName, os, project), 2); summary.addTable(tableRows); } } } } yield summary.write(); } });