-
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 #47 from ctrf-io/feat/suite-list
Feat/suite list
- Loading branch information
Showing
7 changed files
with
142 additions
and
6 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,75 @@ | ||
import * as core from '@actions/core' | ||
import { CtrfTest } from '../../types/ctrf' | ||
|
||
export function generateSuiteListView(tests: CtrfTest[], useSuite: boolean): void { | ||
try { | ||
let markdown = `\n` | ||
|
||
const workspacePath = process.env.GITHUB_WORKSPACE || '' | ||
|
||
const testResultsByGroup: Record<string, { tests: CtrfTest[], statusEmoji: string }> = {} | ||
|
||
tests.forEach((test) => { | ||
const groupKey = useSuite | ||
? test.suite || 'Unknown Suite' | ||
: (test.filePath || 'Unknown File').replace(workspacePath, '').replace(/^\//, '') | ||
|
||
if (!testResultsByGroup[groupKey]) { | ||
testResultsByGroup[groupKey] = { tests: [], statusEmoji: '✅' } | ||
} | ||
|
||
testResultsByGroup[groupKey].tests.push(test) | ||
|
||
if (test.status === 'failed') { | ||
testResultsByGroup[groupKey].statusEmoji = '❌' | ||
} | ||
}) | ||
|
||
function escapeMarkdown(text: string): string { | ||
return text.replace(/([\\*_{}[\]()#+\-.!])/g, '\\$1') | ||
} | ||
|
||
Object.entries(testResultsByGroup).forEach(([groupKey, groupData]) => { | ||
markdown += `## ${groupData.statusEmoji} ${escapeMarkdown(groupKey)}\n\n` | ||
|
||
groupData.tests.forEach((test) => { | ||
const statusEmoji = | ||
test.status === 'passed' ? '✅' : | ||
test.status === 'failed' ? '❌' : | ||
test.status === 'skipped' ? '⏭️' : | ||
test.status === 'pending' ? '⏳' : '❓' | ||
|
||
const testName = escapeMarkdown(test.name || 'Unnamed Test') | ||
|
||
markdown += ` **${statusEmoji} ${testName}**\n` | ||
|
||
if (test.status === 'failed' && test.message) { | ||
const message = test.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` | ||
}) | ||
|
||
markdown += `[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 suite list: ${error.message}`) | ||
} else { | ||
core.setFailed('An unknown error occurred') | ||
} | ||
} | ||
} |