diff --git a/__tests__/report/get-report.test.ts b/__tests__/report/get-report.test.ts index 1925110..670b0ad 100644 --- a/__tests__/report/get-report.test.ts +++ b/__tests__/report/get-report.test.ts @@ -31,6 +31,16 @@ describe('getBadge', () => { expect(badge).toBe('![Tests passed successfully](https://img.shields.io/badge/integration--api--tests-10%20passed-success)') }) + 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('![Tests passed successfully](https://img.shields.io/badge/my__integration__test-10%20passed-success)') + }) + it('handles badge title with version format containing hyphen', () => { const options: ReportOptions = { ...DEFAULT_OPTIONS, diff --git a/src/report/get-report.ts b/src/report/get-report.ts index bbf8aca..5168b7a 100644 --- a/src/report/get-report.ts +++ b/src/report/get-report.ts @@ -309,5 +309,5 @@ function getResultIcon(result: TestExecutionResult): string { } function encodeImgShieldsURIComponent(component: string): string { - return encodeURIComponent(component).replace(/-/g, '--') + return encodeURIComponent(component).replace(/-/g, '--').replace(/_/g, '__') }