-
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
Add support for test logging #1452
Conversation
if (test.error) { | ||
return ' ' + colors.error(figures.cross) + ' ' + test.title + ' ' + colors.error(test.error.message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole stream of changes looks more noisy than it is. This is simply switching from an immediate return
approach to appending to a lines.push
approach so that we can concatinate comments
after the test summary.
@novemberborn thanks for the review! I will:
I should hopefully have this up to you for review by the end of the day. Cheers! |
@novemberborn let me know if my rework looks good, and if you think there are other types of tests that I should add. Thanks! |
@nowells Can you document it in the readme? |
How would that work? The comments would need context. |
Absolutely! Done.
The way I implemented it, in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is almost there @nowells. Awesome work!
lib/reporters/tap.js
Outdated
const appendLogs = () => { | ||
if (test.logs) { | ||
test.logs.forEach(log => { | ||
output.push(` ${log}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If log
contains linebreaks, should the indentation apply on those new lines? If so, this should use https://www.npmjs.com/package/indent-string (like elsewhere in the reporters). May not be a bad idea to use that anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should the indentation apply on those new lines?
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I'm going to make it so that it will result in something like this, where I add the i
figure to the first line.
✔ file-one › passing test
ℹ a comment for passing test
with a newline
ℹ a comment for passing test without a newline
lib/reporters/verbose.js
Outdated
|
||
if (test.logs) { | ||
test.logs.forEach(log => { | ||
output += ' ' + colors.information(figures.info) + ' ' + colors.log(log) + '\n'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question here around linebreaks in the log
value.
readme.md
Outdated
@@ -875,6 +875,10 @@ Plan how many assertion there are in the test. The test will fail if the actual | |||
|
|||
End the test. Only works with `test.cb()`. | |||
|
|||
###### `t.log(message)` | |||
|
|||
Print a log message contextually alongside the test result instead of immediately streaming the message to stdout like `console.log`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Along the lines of https://nodejs.org/api/console.html#console_console_log_data_args, perhaps:
Print a log message contextually alongside the test result instead of immediately printing it to
stdout
likeconsole.log
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There are times when you wish to include comments in your tests that will be shown in context of the test result and not streamed to stdout like console.log statements are.
* [x] Switched from `t.comment` to `t.log` * [x] Added mini reporter comments on failure. * [x] Added tests.
Added indentString support. Fixed up readme.
The tests that are failing appear to be failing on master as well? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nowells sorry for the delay. This looks good, though I think you should avoid rewriting the indent-string
output. Luckily the indent
value can be customized, so with some creative use of its API we can avoid the rewriting.
const logLinesWithLeadingFigure = logLines.replace( | ||
/^ {6}/, | ||
` ${colors.information(figures.info)} ` | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be better as:
const logLines = indentString(colors.log(log), 1, {
indent: ` ${colors.information(figures.info)} `,
includeEmptyLines: true
});
(Though that indent
value should probably be a constant, but feel free to redeclare it in the verbose
logger.)
See indent-string
's API. Including empty lines would be good given the figure prefix.
You'll have to update the indent-string
dependency to 3.2.0
since the includeEmptyLines
feature is pretty new.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@novemberborn the reason I didn't do that was I only wanted to i
symbol to show up once per log line (to indicate where a log message starts)
* this is a message that will have multiple lines, but there only the first line
will have the `*` to indicate a log message, and the indent of the other lines
is at the indent level of the first log message (after the `*`)
* Some other log message
Does that make sense? Or would you rather it be
* this is a message that will have multiple lines, but there only the first line
* will have the `*` to indicate a log message, and the indent of the other lines
* is at the indent level of the first log message (after the `*`)
* Some other log message, but how do I know that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! No that's fine, I misread the code.
I suppose the replacement string could be a constant, but on the other hand it's clearer if it's near the indentation values. So hey :)
I'm hoping #1477 fixes that. |
thanks for the great feedback and guiding me through this @novemberborn! |
Thanks for working on this @nowells 🙌 |
@sindresorhus thanks for making such a wonderful testing system!!! I look forward to helping out on other features as well. ❤️ |
There are times when you wish to include comments in your tests that will be shown in the context of the test result, and not streamed to `stdout` like `console.log` statements are. Fixes #420.
There are times when you wish to include comments in your tests that will be shown in context of the test result and not streamed to
stdout
likeconsole.log
statements are, where they will likely be out of order of the tests they are associated with.I will happily add tests, and change the API, etc. I just want to get general 👍 or 👎 to the concept of adding comments before I flesh out the tests and other cleanup.
One of the main use cases I have for this, is I am using ava as a runner for my SauceLabs/BrowserSrack/Selenium tests, and I would like to have the link to the job results from SauceLabs/BrowserStack be output in context with the test run. There are certainly many other usecases for this, however, just to give a relevant example of when this is useful.
Example output
--verbose
--tap