diff --git a/lib/reporters/verbose.js b/lib/reporters/verbose.js index b35a31549..ae7c06443 100644 --- a/lib/reporters/verbose.js +++ b/lib/reporters/verbose.js @@ -126,6 +126,12 @@ class VerboseReporter { this.filesWithMissingAvaImports.add(evt.testFile); this.lineWriter.writeLine(colors.error(`${figures.cross} No tests found in ${path.relative('.', evt.testFile)}, make sure to import "ava" at the top of your test file`)); break; + case 'hook-finished': + if (evt.logs.length > 0) { + this.lineWriter.writeLine(` ${this.prefixTitle(evt.testFile, evt.title)}`); + this.writeLogs(evt); + } + break; case 'selected-test': if (evt.skip) { this.lineWriter.writeLine(colors.skip(`- ${this.prefixTitle(evt.testFile, evt.title)}`)); diff --git a/lib/runner.js b/lib/runner.js index 8961fae13..35d65125b 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -277,13 +277,15 @@ class Runner extends Emittery { title: `${task.title}${titleSuffix || ''}` })); return this.runMultiple(hooks, this.serial).then(outcome => { - if (outcome.allPassed) { - return true; - } - - // Only emit results for failed hooks. for (const result of outcome.storedResults) { - if (!result.passed) { + if (result.passed) { + this.emit('stateChange', { + type: 'hook-finished', + title: result.title, + duration: result.duration, + logs: result.logs + }); + } else { this.emit('stateChange', { type: 'hook-failed', title: result.title, @@ -294,7 +296,7 @@ class Runner extends Emittery { } } - return false; + return outcome.allPassed; }); } diff --git a/test/fixture/report/regular/output-in-hook.js b/test/fixture/report/regular/output-in-hook.js new file mode 100644 index 000000000..f251cdfbe --- /dev/null +++ b/test/fixture/report/regular/output-in-hook.js @@ -0,0 +1,35 @@ +import test from '../../../..'; + +test.before(() => {}); + +test.before(t => { + t.log('before'); +}); + +test.after('cleanup', t => { + t.log('after'); +}); + +test.after.always('cleanup', t => { + t.log('afterAlways'); +}); + +test.beforeEach(t => { + t.log('beforeEach'); +}); + +test.afterEach(t => { + t.log('afterEach'); +}); + +test.afterEach.always(t => { + t.log('afterEachAlways'); +}); + +test('passing test', t => { + t.pass(); +}); + +test('failing test', t => { + t.fail(); +}); diff --git a/test/reporters/mini.regular.log b/test/reporters/mini.regular.log index da2fa4245..990c2daac 100644 --- a/test/reporters/mini.regular.log +++ b/test/reporters/mini.regular.log @@ -110,10 +110,26 @@ stderr 1 skipped 1 todo---tty-stream-chunk-separator ---tty-stream-chunk-separator +* output-in-hook › passing test + + 6 passed + 1 known failure + 8 tests failed + 1 skipped + 1 todo---tty-stream-chunk-separator +---tty-stream-chunk-separator +* output-in-hook › failing test + + 6 passed + 1 known failure + 9 tests failed + 1 skipped + 1 todo---tty-stream-chunk-separator +---tty-stream-chunk-separator [?25h ✖ No tests found in test/fixture/report/regular/bad-test-chain.js - 8 tests failed + 9 tests failed 1 known failure 1 test skipped 1 test todo @@ -254,6 +270,18 @@ stderr + output-in-hook › failing test + + ~/test/fixture/report/regular/output-in-hook.js:34 + + 33: test('failing test', t => { +  34: t.fail();  + 35: }); + + Test failed via `t.fail()` + + + Uncaught exception in test/fixture/report/regular/bad-test-chain.js ~/test/fixture/report/regular/bad-test-chain.js:3 diff --git a/test/reporters/tap.regular.log b/test/reporters/tap.regular.log index 09434adf6..b16456c62 100644 --- a/test/reporters/tap.regular.log +++ b/test/reporters/tap.regular.log @@ -154,11 +154,23 @@ not ok 21 - test › implementation throws non-error # slow › slow ok 22 - slow › slow ---tty-stream-chunk-separator +# output-in-hook › passing test +ok 23 - output-in-hook › passing test +---tty-stream-chunk-separator +# output-in-hook › failing test +not ok 24 - output-in-hook › failing test + --- + name: AssertionError + message: Test failed via `t.fail()` + assertion: fail + at: 'fail (output-in-hook.js:34:4)' + ... +---tty-stream-chunk-separator -1..16 -# tests 15 -# pass 6 +1..18 +# tests 17 +# pass 7 # skip 1 -# fail 15 +# fail 16 ---tty-stream-chunk-separator diff --git a/test/reporters/verbose.regular.log b/test/reporters/verbose.regular.log index ed6653f59..7f497f495 100644 --- a/test/reporters/verbose.regular.log +++ b/test/reporters/verbose.regular.log @@ -82,8 +82,33 @@ stderr ---tty-stream-chunk-separator ✔ slow › slow (000ms) ---tty-stream-chunk-separator + output-in-hook › before hook + ℹ before +---tty-stream-chunk-separator + output-in-hook › beforeEach hook for passing test + ℹ beforeEach +---tty-stream-chunk-separator + output-in-hook › beforeEach hook for failing test + ℹ beforeEach +---tty-stream-chunk-separator + ✔ output-in-hook › passing test +---tty-stream-chunk-separator + ✖ output-in-hook › failing test Test failed via `t.fail()` +---tty-stream-chunk-separator + output-in-hook › afterEach hook for passing test + ℹ afterEach +---tty-stream-chunk-separator + output-in-hook › afterEach.always hook for failing test + ℹ afterEachAlways +---tty-stream-chunk-separator + output-in-hook › afterEach.always hook for passing test + ℹ afterEachAlways +---tty-stream-chunk-separator + output-in-hook › cleanup + ℹ afterAlways +---tty-stream-chunk-separator - 8 tests failed + 9 tests failed 1 known failure 1 test skipped 1 test todo @@ -222,4 +247,16 @@ stderr null + + + output-in-hook › failing test + + ~/test/fixture/report/regular/output-in-hook.js:34 + + 33: test('failing test', t => { +  34: t.fail();  + 35: }); + + Test failed via `t.fail()` + ---tty-stream-chunk-separator