ava logging (t.log
) only work inside a test, but not during setup (before
, beforeEach
) or teardown (after*
) functions.
This means that meaningful setup / teardown data, which is very useful for debugging and reproducing, is lost. This happens both for successful and failed tests, and with and without the --verbose
flag.
import test from 'ava';
test.before(t => {
// This runs before all tests
t.log('before - 1');
});
test.before(t => {
// This runs after the above, but before tests
t.log('before - 2');
});
test.after('cleanup', t => {
// This runs after all tests
t.log('after');
});
test.after.always('guaranteed cleanup', t => {
// This will always run, regardless of earlier failures
t.log('after always');
});
test.beforeEach(t => {
// This runs before each test
t.log('beforeEach');
});
test.afterEach(t => {
// This runs after each test
t.log('afterEach');
});
test.afterEach.always(t => {
// This runs after each test and other test hooks, even if they failed
t.log('afterEachAlways');
});
test(t => {
t.log('A test');
t.pass();
});
test(t => {
t.log('A test');
t.fail();
});
$ ava run.js --verbose
✔ [anonymous]
ℹ A test
✖ [anonymous] Test failed via `t.fail()`
ℹ A test
1 test failed [00:22:08]
[anonymous]
ℹ A test
/Users/adam/Personal/tmp/ava-bug-log-in-before-each/run.js:46
45: t.log('A test');
46: t.fail();
47: });
Test failed via `t.fail()`
Note that only the printouts from the test (A test
) are show. All other logs are lost.
How can I see the logs from the setup and teardown steps of the test suite?
Could you open an issue for this? https://github.com/avajs/ava/issues
I agree this should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With