mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 22:07:09 +01:00
Add badge title customization
This commit is contained in:
parent
83b7f42d2d
commit
49667db475
5 changed files with 26 additions and 17 deletions
|
|
@ -67,6 +67,10 @@ inputs:
|
||||||
Detailed listing of test suites and test cases will be skipped.
|
Detailed listing of test suites and test cases will be skipped.
|
||||||
default: 'false'
|
default: 'false'
|
||||||
required: false
|
required: false
|
||||||
|
badge-title:
|
||||||
|
description: Customize badge title
|
||||||
|
required: false
|
||||||
|
default: 'tests'
|
||||||
token:
|
token:
|
||||||
description: GitHub Access Token
|
description: GitHub Access Token
|
||||||
required: false
|
required: false
|
||||||
|
|
|
||||||
18
dist/index.js
generated
vendored
18
dist/index.js
generated
vendored
|
|
@ -294,6 +294,7 @@ class TestReporter {
|
||||||
this.failOnError = core.getInput('fail-on-error', { required: true }) === 'true';
|
this.failOnError = core.getInput('fail-on-error', { required: true }) === 'true';
|
||||||
this.workDirInput = core.getInput('working-directory', { required: false });
|
this.workDirInput = core.getInput('working-directory', { required: false });
|
||||||
this.onlySummary = core.getInput('only-summary', { required: false }) === 'true';
|
this.onlySummary = core.getInput('only-summary', { required: false }) === 'true';
|
||||||
|
this.badgeTitle = core.getInput('badge-title', { required: false });
|
||||||
this.token = core.getInput('token', { required: true });
|
this.token = core.getInput('token', { required: true });
|
||||||
this.context = (0, github_utils_1.getCheckRunContext)();
|
this.context = (0, github_utils_1.getCheckRunContext)();
|
||||||
this.octokit = github.getOctokit(this.token);
|
this.octokit = github.getOctokit(this.token);
|
||||||
|
|
@ -392,9 +393,9 @@ class TestReporter {
|
||||||
// ...github.context.repo
|
// ...github.context.repo
|
||||||
// })
|
// })
|
||||||
core.info('Creating report summary');
|
core.info('Creating report summary');
|
||||||
const { listSuites, listTests, onlySummary } = this;
|
const { listSuites, listTests, onlySummary, badgeTitle } = this;
|
||||||
const baseUrl = '';
|
const baseUrl = '';
|
||||||
const summary = (0, get_report_1.getReport)(results, { listSuites, listTests, baseUrl, onlySummary });
|
const summary = (0, get_report_1.getReport)(results, { listSuites, listTests, baseUrl, onlySummary, badgeTitle });
|
||||||
core.info('Summary content:');
|
core.info('Summary content:');
|
||||||
core.info(summary);
|
core.info(summary);
|
||||||
yield fs.promises.writeFile(this.path.replace('*.trx', 'test-summary.md'), summary);
|
yield fs.promises.writeFile(this.path.replace('*.trx', 'test-summary.md'), summary);
|
||||||
|
|
@ -1402,7 +1403,8 @@ const defaultOptions = {
|
||||||
listSuites: 'all',
|
listSuites: 'all',
|
||||||
listTests: 'all',
|
listTests: 'all',
|
||||||
baseUrl: '',
|
baseUrl: '',
|
||||||
onlySummary: false
|
onlySummary: false,
|
||||||
|
badgeTitle: 'tests'
|
||||||
};
|
};
|
||||||
function getReport(results, options = defaultOptions) {
|
function getReport(results, options = defaultOptions) {
|
||||||
core.info('Generating check run summary');
|
core.info('Generating check run summary');
|
||||||
|
|
@ -1463,19 +1465,19 @@ function getByteLength(text) {
|
||||||
}
|
}
|
||||||
function renderReport(results, options) {
|
function renderReport(results, options) {
|
||||||
const sections = [];
|
const sections = [];
|
||||||
const badge = getReportBadge(results);
|
const badge = getReportBadge(results, options);
|
||||||
sections.push(badge);
|
sections.push(badge);
|
||||||
const runs = getTestRunsReport(results, options);
|
const runs = getTestRunsReport(results, options);
|
||||||
sections.push(...runs);
|
sections.push(...runs);
|
||||||
return sections;
|
return sections;
|
||||||
}
|
}
|
||||||
function getReportBadge(results) {
|
function getReportBadge(results, options) {
|
||||||
const passed = results.reduce((sum, tr) => sum + tr.passed, 0);
|
const passed = results.reduce((sum, tr) => sum + tr.passed, 0);
|
||||||
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0);
|
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0);
|
||||||
const failed = results.reduce((sum, tr) => sum + tr.failed, 0);
|
const failed = results.reduce((sum, tr) => sum + tr.failed, 0);
|
||||||
return getBadge(passed, failed, skipped);
|
return getBadge(passed, failed, skipped, options);
|
||||||
}
|
}
|
||||||
function getBadge(passed, failed, skipped) {
|
function getBadge(passed, failed, skipped, options) {
|
||||||
const text = [];
|
const text = [];
|
||||||
if (passed > 0) {
|
if (passed > 0) {
|
||||||
text.push(`${passed} passed`);
|
text.push(`${passed} passed`);
|
||||||
|
|
@ -1495,7 +1497,7 @@ function getBadge(passed, failed, skipped) {
|
||||||
color = 'yellow';
|
color = 'yellow';
|
||||||
}
|
}
|
||||||
const hint = failed > 0 ? 'Tests failed' : 'Tests passed successfully';
|
const hint = failed > 0 ? 'Tests failed' : 'Tests passed successfully';
|
||||||
const uri = encodeURIComponent(`tests-${message}-${color}`);
|
const uri = encodeURIComponent(`${options.badgeTitle}-${message}-${color}`);
|
||||||
return ``;
|
return ``;
|
||||||
}
|
}
|
||||||
function getTestRunsReport(testRuns, options) {
|
function getTestRunsReport(testRuns, options) {
|
||||||
|
|
|
||||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
|
|
@ -41,6 +41,7 @@ class TestReporter {
|
||||||
readonly failOnError = core.getInput('fail-on-error', {required: true}) === 'true'
|
readonly failOnError = core.getInput('fail-on-error', {required: true}) === 'true'
|
||||||
readonly workDirInput = core.getInput('working-directory', {required: false})
|
readonly workDirInput = core.getInput('working-directory', {required: false})
|
||||||
readonly onlySummary = core.getInput('only-summary', {required: false}) === 'true'
|
readonly onlySummary = core.getInput('only-summary', {required: false}) === 'true'
|
||||||
|
readonly badgeTitle = core.getInput('badge-title', {required: false})
|
||||||
readonly token = core.getInput('token', {required: true})
|
readonly token = core.getInput('token', {required: true})
|
||||||
readonly octokit: InstanceType<typeof GitHub>
|
readonly octokit: InstanceType<typeof GitHub>
|
||||||
readonly context = getCheckRunContext()
|
readonly context = getCheckRunContext()
|
||||||
|
|
@ -166,9 +167,9 @@ class TestReporter {
|
||||||
// })
|
// })
|
||||||
|
|
||||||
core.info('Creating report summary')
|
core.info('Creating report summary')
|
||||||
const {listSuites, listTests, onlySummary} = this
|
const {listSuites, listTests, onlySummary, badgeTitle} = this
|
||||||
const baseUrl = ''
|
const baseUrl = ''
|
||||||
const summary = getReport(results, {listSuites, listTests, baseUrl, onlySummary})
|
const summary = getReport(results, {listSuites, listTests, baseUrl, onlySummary, badgeTitle})
|
||||||
core.info('Summary content:')
|
core.info('Summary content:')
|
||||||
core.info(summary)
|
core.info(summary)
|
||||||
await fs.promises.writeFile(this.path.replace('*.trx', 'test-summary.md'), summary)
|
await fs.promises.writeFile(this.path.replace('*.trx', 'test-summary.md'), summary)
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,15 @@ export interface ReportOptions {
|
||||||
listTests: 'all' | 'failed' | 'none'
|
listTests: 'all' | 'failed' | 'none'
|
||||||
baseUrl: string
|
baseUrl: string
|
||||||
onlySummary: boolean
|
onlySummary: boolean
|
||||||
|
badgeTitle: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultOptions: ReportOptions = {
|
const defaultOptions: ReportOptions = {
|
||||||
listSuites: 'all',
|
listSuites: 'all',
|
||||||
listTests: 'all',
|
listTests: 'all',
|
||||||
baseUrl: '',
|
baseUrl: '',
|
||||||
onlySummary: false
|
onlySummary: false,
|
||||||
|
badgeTitle: 'tests'
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getReport(results: TestRunResult[], options: ReportOptions = defaultOptions): string {
|
export function getReport(results: TestRunResult[], options: ReportOptions = defaultOptions): string {
|
||||||
|
|
@ -92,7 +94,7 @@ function getByteLength(text: string): number {
|
||||||
|
|
||||||
function renderReport(results: TestRunResult[], options: ReportOptions): string[] {
|
function renderReport(results: TestRunResult[], options: ReportOptions): string[] {
|
||||||
const sections: string[] = []
|
const sections: string[] = []
|
||||||
const badge = getReportBadge(results)
|
const badge = getReportBadge(results, options)
|
||||||
sections.push(badge)
|
sections.push(badge)
|
||||||
|
|
||||||
const runs = getTestRunsReport(results, options)
|
const runs = getTestRunsReport(results, options)
|
||||||
|
|
@ -101,14 +103,14 @@ function renderReport(results: TestRunResult[], options: ReportOptions): string[
|
||||||
return sections
|
return sections
|
||||||
}
|
}
|
||||||
|
|
||||||
function getReportBadge(results: TestRunResult[]): string {
|
function getReportBadge(results: TestRunResult[], options: ReportOptions): string {
|
||||||
const passed = results.reduce((sum, tr) => sum + tr.passed, 0)
|
const passed = results.reduce((sum, tr) => sum + tr.passed, 0)
|
||||||
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0)
|
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0)
|
||||||
const failed = results.reduce((sum, tr) => sum + tr.failed, 0)
|
const failed = results.reduce((sum, tr) => sum + tr.failed, 0)
|
||||||
return getBadge(passed, failed, skipped)
|
return getBadge(passed, failed, skipped, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBadge(passed: number, failed: number, skipped: number): string {
|
function getBadge(passed: number, failed: number, skipped: number, options: ReportOptions): string {
|
||||||
const text = []
|
const text = []
|
||||||
if (passed > 0) {
|
if (passed > 0) {
|
||||||
text.push(`${passed} passed`)
|
text.push(`${passed} passed`)
|
||||||
|
|
@ -128,7 +130,7 @@ function getBadge(passed: number, failed: number, skipped: number): string {
|
||||||
color = 'yellow'
|
color = 'yellow'
|
||||||
}
|
}
|
||||||
const hint = failed > 0 ? 'Tests failed' : 'Tests passed successfully'
|
const hint = failed > 0 ? 'Tests failed' : 'Tests passed successfully'
|
||||||
const uri = encodeURIComponent(`tests-${message}-${color}`)
|
const uri = encodeURIComponent(`${options.badgeTitle}-${message}-${color}`)
|
||||||
return ``
|
return ``
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue