mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 22:07:09 +01:00
Merge pull request #672 from dorny/bugfix/671-allow_hyphens_in_badge_image_names
This commit is contained in:
commit
4a41472ca4
3 changed files with 137 additions and 5 deletions
120
__tests__/report/get-report.test.ts
Normal file
120
__tests__/report/get-report.test.ts
Normal file
|
|
@ -0,0 +1,120 @@
|
||||||
|
import {getBadge, DEFAULT_OPTIONS, ReportOptions} from '../../src/report/get-report'
|
||||||
|
|
||||||
|
describe('getBadge', () => {
|
||||||
|
describe('URI encoding with special characters', () => {
|
||||||
|
it('generates correct URI with simple badge title', () => {
|
||||||
|
const options: ReportOptions = {
|
||||||
|
...DEFAULT_OPTIONS,
|
||||||
|
badgeTitle: 'tests'
|
||||||
|
}
|
||||||
|
const badge = getBadge(5, 0, 1, options)
|
||||||
|
expect(badge).toBe('')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('handles badge title with single hyphen', () => {
|
||||||
|
const options: ReportOptions = {
|
||||||
|
...DEFAULT_OPTIONS,
|
||||||
|
badgeTitle: 'unit-tests'
|
||||||
|
}
|
||||||
|
const badge = getBadge(3, 0, 0, options)
|
||||||
|
// The hyphen in the badge title should be encoded as --
|
||||||
|
expect(badge).toBe('')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('handles badge title with multiple hyphens', () => {
|
||||||
|
const options: ReportOptions = {
|
||||||
|
...DEFAULT_OPTIONS,
|
||||||
|
badgeTitle: 'integration-api-tests'
|
||||||
|
}
|
||||||
|
const badge = getBadge(10, 0, 0, options)
|
||||||
|
// All hyphens in the title should be encoded as --
|
||||||
|
expect(badge).toBe('')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('handles badge title with multiple underscores', () => {
|
||||||
|
const options: ReportOptions = {
|
||||||
|
...DEFAULT_OPTIONS,
|
||||||
|
badgeTitle: 'my_integration_test'
|
||||||
|
}
|
||||||
|
const badge = getBadge(10, 0, 0, options)
|
||||||
|
// All underscores in the title should be encoded as __
|
||||||
|
expect(badge).toBe('')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('handles badge title with version format containing hyphen', () => {
|
||||||
|
const options: ReportOptions = {
|
||||||
|
...DEFAULT_OPTIONS,
|
||||||
|
badgeTitle: 'MariaDb 12.0-ubi database tests'
|
||||||
|
}
|
||||||
|
const badge = getBadge(1, 0, 0, options)
|
||||||
|
// The hyphen in "12.0-ubi" should be encoded as --
|
||||||
|
expect(badge).toBe('')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('handles badge title with dots and hyphens', () => {
|
||||||
|
const options: ReportOptions = {
|
||||||
|
...DEFAULT_OPTIONS,
|
||||||
|
badgeTitle: 'v1.2.3-beta-test'
|
||||||
|
}
|
||||||
|
const badge = getBadge(4, 1, 0, options)
|
||||||
|
expect(badge).toBe('')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('preserves structural hyphens between label and message', () => {
|
||||||
|
const options: ReportOptions = {
|
||||||
|
...DEFAULT_OPTIONS,
|
||||||
|
badgeTitle: 'test-suite'
|
||||||
|
}
|
||||||
|
const badge = getBadge(2, 3, 1, options)
|
||||||
|
// The URI should have literal hyphens separating title-message-color
|
||||||
|
expect(badge).toBe('')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('generates test outcome as color name for imgshields', () => {
|
||||||
|
it('uses success color when all tests pass', () => {
|
||||||
|
const options: ReportOptions = {...DEFAULT_OPTIONS}
|
||||||
|
const badge = getBadge(5, 0, 0, options)
|
||||||
|
expect(badge).toContain('-success)')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('uses critical color when tests fail', () => {
|
||||||
|
const options: ReportOptions = {...DEFAULT_OPTIONS}
|
||||||
|
const badge = getBadge(5, 2, 0, options)
|
||||||
|
expect(badge).toContain('-critical)')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('uses yellow color when no tests found', () => {
|
||||||
|
const options: ReportOptions = {...DEFAULT_OPTIONS}
|
||||||
|
const badge = getBadge(0, 0, 0, options)
|
||||||
|
expect(badge).toContain('-yellow)')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('badge message composition', () => {
|
||||||
|
it('includes only passed count when no failures or skips', () => {
|
||||||
|
const options: ReportOptions = {...DEFAULT_OPTIONS}
|
||||||
|
const badge = getBadge(5, 0, 0, options)
|
||||||
|
expect(badge).toBe('')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('includes passed and failed counts', () => {
|
||||||
|
const options: ReportOptions = {...DEFAULT_OPTIONS}
|
||||||
|
const badge = getBadge(5, 2, 0, options)
|
||||||
|
expect(badge).toBe('')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('includes passed, failed and skipped counts', () => {
|
||||||
|
const options: ReportOptions = {...DEFAULT_OPTIONS}
|
||||||
|
const badge = getBadge(5, 2, 1, options)
|
||||||
|
expect(badge).toBe('')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('uses "none" message when no tests', () => {
|
||||||
|
const options: ReportOptions = {...DEFAULT_OPTIONS}
|
||||||
|
const badge = getBadge(0, 0, 0, options)
|
||||||
|
expect(badge).toBe('')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
10
dist/index.js
generated
vendored
10
dist/index.js
generated
vendored
|
|
@ -1909,6 +1909,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.DEFAULT_OPTIONS = void 0;
|
exports.DEFAULT_OPTIONS = void 0;
|
||||||
exports.getReport = getReport;
|
exports.getReport = getReport;
|
||||||
|
exports.getBadge = getBadge;
|
||||||
const core = __importStar(__nccwpck_require__(7484));
|
const core = __importStar(__nccwpck_require__(7484));
|
||||||
const markdown_utils_1 = __nccwpck_require__(5129);
|
const markdown_utils_1 = __nccwpck_require__(5129);
|
||||||
const node_utils_1 = __nccwpck_require__(5384);
|
const node_utils_1 = __nccwpck_require__(5384);
|
||||||
|
|
@ -2022,8 +2023,10 @@ function getBadge(passed, failed, skipped, options) {
|
||||||
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(`${options.badgeTitle}-${message}-${color}`);
|
const encodedBadgeTitle = encodeImgShieldsURIComponent(options.badgeTitle);
|
||||||
return ``;
|
const encodedMessage = encodeImgShieldsURIComponent(message);
|
||||||
|
const encodedColor = encodeImgShieldsURIComponent(color);
|
||||||
|
return ``;
|
||||||
}
|
}
|
||||||
function getTestRunsReport(testRuns, options) {
|
function getTestRunsReport(testRuns, options) {
|
||||||
const sections = [];
|
const sections = [];
|
||||||
|
|
@ -2153,6 +2156,9 @@ function getResultIcon(result) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function encodeImgShieldsURIComponent(component) {
|
||||||
|
return encodeURIComponent(component).replace(/-/g, '--').replace(/_/g, '__');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ function getReportBadge(results: TestRunResult[], options: ReportOptions): strin
|
||||||
return getBadge(passed, failed, skipped, options)
|
return getBadge(passed, failed, skipped, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBadge(passed: number, failed: number, skipped: number, options: ReportOptions): string {
|
export 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`)
|
||||||
|
|
@ -145,8 +145,10 @@ function getBadge(passed: number, failed: number, skipped: number, options: Repo
|
||||||
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(`${options.badgeTitle}-${message}-${color}`)
|
const encodedBadgeTitle = encodeImgShieldsURIComponent(options.badgeTitle)
|
||||||
return ``
|
const encodedMessage = encodeImgShieldsURIComponent(message)
|
||||||
|
const encodedColor = encodeImgShieldsURIComponent(color)
|
||||||
|
return ``
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTestRunsReport(testRuns: TestRunResult[], options: ReportOptions): string[] {
|
function getTestRunsReport(testRuns: TestRunResult[], options: ReportOptions): string[] {
|
||||||
|
|
@ -305,3 +307,7 @@ function getResultIcon(result: TestExecutionResult): string {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function encodeImgShieldsURIComponent(component: string): string {
|
||||||
|
return encodeURIComponent(component).replace(/-/g, '--').replace(/_/g, '__')
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue