Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/common time #45

Merged
merged 2 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/views/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ✨')
Expand Down
16 changes: 10 additions & 6 deletions src/views/detailed.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 },
]

Expand All @@ -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 },
])

Expand All @@ -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) {
Expand All @@ -49,4 +49,8 @@ export function generateTestDetailsTable(tests: CtrfTest[], useSuiteName: boolea
core.setFailed('An unknown error occurred')
}
}
}
}

function durationHumanReadabletest(duration: number): any {
throw new Error('Function not implemented.')
}
2 changes: 1 addition & 1 deletion src/views/failed-folded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/views/failed-rate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/views/failed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export function generateFailedTestsDetailsTable(tests: CtrfTest[], useSuiteName:
</table>`
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('<p>No failed tests ✨</p>')
Expand Down
4 changes: 2 additions & 2 deletions src/views/flaky-rate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions src/views/flaky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. ✨')
Expand Down
10 changes: 5 additions & 5 deletions src/views/historical.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down
14 changes: 5 additions & 9 deletions src/views/pull-request.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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

Expand Down Expand Up @@ -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)
`
}

Expand Down
4 changes: 2 additions & 2 deletions src/views/skipped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. ✨')
Expand Down
28 changes: 14 additions & 14 deletions src/views/suite-folded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, { passed: number, failed: number, skippedPendingOtherCount: number, skippedPendingOtherEmoji: string, duration: number, tests: CtrfTest[], statusEmoji: string }> = {}

tests.forEach((test) => {
const groupKey = useSuite ? test.suite || 'Unknown Suite' : (test.filePath || 'Unknown File').replace(workspacePath, '').replace(/^\//, '')

Expand All @@ -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 = '⏭️'
Expand All @@ -43,7 +43,7 @@ export function generateTestSuiteFoldedTable(tests: CtrfTest[], useSuite: boolea
testResultsByGroup[groupKey].skippedPendingOtherCount += 1
totalSkippedPendingOther.other += 1
}

testResultsByGroup[groupKey].duration += test.duration || 0
})

Expand All @@ -70,12 +70,12 @@ export function generateTestSuiteFoldedTable(tests: CtrfTest[], useSuite: boolea
<summary>${result.statusEmoji} ${groupKey}</summary>`

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 += `<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${statusEmoji} ${test.name || 'Unnamed Test'}</div>`
})

Expand All @@ -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}`)
Expand Down
15 changes: 6 additions & 9 deletions src/views/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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) {
Expand Down