Skip to content

Commit

Permalink
Merge pull request #47 from ctrf-io/feat/suite-list
Browse files Browse the repository at this point in the history
Feat/suite list
  • Loading branch information
Ma11hewThomas authored Nov 5, 2024
2 parents 31a5f41 + 41378c6 commit f983d78
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ jobs:
run: node dist/index.js suite-folded ctrf-reports/ctrf-report.json --title "Suite folded" --useSuite --pull-request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test suite list
run: node dist/index.js suite-list ctrf-reports/ctrf-report.json --title "Suite list" --useSuite
- name: Test suite list no fails and filepath
run: node dist/index.js suite-list ctrf-reports/ctrf-report.json --title "Suite list"
- name: Test suite list no fails and suite
run: node dist/index.js suite-list ctrf-reports/ctrf-report.json --title "Suite list useSuite" --useSuite
- name: Upload test results
uses: actions/upload-artifact@v4
with:
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Thank you! Your support is invaluable to us! 💙

| ![all](images/all.png) | ![historical](images/historical.png) | ![flaky-rate](images/flaky-rate.png) | ![ai](images/ai.png) | ![pr](images/pr.png) |
|:--:|:--:|:--:|:--:|:--:|
| ![suite-folded](images/suite-folded.png) | ![failed-folded](images/failed-folded.png) | ![custom](images/custom.png) | ![failed](images/failed.png) | ![annotations](images/annotations.png) |
| ![suite-folded](images/suite-folded.png) | ![failed-folded](images/failed-folded.png) | ![custom](images/custom.png) | ![failed](images/failed.png) | ![suite-list](images/suite-list.png) |

## Usage

Expand Down Expand Up @@ -185,7 +185,7 @@ To see which tests were skipped or pending, add the `skipped` command to your wo

### Generating Suite Folded Table

To see which tests grouped by suite with tests folkded, add the `suite-folded` command to your workflow yaml:
To see which tests grouped by suite with tests folded, add the `suite-folded` command to your workflow yaml:

```yaml
- name: Publish CTRF Suite Folded Summary
Expand All @@ -195,6 +195,18 @@ To see which tests grouped by suite with tests folkded, add the `suite-folded` c

Groups by filePath by default, add argument `--useSuite` to use suite property

### Generating Suite List

To see which tests grouped by suite with tests listed, add the `suite-list` command to your workflow yaml:

```yaml
- name: Publish CTRF Suite Folded Summary
run: npx github-actions-ctrf suite-list path-to-your-ctrf-report.json
if: always()
```

Groups by filePath by default, add argument `--useSuite` to use suite property

### Generating Previous Tests Table

To see results from previous tests, add the `historical` command to your workflow yaml:
Expand Down Expand Up @@ -542,6 +554,10 @@ npm run report

![Suite folded](images/suite-folded.png)

### Suite list

![Suite folded](images/suite-list.png)

### Historical

![Historical](images/historical.png)
Expand Down
Binary file added images/suite-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "github-actions-ctrf",
"version": "0.0.47",
"version": "0.0.48",
"description": "View test results directly within your GitHub workflow summary and Pull Requests",
"main": "index.js",
"scripts": {
Expand Down
41 changes: 40 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { generateFlakyTestsDetailsTable } from './views/flaky'
import { generateSkippedTestsDetailsTable } from './views/skipped'
import { generateFailedFoldedTable } from './views/failed-folded'
import { generateTestSuiteFoldedTable } from './views/suite-folded'
import { generateSuiteListView } from './views/suite-list'

interface Arguments {
_: Array<string | number>
Expand Down Expand Up @@ -168,6 +169,20 @@ const argv: Arguments = yargs(hideBin(process.argv))
})
}
)
.command(
'suite-list <file>',
'Generate a test summary grouped by suite',
(yargs) => {
return yargs.positional('file', {
describe: 'Path to the CTRF file',
type: 'string',
})
.option('useSuite', {
type: 'boolean',
description: 'Use suite property, default is filePath',
})
}
)
.command(
'custom <file> <summary>',
'Generate a custom summary from a CTRF report',
Expand Down Expand Up @@ -562,7 +577,31 @@ if ((commandUsed === 'all' || commandUsed === '') && argv.file) {
} catch (error) {
console.error('Failed to read file:', error)
}
} else if (argv._.includes('custom') && argv.file) {
} else if (argv._.includes('suite-list') && argv.file) {
try {
let report = validateCtrfFile(argv.file)
report = stripAnsiFromErrors(report)
if (report !== null) {
if (argv.title) {
addHeading(title)
}
generateSuiteListView(report.results.tests, useSuite)
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('custom') && argv.file) {
try {
if (argv.summary) {
if (path.extname(argv.summary) === '.hbs') {
Expand Down
75 changes: 75 additions & 0 deletions src/views/suite-list.ts
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 += `&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;**${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 => `&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${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')
}
}
}

0 comments on commit f983d78

Please sign in to comment.