-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add busy indicator to mini reporter #599
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
06289da
Add busy indicator to mini reporter. Fixes #598.
jamestalmage 7d4b099
incorporate PR feedback.
jamestalmage 4583bcd
add some additional mini reporter tests
jamestalmage b32c813
mini reporter should display pass/fail counts on separate lines
jamestalmage d2739df
add all counts to mini-reporter live update
jamestalmage 08d1a66
move spinner over one space
jamestalmage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,13 +3,21 @@ var cliCursor = require('cli-cursor'); | |
| var lastLineTracker = require('last-line-stream/tracker'); | ||
| var StringDecoder = require('string_decoder').StringDecoder; | ||
| var plur = require('plur'); | ||
| var spinners = require('cli-spinners'); | ||
| var chalk = require('chalk'); | ||
| var colors = require('../colors'); | ||
|
|
||
| function MiniReporter() { | ||
| if (!(this instanceof MiniReporter)) { | ||
| return new MiniReporter(); | ||
| } | ||
|
|
||
| var spinnerDef = spinners.dots; | ||
| this.spinnerFrames = spinnerDef.frames.map(function (c) { | ||
| return chalk.gray.dim(c); | ||
| }); | ||
| this.spinnerInterval = spinnerDef.interval; | ||
|
|
||
| this.reset(); | ||
| this.stream = process.stderr; | ||
| this.stringDecoder = new StringDecoder(); | ||
|
|
@@ -18,23 +26,50 @@ function MiniReporter() { | |
| module.exports = MiniReporter; | ||
|
|
||
| MiniReporter.prototype.start = function () { | ||
| return ''; | ||
| var self = this; | ||
| this.interval = setInterval(function () { | ||
| self.spinnerIndex = (self.spinnerIndex + 1) % self.spinnerFrames.length; | ||
| self.write(self.prefix()); | ||
| }, this.spinnerInterval); | ||
| return this.prefix(''); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| }; | ||
|
|
||
| MiniReporter.prototype.reset = function () { | ||
| this.clearInterval(); | ||
| this.passCount = 0; | ||
| this.failCount = 0; | ||
| this.skipCount = 0; | ||
| this.todoCount = 0; | ||
| this.rejectionCount = 0; | ||
| this.exceptionCount = 0; | ||
| this.currentStatus = ''; | ||
| this.currentTest = ''; | ||
| this.statusLineCount = 0; | ||
| this.spinnerIndex = 0; | ||
| this.lastLineTracker = lastLineTracker(); | ||
| }; | ||
|
|
||
| MiniReporter.prototype.spinnerChar = function () { | ||
| return this.spinnerFrames[this.spinnerIndex]; | ||
| }; | ||
|
|
||
| MiniReporter.prototype.clearInterval = function () { | ||
| clearInterval(this.interval); | ||
| this.interval = null; | ||
| }; | ||
|
|
||
| MiniReporter.prototype.test = function (test) { | ||
| var status = ''; | ||
| return this.prefix(this._test(test)); | ||
| }; | ||
|
|
||
| MiniReporter.prototype.prefix = function (str) { | ||
| str = str || this.currentTest; | ||
| this.currentTest = str; | ||
| // The space before the newline is required for proper formatting. (Not sure why). | ||
| return ' \n ' + this.spinnerChar() + ' ' + str; | ||
| }; | ||
|
|
||
| MiniReporter.prototype._test = function (test) { | ||
| var title; | ||
|
|
||
| if (test.todo) { | ||
|
|
@@ -51,18 +86,7 @@ MiniReporter.prototype.test = function (test) { | |
| this.passCount++; | ||
| } | ||
|
|
||
| status += ' ' + title; | ||
| status += '\n\n'; | ||
|
|
||
| if (this.passCount > 0) { | ||
| status += ' ' + colors.pass(this.passCount, 'passed'); | ||
| } | ||
|
|
||
| if (this.failCount > 0) { | ||
| status += ' ' + colors.error(this.failCount, 'failed'); | ||
| } | ||
|
|
||
| return status; | ||
| return title + '\n' + this.reportCounts(); | ||
| }; | ||
|
|
||
| MiniReporter.prototype.unhandledError = function (err) { | ||
|
|
@@ -73,31 +97,38 @@ MiniReporter.prototype.unhandledError = function (err) { | |
| } | ||
| }; | ||
|
|
||
| MiniReporter.prototype.finish = function () { | ||
| var status = '\n'; | ||
| MiniReporter.prototype.reportCounts = function () { | ||
| var status = ''; | ||
|
|
||
| if (this.passCount > 0) { | ||
| status += ' ' + colors.pass(this.passCount, 'passed'); | ||
| status += '\n ' + colors.pass(this.passCount, 'passed'); | ||
| } | ||
|
|
||
| if (this.skipCount > 0) { | ||
| status += ' ' + colors.skip(this.skipCount, 'skipped'); | ||
| status += '\n ' + colors.skip(this.skipCount, 'skipped'); | ||
| } | ||
|
|
||
| if (this.todoCount > 0) { | ||
| status += ' ' + colors.todo(this.todoCount, 'todo'); | ||
| status += '\n ' + colors.todo(this.todoCount, 'todo'); | ||
| } | ||
|
|
||
| if (this.failCount > 0) { | ||
| status += ' ' + colors.error(this.failCount, 'failed'); | ||
| status += '\n ' + colors.error(this.failCount, 'failed'); | ||
| } | ||
|
|
||
| return status.length ? status : '\n'; | ||
| }; | ||
|
|
||
| MiniReporter.prototype.finish = function () { | ||
| this.clearInterval(); | ||
| var status = this.reportCounts(); | ||
|
|
||
| if (this.rejectionCount > 0) { | ||
| status += '\n ' + colors.error(this.rejectionCount, plur('rejection', this.rejectionCount)); | ||
| status += '\n ' + colors.error(this.rejectionCount, plur('rejection', this.rejectionCount)); | ||
| } | ||
|
|
||
| if (this.exceptionCount > 0) { | ||
| status += '\n ' + colors.error(this.exceptionCount, plur('exception', this.exceptionCount)); | ||
| status += '\n ' + colors.error(this.exceptionCount, plur('exception', this.exceptionCount)); | ||
| } | ||
|
|
||
| var i = 0; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
How about using
var dots = require('cli-spinners').dotsabove and just referencingdots.frames/dots.interval?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.
@sindresorhus usually objects to that. I don't have a strong opinion either way.
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.
Also, this way leaves us open to having a command line option to configure your spinner:
then
(I considered waiting until April 1st to post this as a feature request, but I'm pretty sure I would have forgotten by then).