`t.log()` does not work in before/after hooks
See original GitHub issueBug Description
Ava logging with t.log
only work inside a test function, 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.
Steps to reproduce
I’ve created a small git repo exemplifying the problem:
git clone git@github.com:adamatan/ava-logging-bug.git
cd ava-logging-bug
npm install
ava run.js --verbose
Test Source
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('Passing test', (t) => {
t.log('Log from the passing test');
t.pass();
});
test('Failing test', (t) => {
t.log('Log from the failing test');
t.fail();
});
Error Message & Stack Trace
Only the log output from the test
function appear:
✔ Passing test
ℹ Log from the passing test
✖ Failing test Test failed via `t.fail()`
ℹ Log from the failing test
1 test failed [14:00:40]
Failing test
ℹ Log from the failing test
/Users/adam/Personal/tmp/ava-bug-log-in-before-each/run.js:46
45: t.log('Log from the failing test');
46: t.fail();
47: });
Test failed via `t.fail()`
Command-Line Arguments
ava run.js --verbose
Relevant Links
Environment
Node.js v8.1.2
darwin 16.7.0
0.22.0 // ava
5.4.2 . // npm
dflupu earned $100.00 by resolving this issue!
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on Issuehunt to raise funds.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:12 (8 by maintainers)
Top Results From Across the Web
Why doesn't my before() hook in Mocha run at all?
It is not printed because before is run before a test, and you don't have any. Try add a test then it should...
Read more >[bug] after all hooks run before after create/get/... hooks #533
Application level after hooks always run last. It's only when registering all hooks in the same object. Maybe the all key should just...
Read more >[SpecFlow] Logging problems in Feature Hooks
We use the `dotnet` command to run the tests. Only logs related to the Scenario are displayed properly. I tried the classic Console.WriteLine(), ......
Read more >Logger disabled in shutdown hook thread
Hi, all, In a shutdown hook thread, i want to keep a log using jdk1.4's logging class as following: public void run(){ synchronized(this){...
Read more >wp_enqueue_script() | Function
Script Name Handle Script version License
Image Cropper Image cropper (not used in core, see jcrop)
Jcrop jcrop 0.9.12 MIT
SWFObject swfobject 2.2‑20120417 MIT
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sindresorhus Hello! Can I give it a go?
+1 to prioritizing this request