Skip to content
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

Increase tests coverage for spec + dot reporters #2691

Merged
merged 3 commits into from
Jan 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 212 additions & 0 deletions test/reporters/dot.spec.js
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();
});
});
});
128 changes: 128 additions & 0 deletions test/reporters/spec.spec.js
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);
});
});
});