-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Simplify failure output - fixes #1072 #1234
Simplify failure output - fixes #1072 #1234
Conversation
To clarify, you mean Your current approach means no stack traces are ever shown for errors that come out of the test file. I think that's an issue since users may write helper functions in the test file itself. Instead we should not output the stack when it only contains one line. So this should show the stack trace: const testing = () => {
throw new Error('lol')
}
test('testing', t => {
testing()
}) But this should not: test('another test', t => {
throw new Error('lolol')
}) That's my interpretation of @sindresorhus' comment #1072 (comment). |
I this case (that will produce mi first post output), // test.js
import test from 'ava'
import fn from './lol'
test('asd', t => {
fn()
}) // lol.js
module.exports.testing = () => {
throw new Error('lol')
} I understood your point, actually initially I was thinking to check if the extracted stack trace was only one line, but I didn't know if that single line could contain some other info. |
Yes I think that's the way to go. |
Can I assume that there aren't Ex: // lib/reporters/mini.js finish(runStatus)
// Check also if the stack isn't only the `test Fn` (actually check for one-line stack)
if (test.error.stack && extractStack(test.error.stack).search('\n') > -1) {
status += '\n' + indentString(colors.errorStack(extractStack(test.error.stack)), 2);
} Actually I don't like so much this solution because I'm calling twice the same function and I really need the comment to explain what I'm doing. |
You could assign the stack to a variable: if (test.error.stack) {
const extracted = extractStack(test.error.stack);
if (extracted.includes('\n')) {
status += '\n' + indentString(colors.errorStack(extracted), 2);
}
} |
I have made the change and also added the check to the |
This is the output for the examples I posted in #1234 (comment). Looks good to me! @sindresorhus? |
Looks great! Thank you @LasaleFamine :) |
The idea is to check when the
test.error.source.file
is NOT the same of thetest.file
within theforEach
of the errors.I saw that when I throw an error from another module the
test.file
refers to the module's file and not the file that is running the test.In this case for example if I make this check, I'm able to hide the stack trace.
Waiting for your feedback to move forward!