Skip to content
Open
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
39 changes: 39 additions & 0 deletions __tests__/renderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,45 @@ describe('renderer', () => {
expect($.text()).toContain(pieData)
})

it('renders pie with correct colors when some conclusion types are missing', async () => {
const renderer = await getRenderer()
renderer.totalConclusions = { pass: 5, fail: 0, skip: 2 }
await renderer.writeSummary()
const $ = await loadSummaryHTML()

expect($.text()).toContain('```mermaid')
expect($.text()).toContain('"Passed" : 5')
expect($.text()).toContain('"Skipped" : 2')
expect($.text()).not.toMatch(/"Failed" :/) // fail should not appear in data
expect($.text()).toMatch(/pie1/)
expect($.text()).toMatch(/pie2/)
expect($.text()).not.toMatch(/pie3/)
})

it('renders pie with correct colors when only passes exist', async () => {
const renderer = await getRenderer()
renderer.totalConclusions = { pass: 10, fail: 0, skip: 0 }
await renderer.writeSummary()
const $ = await loadSummaryHTML()

expect($.text()).toContain('```mermaid')
expect($.text()).toContain('"Passed" : 10')
expect($.text()).toContain('pie1')
expect($.text()).not.toContain('pie2')
expect($.text()).not.toContain('pie3')
})

it('renders pie with correct colors when only fails exist', async () => {
const renderer = await getRenderer()
renderer.totalConclusions = { pass: 0, fail: 3, skip: 0 }
await renderer.writeSummary()
const $ = await loadSummaryHTML()

expect($.text()).toContain('```mermaid')
expect($.text()).toContain('"Failed" : 3')
expect($.text()).toMatch(/pie1.*#cf222e/) // pie1 should have fail color (red)
})

it('does not render pie when pie in omit', async () => {
const renderer = await getRenderer()
renderer.omit.add(OmitOption.Pie)
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

11 changes: 3 additions & 8 deletions src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,10 @@ class Renderer {
skip: { color: '#dbab0a', word: 'Skipped' },
}

let pieIndex = 1
const pieData = conclusiveTestEvents
.map(conclusion => {
if (!this.totalConclusions[conclusion]) {
return ''
}

pieConfig.themeVariables[`pie${pieIndex}`] = keys[conclusion].color
pieIndex++
.filter(c => this.totalConclusions[c])
.map((conclusion, idx) => {
pieConfig.themeVariables[`pie${idx + 1}`] = keys[conclusion].color
return `"${keys[conclusion].word}" : ${this.totalConclusions[conclusion]}\n`
})
.join('')
Expand Down