-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix slow test for dot reporter #3486
Merged
Merged
Changes from all commits
Commits
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 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 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 |
---|---|---|
|
@@ -8,35 +8,60 @@ var createMockRunner = require('./helpers.js').createMockRunner; | |
|
||
describe('Dot reporter', function() { | ||
var stdout; | ||
var stdoutWrite; | ||
var runner; | ||
var useColors; | ||
var windowWidth; | ||
var color; | ||
var showOutput = false; | ||
|
||
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. For simplicity of comparison, it might be easier not to be so literal. function speedString(type, str) {
return '##' + type.replace(/ /g, '-') + '_' + str;
};
Base.color = speedString; 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. /**
* Run reporter using stream reassignment to capture output.
*
* @param {Object} stubSelf - Reporter-like stub instance
* @param {Runner} runner - Mock instance
* @param {boolean} [tee=false] - If `true`, echo captured output to screen
*/ |
||
beforeEach(function() { | ||
stdout = []; | ||
stdoutWrite = process.stdout.write; | ||
/** | ||
* Run reporter using stream reassignment to capture output. | ||
* | ||
* @param {Object} stubSelf - Reporter-like stub instance | ||
* @param {Runner} runner - Mock instance | ||
* @param {boolean} [tee=false] - If `true`, echo captured output to screen | ||
*/ | ||
function runReporter(stubSelf, runner, tee) { | ||
// Reassign stream in order to make a copy of all reporter output | ||
var stdoutWrite = process.stdout.write; | ||
process.stdout.write = function(string, enc, callback) { | ||
stdout.push(string); | ||
stdoutWrite.call(process.stdout, string, enc, callback); | ||
if (tee) { | ||
stdoutWrite.call(process.stdout, string, enc, callback); | ||
} | ||
}; | ||
|
||
// Invoke reporter | ||
Dot.call(stubSelf, runner); | ||
|
||
// Revert stream reassignment here so reporter output | ||
// can't be corrupted if any test assertions throw | ||
process.stdout.write = stdoutWrite; | ||
} | ||
|
||
beforeEach(function() { | ||
stdout = []; | ||
useColors = Base.useColors; | ||
windowWidth = Base.window.width; | ||
color = Base.color; | ||
Base.useColors = false; | ||
Base.window.width = 0; | ||
Base.color = function(type, str) { | ||
return type.replace(/ /g, '-') + '_' + str; | ||
}; | ||
}); | ||
|
||
afterEach(function() { | ||
Base.useColors = useColors; | ||
Base.window.width = windowWidth; | ||
process.stdout.write = stdoutWrite; | ||
Base.color = color; | ||
runner = undefined; | ||
}); | ||
|
||
describe('on start', function() { | ||
it('should return a new line', function() { | ||
it('should write a newline', function() { | ||
runner = createMockRunner('start', 'start'); | ||
Dot.call({epilogue: function() {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
runReporter({epilogue: function() {}}, runner, showOutput); | ||
var expectedArray = ['\n']; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
|
@@ -46,20 +71,18 @@ describe('Dot reporter', function() { | |
beforeEach(function() { | ||
Base.window.width = 2; | ||
}); | ||
it('should return a new line and then a coma', function() { | ||
it('should write a newline followed by a comma', function() { | ||
runner = createMockRunner('pending', 'pending'); | ||
Dot.call({epilogue: function() {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedArray = ['\n ', Base.symbols.comma]; | ||
runReporter({epilogue: function() {}}, runner, showOutput); | ||
var expectedArray = ['\n ', 'pending_' + Base.symbols.comma]; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
}); | ||
describe('if window width is equal to or less than 1', function() { | ||
it('should return a coma', function() { | ||
it('should write a comma', function() { | ||
runner = createMockRunner('pending', 'pending'); | ||
Dot.call({epilogue: function() {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedArray = [Base.symbols.comma]; | ||
runReporter({epilogue: function() {}}, runner, showOutput); | ||
var expectedArray = ['pending_' + Base.symbols.comma]; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
}); | ||
|
@@ -76,32 +99,42 @@ describe('Dot reporter', function() { | |
Base.window.width = 2; | ||
}); | ||
describe('if test speed is fast', function() { | ||
it('should return a new line and then a dot', function() { | ||
it('should write a newline followed by a dot', function() { | ||
runner = createMockRunner('pass', 'pass', null, null, test); | ||
Dot.call({epilogue: function() {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedArray = ['\n ', Base.symbols.dot]; | ||
runReporter({epilogue: function() {}}, runner, showOutput); | ||
expect(test.speed, 'to equal', 'fast'); | ||
var expectedArray = ['\n ', 'fast_' + Base.symbols.dot]; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
}); | ||
}); | ||
describe('if window width is equal to or less than 1', function() { | ||
describe('if test speed is fast', function() { | ||
it('should return a dot', function() { | ||
it('should write a grey dot', function() { | ||
runner = createMockRunner('pass', 'pass', null, null, test); | ||
Dot.call({epilogue: function() {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedArray = [Base.symbols.dot]; | ||
runReporter({epilogue: function() {}}, runner, showOutput); | ||
expect(test.speed, 'to equal', 'fast'); | ||
var expectedArray = ['fast_' + Base.symbols.dot]; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
}); | ||
describe('if test speed is slow', function() { | ||
it('should return a dot', function() { | ||
describe('if test speed is medium', function() { | ||
it('should write a yellow dot', function() { | ||
test.duration = 2; | ||
runner = createMockRunner('pass', 'pass', null, null, test); | ||
Dot.call({epilogue: function() {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedArray = [Base.symbols.dot]; | ||
runReporter({epilogue: function() {}}, runner, showOutput); | ||
expect(test.speed, 'to equal', 'medium'); | ||
var expectedArray = ['medium_' + Base.symbols.dot]; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
}); | ||
describe('if test speed is slow', function() { | ||
it('should write a bright yellow dot', function() { | ||
test.duration = 3; | ||
runner = createMockRunner('pass', 'pass', null, null, test); | ||
runReporter({epilogue: function() {}}, runner, showOutput); | ||
expect(test.speed, 'to equal', 'slow'); | ||
var expectedArray = ['bright-yellow_' + Base.symbols.dot]; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
}); | ||
|
@@ -117,20 +150,18 @@ describe('Dot reporter', function() { | |
beforeEach(function() { | ||
Base.window.width = 2; | ||
}); | ||
it('should return a new line and then an exclamation mark', function() { | ||
it('should write a newline followed by an exclamation mark', function() { | ||
runner = createMockRunner('fail', 'fail', null, null, test); | ||
Dot.call({epilogue: function() {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedArray = ['\n ', Base.symbols.bang]; | ||
runReporter({epilogue: function() {}}, runner, showOutput); | ||
var expectedArray = ['\n ', 'fail_' + Base.symbols.bang]; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
}); | ||
describe('if window width is equal to or less than 1', function() { | ||
it('should return an exclamation mark', function() { | ||
it('should write an exclamation mark', function() { | ||
runner = createMockRunner('fail', 'fail', null, null, test); | ||
Dot.call({epilogue: function() {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedArray = [Base.symbols.bang]; | ||
runReporter({epilogue: function() {}}, runner, showOutput); | ||
var expectedArray = ['fail_' + Base.symbols.bang]; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
}); | ||
|
@@ -142,8 +173,7 @@ describe('Dot reporter', function() { | |
var epilogue = function() { | ||
epilogueCalled = true; | ||
}; | ||
Dot.call({epilogue: epilogue}, runner); | ||
process.stdout.write = stdoutWrite; | ||
runReporter({epilogue: epilogue}, runner, showOutput); | ||
expect(epilogueCalled, 'to be', true); | ||
}); | ||
}); | ||
|
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.