Skip to content

Commit

Permalink
feat: add failed with folded details
Browse files Browse the repository at this point in the history
  • Loading branch information
Ma11hewThomas committed Oct 29, 2024
1 parent a849bb8 commit 469498f
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/failed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
run: node dist/index.js failed ctrf-reports/ctrf-report.json --title "Failed With Title"
- name: Test failed no title
run: node dist/index.js failed ctrf-reports/ctrf-report.json
- name: Test failed folded
run: node dist/index.js failed-folded ctrf-reports/ctrf-report.json --title "Failed Folded"
- name: Test failed rate
run: node dist/index.js failed-rate ctrf-reports/ctrf-report.json --title "Failed Rate"
env:
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ For a failed test details table, add the `failed` command to your workflow yaml:
if: always()
```

### Generating Failed Folded Test Details Table

For a failed test table with details folded, add the `failed-folded` command to your workflow yaml:

```yaml
- name: Publish CTRF Failed Test Summary Results
run: npx github-actions-ctrf failed-folded path-to-your-ctrf-report.json
if: always()
```

### Generating Failed Rate Test Details Table

To see the failed test rate over time, add the `failed-rate` command to your workflow yaml:
Expand Down Expand Up @@ -490,9 +500,13 @@ npm run report

![Failed](images/failed.png)

### Failed Folded details

![Failed Folded](images/failed-folded.png)

### Failed rate

![Failed](images/failed-rate.png)
![Failed Rate](images/failed-rate.png)

### AI summary

Expand Down
Binary file added images/failed-folded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 36 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { generateTestDetailsTable } from './views/detailed'
import { generateFailedTestsDetailsTable } from './views/failed'
import { generateFlakyTestsDetailsTable } from './views/flaky'
import { generateSkippedTestsDetailsTable } from './views/skipped'
import { generateFailedFoldedTable } from './views/failed-folded'

interface Arguments {
_: Array<string | number>
Expand Down Expand Up @@ -81,6 +82,16 @@ const argv: Arguments = yargs(hideBin(process.argv))
})
}
)
.command(
'failed-folded <file>',
'Generate fail folded test report from a CTRF report',
(yargs) => {
return yargs.positional('file', {
describe: 'Path to the CTRF file',
type: 'string',
})
}
)
.command(
'failed-rate <file>',
'Generate a fail rate statistics test report from a CTRF report',
Expand Down Expand Up @@ -371,7 +382,31 @@ if ((commandUsed === 'all' || commandUsed === '') && argv.file) {
} catch (error) {
console.error('Failed to read file:', error)
}
} else if (argv._.includes('failed-rate') && argv.file) {
} else if (argv._.includes('failed-folded') && argv.file) {
try {
let report = validateCtrfFile(argv.file)
report = stripAnsiFromErrors(report)
if (report !== null) {
if (argv.title) {
addHeading(title)
}
generateFailedFoldedTable(report.results.tests, useSuiteName)
write()
if (argv.prComment) {
postPullRequestComment(report, apiUrl, baseUrl, onFailOnly, title, useSuiteName, prCommentMessage)
}
if (pullRequest) {
postPullRequestComment(report, apiUrl, baseUrl, onFailOnly, title, useSuiteName, core.summary.stringify())
}
if (exitOnFail) {
exitActionOnFail(report)
}
}
} catch (error) {
console.error('Failed to read file:', error)
}
}
else if (argv._.includes('failed-rate') && argv.file) {
try {
let report = validateCtrfFile(argv.file)
report = stripAnsiFromErrors(report)
Expand Down
58 changes: 58 additions & 0 deletions src/views/failed-folded.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as core from '@actions/core'
import { getTestName } from "../common"
import Convert from 'ansi-to-html'
import { CtrfTest } from '../../types/ctrf'

export function generateFailedFoldedTable(tests: CtrfTest[], useSuiteName: boolean): void {
try {
core.summary.addHeading(`Failed Tests`, 3)
const convert = new Convert()

const failedTests = tests.filter((test) => test.status === 'failed')

if (failedTests.length > 0) {
let tableHtml = `
<table>
<thead>
<tr>
<th>Failed Tests</th>
</tr>
</thead>
<tbody>`
failedTests.forEach((test) => {
const testName = getTestName(test, useSuiteName)
const messageHtml = convert.toHtml(test.message || 'No message available')
const traceHtml = convert.toHtml(test.trace || 'No trace available')

tableHtml += `
<tr>
<td>
<details>
<summary>❌ ${testName}</summary>
<p><strong>Message:</strong></p>
<pre><code>${messageHtml}</code></pre>
<p><strong>Trace:</strong></p>
<pre><code>${traceHtml}</code></pre>
</details>
</td>
</tr>`
})
tableHtml += `</tbody>
</table>`

core.summary.addRaw(tableHtml)
core.summary.addLink(
'Github Test Reporter',
'https://github.com/ctrf-io/github-test-reporter'
)
} else {
core.summary.addRaw('<p>No failed tests ✨</p>')
}
} catch (error) {
if (error instanceof Error) {
core.setFailed(`Failed to display failed test details: ${error.message}`)
} else {
core.setFailed('An unknown error occurred')
}
}
}

0 comments on commit 469498f

Please sign in to comment.