-
-
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
Conversation
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.
You changed the test duration, but the test still don't detect "slow"-ness.
Add another assertion after this line that detects color "bright yellow" of dot.
Change PR title to "fix slow test for dot reporter".
@plroebuck It detected "slow" because duration is 3 and slow is 2. |
These tests seem hinky to begin with. Why was the test duration ever allowed to be
|
That's the reason that we didn't find this issue even if this slow test was meaningless. |
Although I applaud your effort in having tracked this down, I see no point in merging this PR in the name of increased coverage - without meaningful changes, it only helps further mask the underlying problems. |
d21f868
to
114eaf1
Compare
Also, I added a |
function color(type, str) { | ||
return '\u001b[' + Base.colors[type] + 'm' + str + '\u001b[0m'; | ||
} | ||
|
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.
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;
114eaf1
to
10caf9a
Compare
I replaced |
Come to think of it, given: if (test.duration > test.slow()) {
test.speed = 'slow';
} else if (test.duration > test.slow() / 2) {
test.speed = 'medium';
} else {
test.speed = 'fast';
} we could also do this assertion for passing tests. expect(test.speed, 'to equal', 'fast'); |
However, they are not only for speed test. We should check report type, dot in here. |
test/reporters/dot.spec.js
Outdated
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 return a grey dot', function() { | ||
runner = createMockRunner('pass', 'pass', null, null, test); | ||
Dot.call({epilogue: function() {}}, runner); | ||
process.stdout.write = stdoutWrite; |
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.
expect(test.speed, 'to equal', 'fast');
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.
I don't understand what you mean and why we check only speed.
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.
the field is set for pass
events by runner
in Base
ctor; it's the only field set there.
test.speed
assertions are in addition to your stdout
assertions, not in lieu of them.
they should agree though.
test/reporters/dot.spec.js
Outdated
@@ -80,28 +86,38 @@ describe('Dot reporter', function() { | |||
runner = createMockRunner('pass', 'pass', null, null, test); | |||
Dot.call({epilogue: function() {}}, runner); | |||
process.stdout.write = stdoutWrite; |
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.
expect(test.speed, 'to equal', 'fast');
test/reporters/dot.spec.js
Outdated
describe('if test speed is slow', function() { | ||
it('should return a dot', function() { | ||
describe('if test speed is medium', function() { | ||
it('should return a yellow dot', function() { | ||
test.duration = 2; | ||
runner = createMockRunner('pass', 'pass', null, null, test); | ||
Dot.call({epilogue: function() {}}, runner); | ||
process.stdout.write = stdoutWrite; |
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.
expect(test.speed, 'to equal', 'medium');
test/reporters/dot.spec.js
Outdated
test.duration = 3; | ||
runner = createMockRunner('pass', 'pass', null, null, test); | ||
Dot.call({epilogue: function() {}}, runner); | ||
process.stdout.write = stdoutWrite; |
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.
expect(test.speed, 'to equal', 'slow');
test/reporters/dot.spec.js
Outdated
@@ -50,7 +56,7 @@ describe('Dot reporter', function() { | |||
runner = createMockRunner('pending', 'pending'); | |||
Dot.call({epilogue: function() {}}, runner); | |||
process.stdout.write = stdoutWrite; |
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 we're doing stream reassignment after Dot.call()
, why repeat in afterEach()
?
And we should explain why it's being done within test, rather than afterwards.
function runReporter(stubSelf, runner) {
// 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);
};
// 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;
}
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.
I will test what you provide.
test/reporters/dot.spec.js
Outdated
}); | ||
|
||
afterEach(function() { | ||
Base.useColors = useColors; | ||
Base.window.width = windowWidth; | ||
Base.color = color; | ||
process.stdout.write = stdoutWrite; |
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.
runner = undefined;
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.
Did you mean that reset runner
here before every test?
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.
yes. runner recreated per-test. reset ensures you can't forget to do so.
10caf9a
to
3a3c8d7
Compare
I fixed them. |
test/reporters/dot.spec.js
Outdated
beforeEach(function() { | ||
stdout = []; | ||
stdoutWrite = process.stdout.write; | ||
function runReporter(stubSelf, runner) { |
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.
function runReporter(stubSelf, runner, tee) {
test/reporters/dot.spec.js
Outdated
stdoutWrite = process.stdout.write; | ||
function runReporter(stubSelf, runner) { | ||
// 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); |
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 (tee) {
stdoutWrite.call(process.stdout, string, enc, callback);
}
@@ -8,35 +8,50 @@ var createMockRunner = require('./helpers.js').createMockRunner; | |||
|
|||
describe('Dot reporter', function() { | |||
var stdout; |
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.
var showOutput = false;
test/reporters/dot.spec.js
Outdated
}); | ||
|
||
describe('on start', function() { | ||
it('should return a new line', function() { | ||
runner = createMockRunner('start', 'start'); | ||
Dot.call({epilogue: function() {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
runReporter({epilogue: function() {}}, runner); |
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.
Add showOutput
argument to all runReporter
invocations that follow.
runReporter({epilogue: function() {}}, runner, showOutput);
It looked good. But glancing job results on Travis, wondered why we would be displaying the test output (which intermixes with the job "spec" report). So my final requested modification:
Now, debugging a test is still simple, but output is turned off by default. |
var runner; | ||
var useColors; | ||
var windowWidth; | ||
var color; | ||
|
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.
/**
* 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
*/
3a3c8d7
to
16a6fa2
Compare
It is a good idea. |
test/reporters/dot.spec.js
Outdated
}); | ||
|
||
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() { |
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 write a newline"
test/reporters/dot.spec.js
Outdated
@@ -48,18 +73,16 @@ describe('Dot reporter', function() { | |||
}); | |||
it('should return a new line and then a coma', function() { |
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 write a newline followed by a comma"
test/reporters/dot.spec.js
Outdated
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() { |
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 write a comma"
test/reporters/dot.spec.js
Outdated
@@ -78,30 +101,40 @@ describe('Dot reporter', function() { | |||
describe('if test speed is fast', function() { | |||
it('should return a new line and then a dot', function() { |
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 write a newline followed by a dot"
test/reporters/dot.spec.js
Outdated
@@ -119,18 +152,16 @@ describe('Dot reporter', function() { | |||
}); | |||
it('should return a new line and then an exclamation mark', function() { |
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 write a newline followed by an exclamation mark"
test/reporters/dot.spec.js
Outdated
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 return a grey dot', function() { |
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 write a grey dot"
test/reporters/dot.spec.js
Outdated
describe('if test speed is slow', function() { | ||
it('should return a dot', function() { | ||
describe('if test speed is medium', function() { | ||
it('should return a yellow dot', function() { |
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 write a yellow dot"
test/reporters/dot.spec.js
Outdated
}); | ||
}); | ||
describe('if test speed is slow', function() { | ||
it('should return a bright yellow dot', function() { |
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 write a bright yellow dot"
test/reporters/dot.spec.js
Outdated
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() { |
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 write an exclamation mark"
Signed-off-by: Outsider <[email protected]>
16a6fa2
to
9ec5614
Compare
I updated the test names. |
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.
Approved. I think the Dot reporter test specification is now an example to be emulated by the others. Sorry about the constant flow of changes, but after each iteration different things stood out.
Thanks for taking the time to get this fixed properly!
Labels: reporter
, semver-patch
.
LGTM!
On the other hand, I am starting to rethink the design of some of the code in the |
what |
I will merge this if one more core members approved. |
I see. Thank you. |
Description of the Change
Although there is a slow test case for dot reporter,
coverage is missed.
Since slow duration is 2(
slow: function() { return 2; }
) and test duration is 2 (test.duration = 2;
),this test is not check slow test actually.
Alternate Designs
N/A
Why should this be in core?
Tests should be run as intended.