Skip to content

Commit

Permalink
100% list reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaub committed Feb 5, 2017
1 parent 3e2c010 commit 3b9c6c9
Showing 1 changed file with 211 additions and 0 deletions.
211 changes: 211 additions & 0 deletions test/reporters/list.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
'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 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(' ✓ ' + expectedTitle + ': ' + expectedDuration + 'ms\n');

Base.cursor = cachedCursor;
});
});
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();
});
});
});

0 comments on commit 3b9c6c9

Please sign in to comment.