Skip to content

Commit 0c64268

Browse files
Chore/minor report improvements (#171)
1 parent 2d199ff commit 0c64268

File tree

9 files changed

+89
-16
lines changed

9 files changed

+89
-16
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import Handlebars from 'handlebars'
2+
import { splitLinesHelper } from '../../src/handlebars/helpers/string'
3+
4+
describe('String Helpers', () => {
5+
beforeEach(() => {
6+
// Register the helper before each test
7+
splitLinesHelper()
8+
})
9+
10+
describe('splitLines', () => {
11+
it('should split lines correctly for multiline strings', () => {
12+
const template = Handlebars.compile(
13+
'{{#each (splitLines text)}}{{this}}{{#unless @last}},{{/unless}}{{/each}}'
14+
)
15+
const result = template({ text: 'Line one\nLine two\nLine three' })
16+
expect(result).toBe('Line one,Line two,Line three')
17+
})
18+
19+
it('should filter out empty lines', () => {
20+
const template = Handlebars.compile(
21+
'{{#each (splitLines text)}}{{this}}{{#unless @last}},{{/unless}}{{/each}}'
22+
)
23+
const result = template({ text: 'Line one\n\nLine two\n\nLine three' })
24+
expect(result).toBe('Line one,Line two,Line three')
25+
})
26+
27+
it('should handle undefined values gracefully', () => {
28+
const template = Handlebars.compile(
29+
'{{#each (splitLines text)}}{{this}}{{#unless @last}},{{/unless}}{{/each}}'
30+
)
31+
const result = template({ text: undefined })
32+
expect(result).toBe('')
33+
})
34+
35+
it('should handle null values gracefully', () => {
36+
const template = Handlebars.compile(
37+
'{{#each (splitLines text)}}{{this}}{{#unless @last}},{{/unless}}{{/each}}'
38+
)
39+
const result = template({ text: null })
40+
expect(result).toBe('')
41+
})
42+
43+
it('should handle empty strings', () => {
44+
const template = Handlebars.compile(
45+
'{{#each (splitLines text)}}{{this}}{{#unless @last}},{{/unless}}{{/each}}'
46+
)
47+
const result = template({ text: '' })
48+
expect(result).toBe('')
49+
})
50+
51+
it('should handle strings with only whitespace', () => {
52+
const template = Handlebars.compile(
53+
'{{#each (splitLines text)}}{{this}}{{#unless @last}},{{/unless}}{{/each}}'
54+
)
55+
const result = template({ text: ' \n \n ' })
56+
expect(result).toBe('')
57+
})
58+
59+
it('should handle single line strings', () => {
60+
const template = Handlebars.compile(
61+
'{{#each (splitLines text)}}{{this}}{{#unless @last}},{{/unless}}{{/each}}'
62+
)
63+
const result = template({ text: 'Single line' })
64+
expect(result).toBe('Single line')
65+
})
66+
})
67+
})

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/reports/previous-results-table.hbs

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/reports/summary-table.hbs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/handlebars/helpers/string.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ export function escapeMarkdownHelper(): void {
5353
*/
5454
export function splitLinesHelper(): void {
5555
Handlebars.registerHelper('splitLines', (str: string) => {
56+
if (!str) {
57+
return []
58+
}
5659
return str.split('\n').filter((line: string) => line.trim() !== '')
5760
})
5861
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
| **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"}}** |
2-
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
3-
| [#{{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}} |
1+
| **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"}}** |
2+
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
3+
| [#{{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}} |
44
{{#each ctrf.extra.previousReports}}
5-
| [#{{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}} |
5+
| [#{{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}} |
66
{{/each}}

src/reports/summary-table.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| **Tests {{getCtrfEmoji "tests"}}** | **Passed {{getCtrfEmoji "passed"}}** | **Failed {{getCtrfEmoji "failed"}}** | **Skipped {{getCtrfEmoji "skipped"}}** | **Pending {{getCtrfEmoji "pending"}}** | **Other {{getCtrfEmoji "other"}}** | **Flaky {{getCtrfEmoji "flaky"}}** | **Duration {{getCtrfEmoji "duration"}}** |
2-
| --- | --- | --- | --- | --- | --- | --- | --- |
3-
| {{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}} |
1+
| **Tests {{getCtrfEmoji "tests"}}** | **Passed {{getCtrfEmoji "passed"}}** | **Failed {{getCtrfEmoji "failed"}}** | **Skipped {{getCtrfEmoji "skipped"}}** | **Other {{getCtrfEmoji "other"}}** | **Flaky {{getCtrfEmoji "flaky"}}** | **Duration {{getCtrfEmoji "duration"}}** |
2+
| --- | --- | --- | --- | --- | --- | --- |
3+
| {{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}} |

0 commit comments

Comments
 (0)