Skip to content

Chore/report test #171

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

Merged
merged 2 commits into from
Jul 6, 2025
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
67 changes: 67 additions & 0 deletions __tests__/handlebars/string.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import Handlebars from 'handlebars'
import { splitLinesHelper } from '../../src/handlebars/helpers/string'

describe('String Helpers', () => {
beforeEach(() => {
// Register the helper before each test
splitLinesHelper()
})

describe('splitLines', () => {
it('should split lines correctly for multiline strings', () => {
const template = Handlebars.compile(
'{{#each (splitLines text)}}{{this}}{{#unless @last}},{{/unless}}{{/each}}'
)
const result = template({ text: 'Line one\nLine two\nLine three' })
expect(result).toBe('Line one,Line two,Line three')
})

it('should filter out empty lines', () => {
const template = Handlebars.compile(
'{{#each (splitLines text)}}{{this}}{{#unless @last}},{{/unless}}{{/each}}'
)
const result = template({ text: 'Line one\n\nLine two\n\nLine three' })
expect(result).toBe('Line one,Line two,Line three')
})

it('should handle undefined values gracefully', () => {
const template = Handlebars.compile(
'{{#each (splitLines text)}}{{this}}{{#unless @last}},{{/unless}}{{/each}}'
)
const result = template({ text: undefined })
expect(result).toBe('')
})

it('should handle null values gracefully', () => {
const template = Handlebars.compile(
'{{#each (splitLines text)}}{{this}}{{#unless @last}},{{/unless}}{{/each}}'
)
const result = template({ text: null })
expect(result).toBe('')
})

it('should handle empty strings', () => {
const template = Handlebars.compile(
'{{#each (splitLines text)}}{{this}}{{#unless @last}},{{/unless}}{{/each}}'
)
const result = template({ text: '' })
expect(result).toBe('')
})

it('should handle strings with only whitespace', () => {
const template = Handlebars.compile(
'{{#each (splitLines text)}}{{this}}{{#unless @last}},{{/unless}}{{/each}}'
)
const result = template({ text: ' \n \n ' })
expect(result).toBe('')
})

it('should handle single line strings', () => {
const template = Handlebars.compile(
'{{#each (splitLines text)}}{{this}}{{#unless @last}},{{/unless}}{{/each}}'
)
const result = template({ text: 'Single line' })
expect(result).toBe('Single line')
})
})
})
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 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.

8 changes: 4 additions & 4 deletions dist/reports/previous-results-table.hbs

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

6 changes: 3 additions & 3 deletions dist/reports/summary-table.hbs

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

3 changes: 3 additions & 0 deletions src/handlebars/helpers/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export function escapeMarkdownHelper(): void {
*/
export function splitLinesHelper(): void {
Handlebars.registerHelper('splitLines', (str: string) => {
if (!str) {
return []
}
return str.split('\n').filter((line: string) => line.trim() !== '')
})
}
Expand Down
8 changes: 4 additions & 4 deletions src/reports/previous-results-table.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
| **Build {{getCtrfEmoji "build"}}** | **Result {{getCtrfEmoji "result"}}** | **Tests {{getCtrfEmoji "tests"}}** | **Passed {{getCtrfEmoji "passed"}}** | **Failed {{getCtrfEmoji "failed"}}** | **Skipped {{getCtrfEmoji "skipped"}}** | **Pending {{getCtrfEmoji "pending"}}** | **Other {{getCtrfEmoji "other"}}** | **Flaky {{getCtrfEmoji "flaky"}}** | **Duration {{getCtrfEmoji "duration"}}** |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| [#{{ctrf.environment.extra.runNumber}}]({{ctrf.environment.extra.buildUrl}}) | {{getCtrfEmoji ctrf.summary.extra.result}} | {{ctrf.summary.tests}} | {{ctrf.summary.passed}} | {{ctrf.summary.failed}} | {{ctrf.summary.skipped}} | {{ctrf.summary.pending}} | {{ctrf.summary.other}} | {{countFlaky ctrf.tests}} | {{formatDuration ctrf.summary.start ctrf.summary.stop}} |
| **Build {{getCtrfEmoji "build"}}** | **Result {{getCtrfEmoji "result"}}** | **Tests {{getCtrfEmoji "tests"}}** | **Passed {{getCtrfEmoji "passed"}}** | **Failed {{getCtrfEmoji "failed"}}** | **Skipped {{getCtrfEmoji "skipped"}}** | **Other {{getCtrfEmoji "other"}}** | **Flaky {{getCtrfEmoji "flaky"}}** | **Duration {{getCtrfEmoji "duration"}}** |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| [#{{ctrf.environment.extra.runNumber}}]({{ctrf.environment.extra.buildUrl}}) | {{getCtrfEmoji ctrf.summary.extra.result}} | {{ctrf.summary.tests}} | {{ctrf.summary.passed}} | {{ctrf.summary.failed}} | {{add ctrf.summary.skipped ctrf.summary.pending}} | {{ctrf.summary.other}} | {{countFlaky ctrf.tests}} | {{formatDuration ctrf.summary.start ctrf.summary.stop}} |
{{#each ctrf.extra.previousReports}}
| [#{{this.results.environment.extra.runNumber}}]({{this.results.environment.extra.buildUrl}}) | {{getCtrfEmoji this.results.summary.extra.result}} | {{this.results.summary.tests}} | {{this.results.summary.passed}} | {{this.results.summary.failed}} | {{this.results.summary.skipped}} | {{this.results.summary.pending}} | {{this.results.summary.other}} | {{this.results.summary.extra.flaky}} | {{formatDuration this.results.summary.start this.results.summary.stop}} |
| [#{{this.results.environment.extra.runNumber}}]({{this.results.environment.extra.buildUrl}}) | {{getCtrfEmoji this.results.summary.extra.result}} | {{this.results.summary.tests}} | {{this.results.summary.passed}} | {{this.results.summary.failed}} | {{add this.results.summary.skipped this.results.summary.pending}} | {{this.results.summary.other}} | {{this.results.summary.extra.flaky}} | {{formatDuration this.results.summary.start this.results.summary.stop}} |
{{/each}}
6 changes: 3 additions & 3 deletions src/reports/summary-table.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
| **Tests {{getCtrfEmoji "tests"}}** | **Passed {{getCtrfEmoji "passed"}}** | **Failed {{getCtrfEmoji "failed"}}** | **Skipped {{getCtrfEmoji "skipped"}}** | **Pending {{getCtrfEmoji "pending"}}** | **Other {{getCtrfEmoji "other"}}** | **Flaky {{getCtrfEmoji "flaky"}}** | **Duration {{getCtrfEmoji "duration"}}** |
| --- | --- | --- | --- | --- | --- | --- | --- |
| {{ctrf.summary.tests}} | {{ctrf.summary.passed}} | {{ctrf.summary.failed}} | {{ctrf.summary.skipped}} | {{ctrf.summary.pending}} | {{ctrf.summary.other}} | {{countFlaky ctrf.tests}} | {{formatDuration ctrf.summary.start ctrf.summary.stop}} |
| **Tests {{getCtrfEmoji "tests"}}** | **Passed {{getCtrfEmoji "passed"}}** | **Failed {{getCtrfEmoji "failed"}}** | **Skipped {{getCtrfEmoji "skipped"}}** | **Other {{getCtrfEmoji "other"}}** | **Flaky {{getCtrfEmoji "flaky"}}** | **Duration {{getCtrfEmoji "duration"}}** |
| --- | --- | --- | --- | --- | --- | --- |
| {{ctrf.summary.tests}} | {{ctrf.summary.passed}} | {{ctrf.summary.failed}} | {{add ctrf.summary.skipped ctrf.summary.pending}} | {{ctrf.summary.other}} | {{countFlaky ctrf.tests}} | {{formatDuration ctrf.summary.start ctrf.summary.stop}} |