Skip to content

Commit

Permalink
Merge pull request #2691 from craigtaub/reporterCoverageSpec
Browse files Browse the repository at this point in the history
Increase tests coverage for spec + dot reporters
  • Loading branch information
Munter committed Jan 30, 2017
2 parents dca2f00 + 763698c commit 503627c
Show file tree
Hide file tree
Showing 2 changed files with 340 additions and 0 deletions.
212 changes: 212 additions & 0 deletions test/reporters/dot.spec.js
@@ -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();
});
});
});
128 changes: 128 additions & 0 deletions test/reporters/spec.spec.js
@@ -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);
});
});
});

0 comments on commit 503627c

Please sign in to comment.