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 landing, min, tap and list reporters #2701

Merged
merged 7 commits into from Feb 6, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
154 changes: 154 additions & 0 deletions test/reporters/landing.spec.js
@@ -0,0 +1,154 @@
'use strict';

var reporters = require('../../').reporters;
var Landing = reporters.Landing;
var Base = reporters.Base;

describe('Landing reporter', function () {
var stdout;
var stdoutWrite;
var runner;
var useColors;
var windowWidth;
var resetCode = '\u001b[0m';

beforeEach(function () {
stdout = [];
runner = {};
stdoutWrite = process.stdout.write;
process.stdout.write = function (string) {
stdout.push(string);
};
useColors = Base.useColors;
Base.useColors = false;
windowWidth = Base.window.width;
Base.window.width = 1;
});

afterEach(function () {
Base.useColors = useColors;
Base.window.width = windowWidth;
});

describe('on start', function () {
it('should write new lines', function () {
var cachedCursor = Base.cursor;
Base.cursor.hide = function () {};
runner.on = function (event, callback) {
if (event === 'start') {
callback();
}
};
Landing.call({}, runner);

process.stdout.write = stdoutWrite;

stdout[0].should.deepEqual('\n\n\n ');
Base.cursor = cachedCursor;
});

it('should call cursor hide', function () {
var cachedCursor = Base.cursor;
var calledCursorHide = false;
Base.cursor.hide = function () {
calledCursorHide = true;
};
runner.on = function (event, callback) {
if (event === 'start') {
callback();
}
};
Landing.call({}, runner);

process.stdout.write = stdoutWrite;
calledCursorHide.should.be.true();

Base.cursor = cachedCursor;
});
});

describe('on test end', function () {
describe('if test has failed', function () {
it('should write expected landing strip', function () {
var test = {
state: 'failed'
};
runner.on = function (event, callback) {
if (event === 'test end') {
callback(test);
}
};
runner.total = 12;
Landing.call({}, runner);

process.stdout.write = stdoutWrite;

var expectedArray = [
'\u001b[1D\u001b[2A',
' ',
'\n ',
'',
'✈',
'\n',
' ',
resetCode
];
stdout.should.deepEqual(expectedArray);
});
});
describe('if test has not failed', function () {
it('should write expected landing strip', function () {
var test = {
state: 'success'
};
runner.on = function (event, callback) {
if (event === 'test end') {
callback(test);
}
};

Landing.call({}, runner);

process.stdout.write = stdoutWrite;

var expectedArray = [
'\u001b[1D\u001b[2A',
' ',
'\n ',
'',
'✈',
'\n',
' ',
resetCode
];
stdout.should.deepEqual(expectedArray);
});
});
});
describe('on end', function () {
it('should call cursor show and epilogue', function () {
var cachedCursor = Base.cursor;
var calledCursorShow = false;
Base.cursor.show = function () {
calledCursorShow = true;
};
runner.on = function (event, callback) {
if (event === 'end') {
callback();
}
};
var calledEpilogue = false;
Landing.call({
epilogue: function () {
calledEpilogue = true;
}
}, runner);

process.stdout.write = stdoutWrite;
calledEpilogue.should.be.true();
calledCursorShow.should.be.true();

Base.cursor = cachedCursor;
});
});
});
215 changes: 215 additions & 0 deletions test/reporters/list.spec.js
@@ -0,0 +1,215 @@
'use strict';

var reporters = require('../../').reporters;
var List = reporters.List;
var Base = reporters.Base;

describe('List 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 start and test', function () {
it('should write expected new line and title to the console', function () {
var expectedTitle = 'some title';
var test = {
fullTitle: function () {
return expectedTitle;
}
};
runner.on = function (event, callback) {
if (event === 'start') {
callback();
}
if (event === 'test') {
callback(test);
}
};
List.call({epilogue: function () {}}, runner);

process.stdout.write = stdoutWrite;
var startString = '\n';
var testString = ' ' + expectedTitle + ': ';
var expectedArray = [
startString,
testString
];
stdout.should.deepEqual(expectedArray);
});
});
describe('on pending', function () {
it('should write expected title to the console', function () {
var expectedTitle = 'some title';
var test = {
fullTitle: function () {
return expectedTitle;
}
};
runner.on = function (event, callback) {
if (event === 'pending') {
callback(test);
}
};
List.call({epilogue: function () {}}, runner);

process.stdout.write = stdoutWrite;

stdout[0].should.deepEqual(' - ' + expectedTitle + '\n');
});
});
describe('on pass', function () {
it('should call cursor CR', function () {
var calledCursorCR = false;
var cachedCursor = Base.cursor;
Base.cursor.CR = function () {
calledCursorCR = true;
};
var expectedTitle = 'some title';
var expectedDuration = 100;
var test = {
fullTitle: function () {
return expectedTitle;
},
duration: expectedDuration,
slow: function () {}
};
runner.on = function (event, callback) {
if (event === 'pass') {
callback(test);
}
};
List.call({epilogue: function () {}}, runner);

process.stdout.write = stdoutWrite;

calledCursorCR.should.be.true();

Base.cursor = cachedCursor;
});
it('should write expected symbol, title and duration to the console', function () {
var cachedSymbols = Base.symbols;
var expectedOkSymbol = 'OK';
Base.symbols.ok = expectedOkSymbol;
var cachedCursor = Base.cursor;
Base.cursor.CR = function () {};
var expectedTitle = 'some title';
var expectedDuration = 100;
var test = {
fullTitle: function () {
return expectedTitle;
},
duration: expectedDuration,
slow: function () {}
};
runner.on = function (event, callback) {
if (event === 'pass') {
callback(test);
}
};
List.call({epilogue: function () {}}, runner);

process.stdout.write = stdoutWrite;

stdout[0].should.equal(' ' + expectedOkSymbol + ' ' + expectedTitle + ': ' + expectedDuration + 'ms\n');

Base.cursor = cachedCursor;
Base.symbols = cachedSymbols;
});
});
describe('on fail', function () {
it('should call cursor CR', function () {
var calledCursorCR = false;
var cachedCursor = Base.cursor;
Base.cursor.CR = function () {
calledCursorCR = true;
};
var expectedTitle = 'some title';
var expectedDuration = 100;
var test = {
fullTitle: function () {
return expectedTitle;
},
duration: expectedDuration,
slow: function () {}
};
runner.on = function (event, callback) {
if (event === 'fail') {
callback(test);
}
};
List.call({epilogue: function () {}}, runner);

process.stdout.write = stdoutWrite;

calledCursorCR.should.be.true();

Base.cursor = cachedCursor;
});
it('should write expected error number and title', function () {
var cachedCursor = Base.cursor;
var expectedErrorCount = 1;
Base.cursor.CR = function () {};
var expectedTitle = 'some title';
var expectedDuration = 100;
var test = {
fullTitle: function () {
return expectedTitle;
},
duration: expectedDuration,
slow: function () {}
};
runner.on = function (event, callback) {
if (event === 'fail') {
callback(test);
}
};
runner.on = function (event, callback) {
if (event === 'fail') {
callback(test);
}
};
List.call({epilogue: function () {}}, runner);

process.stdout.write = stdoutWrite;

stdout[0].should.equal(' ' + expectedErrorCount + ') ' + expectedTitle + '\n');

Base.cursor = cachedCursor;
});
});

describe('on end', function () {
it('should call epilogue', function () {
var calledEpilogue = false;
runner.on = function (event, callback) {
if (event === 'end') {
callback();
}
};
List.call({
epilogue: function () {
calledEpilogue = true;
}
}, runner);
process.stdout.write = stdoutWrite;

calledEpilogue.should.be.true();
});
});
});