-
Notifications
You must be signed in to change notification settings - Fork 9
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 #48 from ctrf-io/feat/test-list
Feat/test list
- Loading branch information
Showing
9 changed files
with
110 additions
and
15 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
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,48 @@ | ||
import * as core from '@actions/core' | ||
import { CtrfTest } from '../../types/ctrf' | ||
import { getTestName, stripAnsi } from '../common' | ||
import { getEmojiForStatus } from './common' | ||
|
||
export function generateTestListView(tests: CtrfTest[], useSuiteName: boolean): void { | ||
try { | ||
let markdown = `\n` | ||
|
||
function escapeMarkdown(text: string): string { | ||
return text.replace(/([\\*_{}[\]()#+\-.!])/g, '\\$1') | ||
} | ||
|
||
tests.forEach((test) => { | ||
const statusEmoji = getEmojiForStatus(test.status) | ||
|
||
const testName = escapeMarkdown(getTestName(test, useSuiteName)) | ||
|
||
markdown += `**${statusEmoji} ${testName}**\n` | ||
|
||
if (test.status === 'failed') { | ||
let message = stripAnsi(test.message || "No failure message") | ||
message = message.replace(/\n{2,}/g, '\n').trim() | ||
|
||
const escapedMessage = escapeMarkdown(message) | ||
|
||
const indentedMessage = escapedMessage | ||
.split('\n') | ||
.filter(line => line.trim() !== '') | ||
.map(line => ` ${line}`) | ||
.join('\n') | ||
|
||
markdown += `${indentedMessage}\n` | ||
} | ||
}) | ||
|
||
markdown += `\n[Github Test Reporter](https://github.com/ctrf-io/github-test-reporter)` | ||
|
||
core.summary.addRaw(markdown) | ||
|
||
} catch (error) { | ||
if (error instanceof Error) { | ||
core.setFailed(`Failed to display test list: ${error.message}`) | ||
} else { | ||
core.setFailed('An unknown error occurred') | ||
} | ||
} | ||
} |