From e36474823fe40d0b41c9676bd7cc5d644621cbb5 Mon Sep 17 00:00:00 2001 From: Matthew Thomas Date: Fri, 1 Nov 2024 18:18:03 +0000 Subject: [PATCH 1/2] feat: use common duration --- src/views/ai.ts | 4 ++-- src/views/detailed.ts | 16 ++++++++++------ src/views/failed-folded.ts | 2 +- src/views/failed-rate.ts | 2 +- src/views/failed.ts | 4 ++-- src/views/flaky-rate.ts | 2 +- src/views/flaky.ts | 4 ++-- src/views/historical.ts | 10 +++++----- src/views/pull-request.ts | 14 +++++--------- src/views/skipped.ts | 4 ++-- src/views/suite-folded.ts | 28 ++++++++++++++-------------- src/views/summary.ts | 15 ++++++--------- 12 files changed, 51 insertions(+), 54 deletions(-) diff --git a/src/views/ai.ts b/src/views/ai.ts index 938d7c6b..20b56ecd 100644 --- a/src/views/ai.ts +++ b/src/views/ai.ts @@ -21,8 +21,8 @@ export function generateAIFailedTestsSummaryTable(tests: CtrfTest[], useSuiteNam ]), ]) .addLink( - 'Github Actions Test Reporter CTRF', - 'https://github.com/ctrf-io/github-actions-test-reporter-ctrf' + 'Github Test Reporter CTRF', + 'https://github.com/ctrf-io/github-test-reporter' ) } else { core.summary.addRaw('No failed tests ✨') diff --git a/src/views/detailed.ts b/src/views/detailed.ts index 999ab820..b0c63d17 100644 --- a/src/views/detailed.ts +++ b/src/views/detailed.ts @@ -1,6 +1,6 @@ import * as core from '@actions/core' import { CtrfTest } from "../../types/ctrf" -import { getTestName } from "../common" +import { formatDurationHumanReadable, getTestName } from "../common" import { getEmojiForStatus } from "./common" export function generateTestDetailsTable(tests: CtrfTest[], useSuiteName: boolean): void { @@ -17,7 +17,7 @@ export function generateTestDetailsTable(tests: CtrfTest[], useSuiteName: boolea const headers = [ { data: 'Name', header: true }, { data: 'Status', header: true }, - { data: 'ms', header: true }, + { data: 'Duration', header: true }, { data: 'Flaky', header: true }, ] @@ -27,7 +27,7 @@ export function generateTestDetailsTable(tests: CtrfTest[], useSuiteName: boolea data: `${test.status} ${getEmojiForStatus(test.status)}`, header: false, }, - { data: test.duration.toString(), header: false }, + { data: formatDurationHumanReadable(test.duration), header: false }, { data: test.flaky ? '🍂' : '', header: false }, ]) @@ -39,8 +39,8 @@ export function generateTestDetailsTable(tests: CtrfTest[], useSuiteName: boolea ) } core.summary.addLink( - 'Github Actions Test Reporter CTRF', - 'https://github.com/ctrf-io/github-actions-test-reporter-ctrf' + 'Github Test Reporter CTRF', + 'https://github.com/ctrf-io/github-test-reporter' ) } catch (error) { if (error instanceof Error) { @@ -49,4 +49,8 @@ export function generateTestDetailsTable(tests: CtrfTest[], useSuiteName: boolea core.setFailed('An unknown error occurred') } } - } \ No newline at end of file + } + +function durationHumanReadabletest(duration: number): any { + throw new Error('Function not implemented.') +} diff --git a/src/views/failed-folded.ts b/src/views/failed-folded.ts index 1ffbc693..e87dea1f 100644 --- a/src/views/failed-folded.ts +++ b/src/views/failed-folded.ts @@ -42,7 +42,7 @@ export function generateFailedFoldedTable(tests: CtrfTest[], useSuiteName: boole core.summary.addRaw(tableHtml) core.summary.addLink( - 'Github Test Reporter', + 'Github Test Reporter CTRF', 'https://github.com/ctrf-io/github-test-reporter' ) } else { diff --git a/src/views/failed-rate.ts b/src/views/failed-rate.ts index 8648a873..097d99d7 100644 --- a/src/views/failed-rate.ts +++ b/src/views/failed-rate.ts @@ -139,7 +139,7 @@ ${limitedSummaryRows.join('\n')} ${totalRunsMessage} -[Github Actions Test Reporter CTRF](https://github.com/ctrf-io/github-actions-test-reporter-ctrf) +[Github Test Reporter CTRF](https://github.com/ctrf-io/github-test-reporter) ` core.summary.addRaw(summaryTable) diff --git a/src/views/failed.ts b/src/views/failed.ts index f4f4bc87..cfe23e0c 100644 --- a/src/views/failed.ts +++ b/src/views/failed.ts @@ -34,8 +34,8 @@ export function generateFailedTestsDetailsTable(tests: CtrfTest[], useSuiteName: ` core.summary.addRaw(tableHtml) core.summary.addLink( - 'Github Actions Test Reporter CTRF', - 'https://github.com/ctrf-io/github-actions-test-reporter-ctrf' + 'Github Test Reporter CTRF', + 'https://github.com/ctrf-io/github-test-reporter' ) } else { core.summary.addRaw('

No failed tests ✨

') diff --git a/src/views/flaky-rate.ts b/src/views/flaky-rate.ts index 6c323a56..16c06d05 100644 --- a/src/views/flaky-rate.ts +++ b/src/views/flaky-rate.ts @@ -128,7 +128,7 @@ ${overallFlakeRateMessage} ${noFlakyMessage} -[Github Actions Test Reporter CTRF](https://github.com/ctrf-io/github-actions-test-reporter-ctrf) +[Github Test Reporter CTRF](https://github.com/ctrf-io/github-test-reporter) ` core.summary.addRaw(summary) return diff --git a/src/views/flaky.ts b/src/views/flaky.ts index a060fa81..0e2927f3 100644 --- a/src/views/flaky.ts +++ b/src/views/flaky.ts @@ -30,8 +30,8 @@ export function generateFlakyTestsDetailsTable(tests: CtrfTest[], useSuiteName: core.summary .addTable([headers, ...rows]) .addLink( - 'Github Actions Test Reporter CTRF', - 'https://github.com/ctrf-io/github-actions-test-reporter-ctrf' + 'Github Test Reporter CTRF', + 'https://github.com/ctrf-io/github-test-reporter' ) } else { core.summary.addRaw('No flaky tests detected. ✨') diff --git a/src/views/historical.ts b/src/views/historical.ts index 6ce07481..e08d3c96 100644 --- a/src/views/historical.ts +++ b/src/views/historical.ts @@ -1,6 +1,6 @@ import { type CtrfReport } from '../../types/ctrf' import * as core from '@actions/core' -import { extractGithubProperties } from '../common' +import { extractGithubProperties, formatDurationHumanReadable } from '../common' import { fetchArtifactsFromPreviousBuilds } from '../api/fetch-previous-runs' export async function generateHistoricSummary( @@ -45,12 +45,12 @@ export async function generateHistoricSummary( const summaryRows = workflowRun.map((run) => { const { results } = run const flakyCount = results.tests.filter((test) => test.flaky).length - const duration = results.summary.stop - results.summary.start - const durationFormatted = `${(duration / 1000).toFixed(2)} s` + const duration = report.results.summary.stop - report.results.summary.start + const durationHumanReadable = formatDurationHumanReadable(duration) const testResult = results.summary.failed > 0 ? 'Fail ❌' : 'Pass ✅' - return `| [#${run.runNumber}](${run.buildUrl}) | ${testResult} | ${results.summary.tests} | ${results.summary.passed} | ${results.summary.failed} | ${results.summary.skipped} | ${results.summary.pending} | ${results.summary.other} | ${flakyCount} | ${durationFormatted} |` + return `| [#${run.runNumber}](${run.buildUrl}) | ${testResult} | ${results.summary.tests} | ${results.summary.passed} | ${results.summary.failed} | ${results.summary.skipped} | ${results.summary.pending} | ${results.summary.other} | ${flakyCount} | ${durationHumanReadable} |` }) const limitedSummaryRows = summaryRows.slice(0, rows) @@ -60,7 +60,7 @@ export async function generateHistoricSummary( | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ${limitedSummaryRows.join('\n')} -[Github Actions Test Reporter CTRF](https://github.com/ctrf-io/github-actions-test-reporter-ctrf) +[Github Test Reporter CTRF](https://github.com/ctrf-io/github-test-reporter) ` core.summary.addHeading(`Previous Results`, 3) diff --git a/src/views/pull-request.ts b/src/views/pull-request.ts index d91d26f0..9365c7cf 100644 --- a/src/views/pull-request.ts +++ b/src/views/pull-request.ts @@ -1,5 +1,5 @@ import { CtrfReport } from "../../types/ctrf" -import { getTestName, stripAnsi } from "../common" +import { formatDurationHumanReadable, getTestName, stripAnsi } from "../common" import fs from 'fs' import https from 'https' @@ -9,12 +9,8 @@ export function generatePullRequestComment( title: string, useSuiteName: boolean ): string { - const durationInSeconds = - (report.results.summary.stop - report.results.summary.start) / 1000 - const durationFormatted = - durationInSeconds < 1 - ? '<1s' - : new Date(durationInSeconds * 1000).toISOString().substr(11, 8) + const duration = report.results.summary.stop - report.results.summary.start + const durationHumanReadable = formatDurationHumanReadable(duration) const runNumber = process.env.GITHUB_RUN_NUMBER @@ -67,12 +63,12 @@ export function generatePullRequestComment( | **Tests 📝** | **Passed ✅** | **Failed ❌** | **Skipped ⏭️** | **Pending ⏳** | **Other ❓** | **Flaky 🍂** | **Duration ⏱️** | | --- | --- | --- | --- | --- | --- | --- | --- | - | ${report.results.summary.tests} | ${report.results.summary.passed} | ${report.results.summary.failed} | ${report.results.summary.skipped} | ${report.results.summary.pending} | ${report.results.summary.other} | ${flakyCount} | ${durationFormatted} | + | ${report.results.summary.tests} | ${report.results.summary.passed} | ${report.results.summary.failed} | ${report.results.summary.skipped} | ${report.results.summary.pending} | ${report.results.summary.other} | ${flakyCount} | ${durationHumanReadable} | ### ${statusLine} ${failedTestsTable} - [Github Actions Test Reporter CTRF](https://github.com/ctrf-io/github-actions-test-reporter-ctrf) + [Github Test Reporter CTRF](https://github.com/ctrf-io/github-test-reporter) ` } diff --git a/src/views/skipped.ts b/src/views/skipped.ts index 983470df..56b75ae6 100644 --- a/src/views/skipped.ts +++ b/src/views/skipped.ts @@ -28,8 +28,8 @@ export function generateSkippedTestsDetailsTable(tests: CtrfTest[], useSuiteName core.summary .addTable([headers, ...rows]) .addLink( - 'Github Actions Test Reporter CTRF', - 'https://github.com/ctrf-io/github-actions-test-reporter-ctrf' + 'Github Test Reporter CTRF', + 'https://github.com/ctrf-io/github-test-reporter' ) } else { core.summary.addRaw('No skipped or pending tests detected. ✨') diff --git a/src/views/suite-folded.ts b/src/views/suite-folded.ts index f1869879..3aa69a53 100644 --- a/src/views/suite-folded.ts +++ b/src/views/suite-folded.ts @@ -5,15 +5,15 @@ import { formatDurationHumanReadable } from '../common' export function generateTestSuiteFoldedTable(tests: CtrfTest[], useSuite: boolean): void { try { core.summary.addHeading(`Test Suite Summary`, 3) - + const workspacePath = process.env.GITHUB_WORKSPACE || '' - + let totalPassed = 0 let totalFailed = 0 let totalSkippedPendingOther = { skipped: 0, pending: 0, other: 0 } const testResultsByGroup: Record = {} - + tests.forEach((test) => { const groupKey = useSuite ? test.suite || 'Unknown Suite' : (test.filePath || 'Unknown File').replace(workspacePath, '').replace(/^\//, '') @@ -28,7 +28,7 @@ export function generateTestSuiteFoldedTable(tests: CtrfTest[], useSuite: boolea totalPassed += 1 } else if (test.status === 'failed') { testResultsByGroup[groupKey].failed += 1 - testResultsByGroup[groupKey].statusEmoji = '❌' + testResultsByGroup[groupKey].statusEmoji = '❌' totalFailed += 1 } else if (test.status === 'skipped') { testResultsByGroup[groupKey].skippedPendingOtherEmoji = '⏭️' @@ -43,7 +43,7 @@ export function generateTestSuiteFoldedTable(tests: CtrfTest[], useSuite: boolea testResultsByGroup[groupKey].skippedPendingOtherCount += 1 totalSkippedPendingOther.other += 1 } - + testResultsByGroup[groupKey].duration += test.duration || 0 }) @@ -70,12 +70,12 @@ export function generateTestSuiteFoldedTable(tests: CtrfTest[], useSuite: boolea ${result.statusEmoji} ${groupKey}` result.tests.forEach((test) => { - const statusEmoji = + const statusEmoji = test.status === 'passed' ? '✅' : - test.status === 'failed' ? '❌' : - test.status === 'skipped' ? '⏭️' : - test.status === 'pending' ? '⏳' : '❓' - + test.status === 'failed' ? '❌' : + test.status === 'skipped' ? '⏭️' : + test.status === 'pending' ? '⏳' : '❓' + tableHtml += `
        ${statusEmoji} ${test.name || 'Unnamed Test'}
` }) @@ -96,10 +96,10 @@ export function generateTestSuiteFoldedTable(tests: CtrfTest[], useSuite: boolea core.summary.addRaw(tableHtml) core.summary - .addLink( - 'Github Test Reporter', - 'https://github.com/ctrf-io/github-test-reporter' - ) + .addLink( + 'Github Test Reporter CTRF', + 'https://github.com/ctrf-io/github-test-reporter' + ) } catch (error) { if (error instanceof Error) { core.setFailed(`Failed to display test suite summary: ${error.message}`) diff --git a/src/views/summary.ts b/src/views/summary.ts index d56a3f16..cf6c9c98 100644 --- a/src/views/summary.ts +++ b/src/views/summary.ts @@ -2,15 +2,12 @@ import * as core from '@actions/core' import { type CtrfReport, } from '../../types/ctrf' +import { formatDurationHumanReadable } from '../common' export function generateSummaryDetailsTable(report: CtrfReport): void { try { - const durationInSeconds = - (report.results.summary.stop - report.results.summary.start) / 1000 - const durationFormatted = - durationInSeconds < 1 - ? '<1s' - : `${new Date(durationInSeconds * 1000).toISOString().substr(11, 8)}` + const duration = report.results.summary.stop - report.results.summary.start + const durationHumanReadable = formatDurationHumanReadable(duration) const flakyCount = report.results.tests.filter((test) => test.flaky).length @@ -34,12 +31,12 @@ export function generateSummaryDetailsTable(report: CtrfReport): void { report.results.summary.pending.toString(), report.results.summary.other.toString(), flakyCount.toString(), - durationFormatted, + durationHumanReadable, ], ]) .addLink( - 'Github Actions Test Reporter CTRF', - 'https://github.com/ctrf-io/github-actions-test-reporter-ctrf' + 'Github Test Reporter CTRF', + 'https://github.com/ctrf-io/github-test-reporter' ) } catch (error) { if (error instanceof Error) { From d4b94ebb8262c70c63bfcbcbdbeec64e12cc6500 Mon Sep 17 00:00:00 2001 From: Matthew Thomas Date: Fri, 1 Nov 2024 18:21:18 +0000 Subject: [PATCH 2/2] chore: acknowledgement --- src/views/failed-rate.ts | 2 +- src/views/flaky-rate.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/failed-rate.ts b/src/views/failed-rate.ts index 097d99d7..4170bb3f 100644 --- a/src/views/failed-rate.ts +++ b/src/views/failed-rate.ts @@ -113,7 +113,7 @@ ${overallFailRateMessage} ${noFailMessage} -[Github Actions Test Reporter CTRF](https://github.com/ctrf-io/github-actions-test-reporter-ctrf) +[Github Test Reporter CTRF](https://github.com/ctrf-io/github-test-reporter) ` core.summary.addRaw(summary) return diff --git a/src/views/flaky-rate.ts b/src/views/flaky-rate.ts index 16c06d05..76b029aa 100644 --- a/src/views/flaky-rate.ts +++ b/src/views/flaky-rate.ts @@ -154,7 +154,7 @@ ${limitedSummaryRows.join('\n')} ${totalRunsMessage} -[Github Actions Test Reporter CTRF](https://github.com/ctrf-io/github-actions-test-reporter-ctrf) +[Github Test Reporter CTRF](https://github.com/ctrf-io/github-test-reporter-ctrf) ` core.summary.addRaw(summaryTable) }