-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from ctrf-io/feat/failed-folded
feat: add failed with folded details
- Loading branch information
Showing
7 changed files
with
114 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
} | ||
} | ||
} |