Skip to content

Commit

Permalink
refactor tests which rely on TTY support
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaub committed Jan 31, 2017
1 parent 5c904e0 commit 2b4eb7c
Showing 1 changed file with 43 additions and 25 deletions.
68 changes: 43 additions & 25 deletions test/reporters/nyan.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,17 @@ describe('Nyon reporter', function () {
epilogue: function () {}
}, runner);

stdout.shift();
var arrayWithoutShow = stdout;
var arrayOfNewlines = stdout.filter(function (value) { return value === '\n'; });
process.stdout.write = stdoutWrite;
arrayWithoutShow.should.have.length(expectedNumberOfLines);

arrayOfNewlines.should.have.length(expectedNumberOfLines);
});
it('should write cursor interaction for show', function () {
var expectedShowInteraction = '\u001b[?25h';
it('should call Base show', function () {
var showCalled = false;
var cachedShow = Base.cursor.show;
Base.cursor.show = function () {
showCalled = true;
};
runner.on = function (event, callback) {
if (event === 'end') {
callback();
Expand All @@ -153,7 +157,8 @@ describe('Nyon reporter', function () {
}, runner);

process.stdout.write = stdoutWrite;
stdout[0].should.equal(expectedShowInteraction);
showCalled.should.be.true();
Base.cursor.show = cachedShow;
});
});
});
Expand All @@ -175,33 +180,46 @@ describe('Nyon reporter', function () {
var nyanCat = new NyanCat({on: function () {}});
nyanCat.stats = { passes: 2, pending: 1, failures: 0 };

nyanCat.draw.call({
tick: false,
appendRainbow: function () {},
rainbowify: function () {},
drawScoreboard: function () {},
drawRainbow: function () {},
drawNyanCat: NyanCat.prototype.drawNyanCat,
scoreboardWidth: 0,
trajectories: [[]],
face: function () {},
cursorUp: function () {}
});

nyanCat.draw();
process.stdout.write = stdoutWrite;
var expectedArray = [
'\u001b[0C',
' ',
'\u001b[32m2\u001b[0m',
'\n',
' ',
'\u001b[31m0\u001b[0m',
'\n',
' ',
'\u001b[36m1\u001b[0m',
'\n',
'\n',
'\u001b[4A',
'\u001b[5C',
'\u001b[38;5;154m-\u001b[0m',
'\n',
'\u001b[5C',
'\u001b[38;5;154m-\u001b[0m',
'\n',
'\u001b[5C',
'\u001b[38;5;154m-\u001b[0m',
'\n',
'\u001b[5C',
'\u001b[38;5;154m-\u001b[0m',
'\n',
'\u001b[4A',
'\u001b[6C',
'_,------,',
'\n',
'\u001b[0C',
'\u001b[6C',
'_| /\\_/\\ ',
'\n',
'\u001b[0C',
'^|__undefined ',
'\u001b[6C',
'^|__( o .o) ',
'\n',
'\u001b[0C',
'\u001b[6C',
' "" "" ',
'\n'
'\n',
'\u001b[4A'
];
stdout.should.deepEqual(expectedArray);
});
Expand Down

0 comments on commit 2b4eb7c

Please sign in to comment.