ava logging(t.log
)仅适用于测试,但不适用于设置(before
,beforeEach
)或拆卸(after*
)功能。
这意味着丢失了对调试和再现非常有用的有意义的设置/拆除数据。对于成功和失败的测试,以及带有和不带--verbose
标志的情况都会发生这种情况。
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()`
请注意,仅显示测试(A test
)的打印输出。所有其他日志都将丢失。
如何从测试套件的设置和拆卸步骤中查看日志?