-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2691 from craigtaub/reporterCoverageSpec
Increase tests coverage for spec + dot reporters
- Loading branch information
Showing
2 changed files
with
340 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
'use strict'; | ||
|
||
var reporters = require('../../').reporters; | ||
var Dot = reporters.Dot; | ||
var Base = reporters.Base; | ||
|
||
describe('Dot reporter', function () { | ||
var stdout; | ||
var stdoutWrite; | ||
var runner; | ||
var useColors; | ||
var windowWidth; | ||
|
||
beforeEach(function () { | ||
stdout = []; | ||
runner = {}; | ||
stdoutWrite = process.stdout.write; | ||
process.stdout.write = function (string) { | ||
stdout.push(string); | ||
}; | ||
useColors = Base.useColors; | ||
windowWidth = Base.window.width; | ||
Base.useColors = false; | ||
Base.window.width = 0; | ||
}); | ||
|
||
afterEach(function () { | ||
Base.useColors = useColors; | ||
Base.window.width = windowWidth; | ||
}); | ||
|
||
describe('on start', function () { | ||
it('should return a new line', function () { | ||
runner.on = function (event, callback) { | ||
if (event === 'start') { | ||
callback(); | ||
} | ||
}; | ||
Dot.call({epilogue: function () {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedArray = [ | ||
'\n' | ||
]; | ||
stdout.should.deepEqual(expectedArray); | ||
}); | ||
}); | ||
describe('on pending', function () { | ||
describe('if window width is greater than 1', function () { | ||
beforeEach(function () { | ||
Base.window.width = 2; | ||
}); | ||
it('should return a new line and then a coma', function () { | ||
runner.on = function (event, callback) { | ||
if (event === 'pending') { | ||
callback(); | ||
} | ||
}; | ||
Dot.call({epilogue: function () {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedArray = [ | ||
'\n ', | ||
Base.symbols.comma | ||
]; | ||
stdout.should.deepEqual(expectedArray); | ||
}); | ||
}); | ||
describe('if window width is equal to or less than 1', function () { | ||
it('should return a coma', function () { | ||
runner.on = function (event, callback) { | ||
if (event === 'pending') { | ||
callback(); | ||
} | ||
}; | ||
Dot.call({epilogue: function () {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedArray = [ | ||
Base.symbols.comma | ||
]; | ||
stdout.should.deepEqual(expectedArray); | ||
}); | ||
}); | ||
}); | ||
describe('on pass', function () { | ||
describe('if window width is greater than 1', function () { | ||
beforeEach(function () { | ||
Base.window.width = 2; | ||
}); | ||
describe('if test speed is fast', function () { | ||
it('should return a new line and then a dot', function () { | ||
var test = { | ||
duration: 1, | ||
slow: function () { return 2; } | ||
}; | ||
runner.on = function (event, callback) { | ||
if (event === 'pass') { | ||
callback(test); | ||
} | ||
}; | ||
Dot.call({epilogue: function () {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedArray = [ | ||
'\n ', | ||
Base.symbols.dot | ||
]; | ||
stdout.should.deepEqual(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 () { | ||
var test = { | ||
duration: 1, | ||
slow: function () { return 2; } | ||
}; | ||
runner.on = function (event, callback) { | ||
if (event === 'pass') { | ||
callback(test); | ||
} | ||
}; | ||
Dot.call({epilogue: function () {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedArray = [ | ||
Base.symbols.dot | ||
]; | ||
stdout.should.deepEqual(expectedArray); | ||
}); | ||
}); | ||
describe('if test speed is slow', function () { | ||
it('should return a dot', function () { | ||
var test = { | ||
duration: 2, | ||
slow: function () { return 1; } | ||
}; | ||
runner.on = function (event, callback) { | ||
if (event === 'pass') { | ||
callback(test); | ||
} | ||
}; | ||
Dot.call({epilogue: function () {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedArray = [ | ||
Base.symbols.dot | ||
]; | ||
stdout.should.deepEqual(expectedArray); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('on fail', function () { | ||
describe('if window width is greater than 1', function () { | ||
beforeEach(function () { | ||
Base.window.width = 2; | ||
}); | ||
it('should return a new line and then an exclamation mark', function () { | ||
var test = { | ||
test: { | ||
err: 'some error' | ||
} | ||
}; | ||
runner.on = function (event, callback) { | ||
if (event === 'fail') { | ||
callback(test); | ||
} | ||
}; | ||
Dot.call({epilogue: function () {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedArray = [ | ||
'\n ', | ||
Base.symbols.bang | ||
]; | ||
stdout.should.deepEqual(expectedArray); | ||
}); | ||
}); | ||
describe('if window width is equal to or less than 1', function () { | ||
it('should return an exclamation mark', function () { | ||
var test = { | ||
test: { | ||
err: 'some error' | ||
} | ||
}; | ||
runner.on = function (event, callback) { | ||
if (event === 'fail') { | ||
callback(test); | ||
} | ||
}; | ||
Dot.call({epilogue: function () {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedArray = [ | ||
Base.symbols.bang | ||
]; | ||
stdout.should.deepEqual(expectedArray); | ||
}); | ||
}); | ||
}); | ||
describe('on end', function () { | ||
it('should call the epilogue', function () { | ||
runner.on = function (event, callback) { | ||
if (event === 'end') { | ||
callback(); | ||
} | ||
}; | ||
var epilogueCalled = false; | ||
var epilogue = function () { | ||
epilogueCalled = true; | ||
}; | ||
Dot.call({epilogue: epilogue}, runner); | ||
process.stdout.write = stdoutWrite; | ||
epilogueCalled.should.be.true(); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,128 @@ | ||
'use strict'; | ||
|
||
var reporters = require('../../').reporters; | ||
var Spec = reporters.Spec; | ||
var Base = reporters.Base; | ||
|
||
describe('Spec reporter', function () { | ||
var stdout; | ||
var stdoutWrite; | ||
var runner; | ||
var useColors; | ||
|
||
beforeEach(function () { | ||
stdout = []; | ||
runner = {}; | ||
stdoutWrite = process.stdout.write; | ||
process.stdout.write = function (string) { | ||
stdout.push(string); | ||
}; | ||
useColors = Base.useColors; | ||
Base.useColors = false; | ||
}); | ||
|
||
afterEach(function () { | ||
Base.useColors = useColors; | ||
}); | ||
|
||
describe('on suite', function () { | ||
it('should return title', function () { | ||
var expectedTitle = 'expectedTitle'; | ||
var suite = { | ||
title: expectedTitle | ||
}; | ||
runner.on = function (event, callback) { | ||
if (event === 'suite') { | ||
callback(suite); | ||
} | ||
}; | ||
Spec.call({epilogue: function () {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedArray = [ | ||
expectedTitle + '\n' | ||
]; | ||
stdout.should.deepEqual(expectedArray); | ||
}); | ||
}); | ||
describe('on pending', function () { | ||
it('should return title', function () { | ||
var expectedTitle = 'expectedTitle'; | ||
var suite = { | ||
title: expectedTitle | ||
}; | ||
runner.on = function (event, callback) { | ||
if (event === 'pending') { | ||
callback(suite); | ||
} | ||
}; | ||
Spec.call({epilogue: function () {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedArray = [ | ||
' - ' + expectedTitle + '\n' | ||
]; | ||
stdout.should.deepEqual(expectedArray); | ||
}); | ||
}); | ||
describe('on pass', function () { | ||
describe('if test speed is slow', function () { | ||
it('should return expected tick, title and duration', function () { | ||
var expectedTitle = 'expectedTitle'; | ||
var expectedDuration = 2; | ||
var test = { | ||
title: expectedTitle, | ||
duration: expectedDuration, | ||
slow: function () { return 1; } | ||
}; | ||
runner.on = function (event, callback) { | ||
if (event === 'pass') { | ||
callback(test); | ||
} | ||
}; | ||
Spec.call({epilogue: function () {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedString = ' ' + Base.symbols.ok + ' ' + expectedTitle + ' (' + expectedDuration + 'ms)' + '\n'; | ||
stdout[0].should.equal(expectedString); | ||
}); | ||
}); | ||
describe('if test speed is fast', function () { | ||
it('should return expected tick, title and without a duration', function () { | ||
var expectedTitle = 'expectedTitle'; | ||
var expectedDuration = 1; | ||
var test = { | ||
title: expectedTitle, | ||
duration: expectedDuration, | ||
slow: function () { return 2; } | ||
}; | ||
runner.on = function (event, callback) { | ||
if (event === 'pass') { | ||
callback(test); | ||
} | ||
}; | ||
Spec.call({epilogue: function () {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedString = ' ' + Base.symbols.ok + ' ' + expectedTitle + '\n'; | ||
stdout[0].should.equal(expectedString); | ||
}); | ||
}); | ||
}); | ||
describe('on fail', function () { | ||
it('should return title and function count', function () { | ||
var expectedTitle = 'expectedTitle'; | ||
var functionCount = 1; | ||
var test = { | ||
title: expectedTitle | ||
}; | ||
runner.on = function (event, callback) { | ||
if (event === 'fail') { | ||
callback(test); | ||
} | ||
}; | ||
Spec.call({epilogue: function () {}}, runner); | ||
process.stdout.write = stdoutWrite; | ||
var expectedArray = [ | ||
' ' + functionCount + ') ' + expectedTitle + '\n' | ||
]; | ||
stdout.should.deepEqual(expectedArray); | ||
}); | ||
}); | ||
}); |