-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Output test execution time #30
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
Conversation
👍 Neat. Code looks good to me. Could there be a way to optionally specify that I want to always show at least millisecond output? |
if (err) { | ||
log.error(title, chalk.red(err.message)); | ||
return; | ||
} | ||
|
||
log.success(title); | ||
log.success(title + ' (' + hrtime(duration) + ')'); |
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.
log.success(title + ' ' + chalk.dim('(' + hrtime(duration) + ')'));
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.
Pushed an update.
Was thinking about doing something like this, but instead only show the time when it passes some kind of threshold, as the number is really only useful for identifying slow tests. Thoughts? |
That's how mocha does it, and it makes sense. I don't care if a test took 200us. I do care if it took 200ms. |
If so, what kind of threshold makes sense? Not interested in adding an option to change it, so it needs to cover most use-cases. |
Duration measured in nanoseconds does not give any valuable information to the developer. It makes sense to display time only for long-running tests, above some threshold. Also, process.hrtime() is not available in browsers, so it would need replacement anyway.
Added code to display test duration only when a threshold (100ms) is reached. If you want, you can easily change it here: 2791234#diff-168726dbe96b3ce427e7fedce31bb0bcR31 |
Looks very good @vdemedes! Can you add a test? |
var threshold = 100; | ||
|
||
if (duration > threshold) { | ||
timeSpent = chalk.dim('(' + prettyMs(duration) + ')'); |
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.
Just remembered that dim
doesn't work everywhere. Can you make it chalk.gray.dim
?
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.
And the below ' '
should be here instead.
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.
Sure, going to add that now.
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.
Pushed an update.
@sindresorhus of course, will add a test for sure |
@sindresorhus Added a test for measuring duration, let me know what you think! |
Excellent work @vdemedes. Keep'em coming! ;) More than happy to receive addition suggestion on how AVA can be better in form of issues or PRs. |
Thank you @sindresorhus, will definitely contribute more! |
Hello Sindre,
This pull request closes issue #14. It measures each test's total execution time (duration) using
process.hrtime()
and then outputs nicely formatted time near test's title:pretty-hrtime module is used for converting
process.hrtime()
result to a human-readable form.Thanks for a great project, will be switching off mocha to ava soon.