fix listing for errors that occurs within beforeEach
All checks were successful
tests / test (push) Successful in 8s
All checks were successful
tests / test (push) Successful in 8s
This commit is contained in:
@@ -14,6 +14,7 @@ const {
|
||||
EVENT_TEST_PASS,
|
||||
EVENT_TEST_FAIL,
|
||||
EVENT_TEST_PENDING,
|
||||
EVENT_HOOK_FAIL,
|
||||
} = Mocha.Runner.constants;
|
||||
|
||||
function serializeError(err) {
|
||||
@@ -81,6 +82,10 @@ class NdjsonReporter {
|
||||
this.emit(this.testPayload('failed', test, serializeError(err)));
|
||||
})
|
||||
|
||||
.on(EVENT_HOOK_FAIL, (hook, err) => {
|
||||
this.emit(this.hookPayload('failed', hook, serializeError(err)));
|
||||
})
|
||||
|
||||
.on(EVENT_TEST_PENDING, (test) => {
|
||||
// Mocha "pending" includes:
|
||||
// - TODO tests (no function)
|
||||
@@ -169,6 +174,43 @@ class NdjsonReporter {
|
||||
return payload;
|
||||
}
|
||||
|
||||
hookPayload(status, hook, errorObj) {
|
||||
const currentTest = hook && hook.ctx && hook.ctx.currentTest ? hook.ctx.currentTest : null;
|
||||
const hookType = hook && hook.type ? hook.type : 'hook';
|
||||
const titlePath =
|
||||
(currentTest && safeTitlePath(currentTest)) ||
|
||||
(hook && hook.parent && safeTitlePath(hook.parent)) ||
|
||||
safeTitlePath(hook);
|
||||
const fullTitle =
|
||||
(currentTest && typeof currentTest.fullTitle === 'function' && currentTest.fullTitle()) ||
|
||||
(hook && hook.title) ||
|
||||
null;
|
||||
const file =
|
||||
(hook && hook.file) ||
|
||||
(currentTest && currentTest.file) ||
|
||||
(hook && hook.parent && hook.parent.file) ||
|
||||
null;
|
||||
const location =
|
||||
(currentTest && currentTest._akLocation) ||
|
||||
(hook && hook._akLocation) ||
|
||||
null;
|
||||
|
||||
const payload = {
|
||||
event: 'hook',
|
||||
status,
|
||||
hookType,
|
||||
title: hook && hook.title ? hook.title : null,
|
||||
fullTitle,
|
||||
titlePath,
|
||||
file,
|
||||
location,
|
||||
};
|
||||
|
||||
if (status === 'failed') payload.error = errorObj;
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
emit(obj) {
|
||||
this.originalStdoutWrite(JSON.stringify(obj) + '\n');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user