Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Report on failures after test complete. #237

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ var reportTestResult = function (karma, test) {
karma.result(result)
}

var completedTests = new Set()

var createMochaReporterConstructor = function (tc, pathname) {
var isDebugPage = /debug.html$/.test(pathname)

Expand Down Expand Up @@ -168,10 +170,12 @@ var createMochaReporterConstructor = function (tc, pathname) {
} else {
test.$errors.push(isDebugPage ? error : simpleError)
if (assertionError) test.$assertionErrors.push(assertionError)
if (completedTests.has(test)) reportTestResult(tc, test)
}
})

runner.on('test end', function (test) {
completedTests.add(test)
reportTestResult(tc, test)
})
}
Expand Down
22 changes: 22 additions & 0 deletions test/src/adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,28 @@ describe('adapter mocha', function () {
expect(tc.result.called).to.eq(true)
})

it('should report failure even after test end', function () {
const spy = sandbox.spy(tc, 'result')
var mockMochaResult = {
parent: {title: 'desc', root: true},
state: 'failed',
title: 'should do something',
$errors: []
}

runner.emit('test end', mockMochaResult)
expect(tc.result.calledOnce).to.eq(true)
expect(spy.firstCall.args[0]).deep.include({ success: false, skipped: false })
expect(spy.firstCall.args[0].log).to.deep.eq([])
expect(spy.firstCall.args[0].assertionErrors).to.deep.eq([])

runner.emit('fail', mockMochaResult, {message: 'Biggest trouble.'})
expect(tc.result.calledTwice).to.eq(true)
expect(spy.firstCall.args[0]).deep.include({ success: false, skipped: false })
expect(spy.secondCall.args[0].log).to.deep.eq(['Biggest trouble.'])
expect(spy.firstCall.args[0].assertionErrors).to.deep.eq([])
})

it('should report failed mocha result', function () {
sandbox.stub(tc, 'result', function (result) {
expect(result.log).to.deep.eq(['Big trouble.', 'Another fail.'])
Expand Down