Skip to content

Commit 7148297

Browse files
pespineljozefizso
authored andcommitted
test: fix linter and create tests
1 parent 828632a commit 7148297

File tree

2 files changed

+75
-3
lines changed

2 files changed

+75
-3
lines changed

__tests__/jest-junit.test.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,78 @@ describe('jest-junit tests', () => {
207207
// Report should have the title as the first line
208208
expect(report).toMatch(/^# My Custom Title\n/)
209209
})
210+
211+
it('report can be collapsed when configured', async () => {
212+
const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit.xml')
213+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
214+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
215+
216+
const opts: ParseOptions = {
217+
parseErrors: true,
218+
trackedFiles: []
219+
}
220+
221+
const parser = new JestJunitParser(opts)
222+
const result = await parser.parse(filePath, fileContent)
223+
const report = getReport([result], {
224+
...DEFAULT_OPTIONS,
225+
collapsed: 'always'
226+
})
227+
// Report should include collapsible details
228+
expect(report).toContain('<details><summary>Expand for details</summary>')
229+
expect(report).toContain('</details>')
230+
})
231+
232+
it('report is not collapsed when configured to never', async () => {
233+
const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit.xml')
234+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
235+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
236+
237+
const opts: ParseOptions = {
238+
parseErrors: true,
239+
trackedFiles: []
240+
}
241+
242+
const parser = new JestJunitParser(opts)
243+
const result = await parser.parse(filePath, fileContent)
244+
const report = getReport([result], {
245+
...DEFAULT_OPTIONS,
246+
collapsed: 'never'
247+
})
248+
// Report should not include collapsible details
249+
expect(report).not.toContain('<details><summary>Expand for details</summary>')
250+
expect(report).not.toContain('</details>')
251+
})
252+
253+
it('report auto-collapses only when all tests pass', async () => {
254+
// Test with a fixture that has passing tests (no failures)
255+
const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit.xml')
256+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
257+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
258+
259+
const opts: ParseOptions = {
260+
parseErrors: true,
261+
trackedFiles: []
262+
}
263+
264+
const parser = new JestJunitParser(opts)
265+
const result = await parser.parse(filePath, fileContent)
266+
267+
// Check if this fixture has failures to determine expected behavior
268+
const hasFailed = result.failed > 0
269+
270+
const report = getReport([result], {
271+
...DEFAULT_OPTIONS,
272+
collapsed: 'auto'
273+
})
274+
275+
if (hasFailed) {
276+
// Should not collapse when there are failures
277+
expect(report).not.toContain('<details><summary>Expand for details</summary>')
278+
} else {
279+
// Should collapse when all tests pass
280+
expect(report).toContain('<details><summary>Expand for details</summary>')
281+
expect(report).toContain('</details>')
282+
}
283+
})
210284
})

src/report/get-report.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ function getTestRunsReport(testRuns: TestRunResult[], options: ReportOptions): s
158158
const totalFailed = testRuns.reduce((sum, tr) => sum + tr.failed, 0)
159159

160160
// Determine if report should be collapsed based on collapsed option
161-
const shouldCollapse =
162-
options.collapsed === 'always' ||
163-
(options.collapsed === 'auto' && totalFailed === 0)
161+
const shouldCollapse = options.collapsed === 'always' || (options.collapsed === 'auto' && totalFailed === 0)
164162

165163
if (shouldCollapse) {
166164
sections.push(`<details><summary>Expand for details</summary>`)

0 commit comments

Comments
 (0)