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

Report fails without emit 'test end' event #223

Merged
merged 2 commits into from Apr 29, 2020
Merged
Changes from 1 commit
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
70 changes: 37 additions & 33 deletions src/adapter.js
Expand Up @@ -80,6 +80,41 @@ var haveMochaConfig = function (karma) {
return karma.config && karma.config.mocha
}

var reportTestResult = function (karma, test) {
var skipped = test.pending === true

var result = {
id: '',
description: test.title,
suite: [],
success: test.state === 'passed',
skipped: skipped,
pending: skipped,
time: skipped ? 0 : test.duration,
log: test.$errors || [],
assertionErrors: test.$assertionErrors || [],
startTime: test.$startTime,
endTime: Date.now()
}

var pointer = test.parent
while (!pointer.root) {
result.suite.unshift(pointer.title)
pointer = pointer.parent
}

if (haveMochaConfig(karma) && karma.config.mocha.expose && karma.config.mocha.expose.forEach) {
result.mocha = {}
karma.config.mocha.expose.forEach(function (prop) {
if (test.hasOwnProperty(prop)) {
result.mocha[prop] = test[prop]
}
})
}

karma.result(result)
}

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

Expand Down Expand Up @@ -129,46 +164,15 @@ var createMochaReporterConstructor = function (tc, pathname) {
if (test.type === 'hook') {
test.$errors = isDebugPage ? [error] : [simpleError]
test.$assertionErrors = assertionError ? [assertionError] : []
runner.emit('test end', test)
reportTestResult(tc, test)
} else {
test.$errors.push(isDebugPage ? error : simpleError)
if (assertionError) test.$assertionErrors.push(assertionError)
}
})

runner.on('test end', function (test) {
var skipped = test.pending === true

var result = {
id: '',
description: test.title,
suite: [],
success: test.state === 'passed',
skipped: skipped,
pending: skipped,
time: skipped ? 0 : test.duration,
log: test.$errors || [],
assertionErrors: test.$assertionErrors || [],
startTime: test.$startTime,
endTime: Date.now()
}

var pointer = test.parent
while (!pointer.root) {
result.suite.unshift(pointer.title)
pointer = pointer.parent
}

if (haveMochaConfig(tc) && tc.config.mocha.expose && tc.config.mocha.expose.forEach) {
result.mocha = {}
tc.config.mocha.expose.forEach(function (prop) {
if (test.hasOwnProperty(prop)) {
result.mocha[prop] = test[prop]
}
})
}

tc.result(result)
reportTestResult(tc, test)
})
}
}
Expand Down