ava:在测试之外生成的日志不会显示在控制台中

时间:2017-09-24 21:23:55

标签: ava

我的问题

ava logging(t.log)仅适用于测试,但不适用于设置(beforebeforeEach)或拆卸(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)的打印输出。所有其他日志都将丢失。

我的问题

如何从测试套件的设置和拆卸步骤中查看日志?

1 个答案:

答案 0 :(得分:3)

你能解决这个问题吗? https://github.com/avajs/ava/issues

我同意这应该有用。