Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add check_title_template to action inputs #546

Merged
merged 4 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
check_name: Example JUnit Test Report
report_paths: '**/surefire-reports/TEST-*.xml'
summary: '<table><thead><tr><th> Application (src/applications) </th></tr></thead><tbody><tr><td> test </td></tr></tbody></table>'
check_title_template: '{{SUITE_NAME}} | {{TEST_NAME}}'
- name: Test PyTest test import
uses: ./
if: endsWith(github.ref, 'main') == false
Expand Down Expand Up @@ -60,4 +61,3 @@ jobs:
prerelease: ${{ contains(github.ref, '-rc') || contains(github.ref, '-b') || contains(github.ref, '-a') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
| `fail_on_failure` | Optional. Fail the build in case of a test failure. |
| `require_tests` | Optional. Fail if no test are found.. |
| `check_retries` | Optional. If a testcase is retried, ignore the original failure. |
| `check_title_template` | Optional. Template to configure the title format. Placeholders: ${{FILE_NAME}}, ${{SUITE_NAME}}, ${{TEST_NAME}}. |
| `check_title_template` | Optional. Template to configure the title format. Placeholders: {{FILE_NAME}}, {{SUITE_NAME}}, {{TEST_NAME}}. |
| `summary` | Optional. Additional text to summary output |
| `update_check` | Optional. Uses an alternative API to update checks, use for cases with more than 50 annotations. |
| `annotate_only` | Optional. Will only annotate the results on the files, won't create a check run. |
Expand Down
2 changes: 1 addition & 1 deletion __tests__/testParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ action.surefire.report.email.InvalidEmailAddressException: Invalid email address
});

it('parse mocha test case, custom title template', async () => {
const { count, skipped, annotations } = await parseFile('test_results/mocha/mocha.xml', '*', true, false, ['/build/', '/__pycache__/'], '${{TEST_NAME}}');
const { count, skipped, annotations } = await parseFile('test_results/mocha/mocha.xml', '*', true, false, ['/build/', '/__pycache__/'], '{{TEST_NAME}}');

expect(count).toBe(1);
expect(skipped).toBe(0);
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ inputs:
description: 'Include passed tests in the report'
required: false
default: 'false'
check_title_template:
description: |-
Template to configure the title format. Placeholders: {{FILE_NAME}}, {{SUITE_NAME}}, {{TEST_NAME}}.
required: false
summary:
description: 'Additional text to summary output'
required: false
Expand Down
9 changes: 6 additions & 3 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions src/testParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ export async function parseFile(
)
}

function templateVar(varName: string): string {
return `{{${varName}}}`
}

async function parseSuite(
/* eslint-disable @typescript-eslint/no-explicit-any */
suite: any,
Expand Down Expand Up @@ -296,9 +300,9 @@ async function parseSuite(
const fileName =
pos.fileName !== testcase._attributes.name ? pos.fileName : ''
title = checkTitleTemplate
.replace('${{FILE_NAME}}', fileName)
.replace('${{SUITE_NAME}}', suiteName ?? '')
.replace('${{TEST_NAME}}', testcase._attributes.name)
.replace(templateVar('FILE_NAME'), fileName)
.replace(templateVar('SUITE_NAME'), suiteName ?? '')
.replace(templateVar('TEST_NAME'), testcase._attributes.name)
} else if (pos.fileName !== testcase._attributes.name) {
title = suiteName
? `${pos.fileName}.${suiteName}/${testcase._attributes.name}`
Expand Down