Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ava: Logs generated outside tests are not shown in the console

Tags:

ava

My problem

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.

Code

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();
});

Output

$ 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.

My question

How can I see the logs from the setup and teardown steps of the test suite?

like image 582
Adam Matan Avatar asked Sep 24 '17 21:09

Adam Matan


Video Answer


1 Answers

Could you open an issue for this? https://github.com/avajs/ava/issues

I agree this should work.

like image 87
Mark Wubben Avatar answered Oct 20 '22 03:10

Mark Wubben