Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

refactor tests which rely on TTY support

Craig Taub2b4eb7c7a2ae
diff --git a/test/reporters/nyan.spec.js b/test/reporters/nyan.spec.js
index 7e7ebb67..e9b7e0ce 100644
--- a/test/reporters/nyan.spec.js
+++ b/test/reporters/nyan.spec.js
@@ -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();
@@ -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;
});
});
});
@@ -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);
});