Skip to content

Commit

Permalink
added test for progress reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaub committed Feb 3, 2017
1 parent d7846b6 commit fd6e979
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/reporters/json-stream.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var reporters = require('../../').reporters;
var JSONStream = reporters.JSONStream;

Expand Down
114 changes: 114 additions & 0 deletions test/reporters/progress.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
'use strict';

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

describe('Progrss reporter', function () {
var stdout;
var stdoutWrite;
var runner;

beforeEach(function () {
stdout = [];
runner = {};
stdoutWrite = process.stdout.write;
process.stdout.write = function (string) {
stdout.push(string);
};
});

describe('on start', function () {
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();
}
};
Progress.call({}, runner);

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

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

describe('on test end', function () {
it('should write expected progress of open and close options', function () {
var calledCursorCR = false;
var cachedCursor = Base.cursor;
var useColors = Base.useColors;
Base.useColors = false;
Base.cursor.CR = function () {
calledCursorCR = true;
};
var windowWidth = Base.window.width;
Base.window.width = 0;

var expectedTotal = 12;
var expectedOpen = 'OpEn';
var expectedClose = 'cLoSe';
var expectedOptions = {
open: expectedOpen,
complete: 'cOmPlEtE',
incomplete: 'iNcOmPlEtE',
close: expectedClose
};
runner.total = expectedTotal;
runner.on = function (event, callback) {
if (event === 'test end') {
callback();
}
};
Progress.call({}, runner, expectedOptions);

process.stdout.write = stdoutWrite;
var expectedArray = [
'\u001b[J',
' ' + expectedOpen,
'',
'',
expectedClose
];
calledCursorCR.should.be.true();
stdout.should.deepEqual(expectedArray);

Base.cursor = cachedCursor;
Base.useColors = useColors;
Base.window.width = windowWidth;
});
});

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;
Progress.call({
epilogue: function () {
calledEpilogue = true;
}
}, runner);

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

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

0 comments on commit fd6e979

Please sign in to comment.