Skip to content

Commit

Permalink
fix(coverage): do not collect coverage data if coverage is not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBuchholz committed Sep 3, 2024
1 parent 7381caf commit dcfedd9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/qunit-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ async function done (job, urlWithHash, report) {
}
}
page.end = new Date()
if (job.coverage && report.__coverage__) {
await collect(job, url, report.__coverage__)
if (report.__coverage__) {
if (job.coverage) {
await collect(job, url, report.__coverage__)
}
delete report.__coverage__
}
page.report = report
Expand Down
14 changes: 13 additions & 1 deletion src/qunit-hooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('src/qunit-hooks', () => {
screenshot.mockReset()
screenshot.mockImplementation((job, url, testId) => Promise.resolve(`whatever/${testId}.png`))
stop.mockClear()
collect.mockClear()
mockGenericError.mockClear()
job = {
screenshot: true,
Expand Down Expand Up @@ -686,16 +687,27 @@ describe('src/qunit-hooks', () => {
expect(page.report).toStrictEqual(getDoneInfo())
})

it('collects and strips coverage information', async () => {
it('collects and strips coverage information (coverage enabled)', async () => {
const report = getDoneInfo()
const coverage = {}
report.__coverage__ = coverage
job.coverage = true
await done(job, url, report)
expect(collect).toHaveBeenCalledWith(job, url, coverage)
const { page } = get(job, url)
expect(page.report).toStrictEqual(getDoneInfo())
})

it('collects but drops coverage information (coverage disabled)', async () => {
const report = getDoneInfo()
const coverage = {}
report.__coverage__ = coverage
await done(job, url, report)
expect(collect).not.toHaveBeenCalled()
const { page } = get(job, url)
expect(page.report).toStrictEqual(getDoneInfo())
})

it('documents when the page ended', async () => {
await done(job, url, getDoneInfo())
const { page } = get(job, url)
Expand Down

0 comments on commit dcfedd9

Please sign in to comment.