Skip to content
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

Duplicate t.log when test fails #2963

Closed
fcastilloec opened this issue Feb 6, 2022 · 8 comments · Fixed by #3013
Closed

Duplicate t.log when test fails #2963

fcastilloec opened this issue Feb 6, 2022 · 8 comments · Fixed by #3013

Comments

@fcastilloec
Copy link

fcastilloec commented Feb 6, 2022

I'm running ava v4.0.1, without any configuration.

Running the following code, outputs t.log twice on the console. Is there a reason for this?

const test = require('ava');

test('application', (t) => {
  t.fail();
  t.log('1');
});

This is the output:
Selection_003

What I'm expecting to see is the log on the first part (where the test failed) but not on the second part (under the horizontal "line").
From my understanding, the second part of the output should just give details on why the test failed, there's no need to output the logs again.

This is extremely annoying when you're trying to t.log something longer than a couple of lines and your screen is flooded with duplicate text.

@oantoro
Copy link
Contributor

oantoro commented Feb 9, 2022

Yes, I agree. I think the log doesn't need to be printed two times. Or maybe there is any other reason of printing the log with the failure after the test finished? @novemberborn

@novemberborn
Copy link
Member

The logs could be useful for understanding why the test failed though. I wonder if, for failing tests, we shouldn't print them as test results come in but only at the end — and for passing tests we print them along with the passing test (since those are not repeated at the end).

@fcastilloec
Copy link
Author

The logs could be useful for understanding why the test failed though. I wonder if, for failing tests, we shouldn't print them as test results come in but only at the end — and for passing tests we print them along with the passing test (since those are not repeated at the end).

Either way will work, as long as there are no duplicates on failed tests. I would argue that, for consistency, you should only show them along with the test for both passing and failing tests. t.log() messages can be used to debug a failing test but that's not their only function. It'll be better to keep them together with the running test and you can still use them for debugging. The summary at the end can focus only on why the test failed, without cramming extra information that might be unrelated to debugging a failed test.
Implementation is just a personal (or project) preference, which I don't care as much. As previously mentioned, as long as I don't see duplicates, I'm happy 😄

@novemberborn
Copy link
Member

I would argue that, for consistency, you should only show them along with the test for both passing and failing tests. t.log() messages can be used to debug a failing test but that's not their only function. It'll be better to keep them together with the running test and you can still use them for debugging. The summary at the end can focus only on why the test failed, without cramming extra information that might be unrelated to debugging a failed test.

Yea sounds good. PR welcome 😄

@santhoshbala0178
Copy link

@novemberborn I would like to work on this issue if its okay.

@novemberborn
Copy link
Member

@santhoshbala0178 of course!

@santhoshbala0178
Copy link

@novemberborn, Could you please point me to the documentation on how to set up and test the changes locally, if it is possible please.?

@novemberborn
Copy link
Member

Use Node.js 16 or 17, npm install, npm test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants