-
Notifications
You must be signed in to change notification settings - Fork 1.4k
t.log()
does not work in before/after hooks
#1536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
t.log()
does not work in before/after hooks
// @nowells In case you would be interested in working on this. No worries if not though. |
@sindresorhus Hello! Can I give it a go? |
Go for it @Lifeuser! 👍 |
I took a look at the code and this lines seems to be causing the problem. Lines 35 to 38 in 1cb9d4f
How exactly do we want treat hooks in each reporter? Mini-reporterI guess user should only see logs from failed hooks in mini reporter (correct me please if I'm wrong). So, there are two options:
Tap and VerboseEven in case of only two files it starts to look rather messy for me...
It's only second day that I'm digging in project. |
Ah yikes, this does look quite complicated @Lifeuser! With the The |
My use case is passing a logger that uses import test from 'ava'
import createLogger from '@private/logger'
import Foo from './foo'
// How it works now
test('does bar', t => {
const foo = new Foo({log: createLogger({t})})
const bar = foo.bar()
t.true(bar)
})
// How I would like it to work
test.beforeEach(t => {
t.context.foo = new Foo({log: createLogger({t})})
})
test('does bar', t => {
const bar = t.context.foo.bar()
t.true(bar)
})
// How I have to work around it
test.beforeEach(t => {
t.context.foo = t => new Foo({log: createLogger({t})})
})
test('does bar', t => {
const foo = t.context.foo(t)
const bar = foo.bar()
t.true(bar)
}) |
+1 to prioritizing this request |
Hi @novemberborn ! Can you remove assigned label please, 'cause I'm not actually working on this issue anymore. |
@Lifeuser thanks for the heads up 👍 |
@issuehuntfest has funded $100.00 to this issue. See it on IssueHunt |
@dflupu has submitted a pull request. See it on IssueHunt |
@sindresorhus has rewarded $90.00 to @dflupu. See it on IssueHunt
|
Bug 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:
Test Source
Error Message & Stack Trace
Only the log output from the
test
function appear:Command-Line Arguments
Relevant Links
Environment
The text was updated successfully, but these errors were encountered: