Skip to content

Commit

Permalink
fix - improvements to helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jmuzsik committed Mar 18, 2018
1 parent d87d749 commit e059142
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 206 deletions.
21 changes: 10 additions & 11 deletions test/reporters/doc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
var reporters = require('../../').reporters;
var Doc = reporters.Doc;

var runnerEvent = require('./helpers.js').runnerEvent;
var createMockRunner = require('./helpers.js').createMockRunner;

describe('Doc reporter', function () {
var stdout;
var stdoutWrite;
var runner;
beforeEach(function () {
stdout = [];
runner = {};
stdoutWrite = process.stdout.write;
process.stdout.write = function (string) {
stdout.push(string);
Expand All @@ -27,7 +26,7 @@ describe('Doc reporter', function () {
title: expectedTitle
};
it('should log html with indents and expected title', function () {
runner.on = runner.once = runnerEvent('suite', 'suite', null, null, suite);
runner = createMockRunner('suite', 'suite', null, null, suite);
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
Expand All @@ -43,7 +42,7 @@ describe('Doc reporter', function () {
title: unescapedTitle
};
expectedTitle = '<div>' + expectedTitle + '</div>';
runner.on = runner.once = runnerEvent('suite', 'suite', null, null, suite);
runner = createMockRunner('suite', 'suite', null, null, suite);
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
Expand All @@ -59,7 +58,7 @@ describe('Doc reporter', function () {
root: true
};
it('should not log any html', function () {
runner.on = runner.once = runnerEvent('suite', 'suite', null, null, suite);
runner = createMockRunner('suite', 'suite', null, null, suite);
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
expect(stdout).to.be.empty();
Expand All @@ -73,7 +72,7 @@ describe('Doc reporter', function () {
root: false
};
it('should log expected html with indents', function () {
runner.on = runner.once = runnerEvent('suite end', 'suite end', null, null, suite);
runner = createMockRunner('suite end', 'suite end', null, null, suite);
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
Expand All @@ -87,7 +86,7 @@ describe('Doc reporter', function () {
root: true
};
it('should not log any html', function () {
runner.on = runner.once = runnerEvent('suite end', 'suite end', null, null, suite);
runner = createMockRunner('suite end', 'suite end', null, null, suite);
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
expect(stdout).to.be.empty();
Expand All @@ -106,7 +105,7 @@ describe('Doc reporter', function () {
}
};
it('should log html with indents and expected title and body', function () {
runner.on = runner.once = runnerEvent('pass', 'pass', null, null, test);
runner = createMockRunner('pass', 'pass', null, null, test);
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
Expand All @@ -123,7 +122,7 @@ describe('Doc reporter', function () {

var expectedEscapedTitle = '<div>' + expectedTitle + '</div>';
var expectedEscapedBody = '<div>' + expectedBody + '</div>';
runner.on = runner.once = runnerEvent('pass', 'pass', null, null, test);
runner = createMockRunner('pass', 'pass', null, null, test);
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
Expand All @@ -146,7 +145,7 @@ describe('Doc reporter', function () {
}
};
it('should log html with indents and expected title, body and error', function () {
runner.on = runner.once = runnerEvent('fail two args', 'fail', null, null, test, expectedError);
runner = createMockRunner('fail two args', 'fail', null, null, test, expectedError);
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
Expand All @@ -166,7 +165,7 @@ describe('Doc reporter', function () {
var expectedEscapedTitle = '<div>' + expectedTitle + '</div>';
var expectedEscapedBody = '<div>' + expectedBody + '</div>';
var expectedEscapedError = '<div>' + expectedError + '</div>';
runner.on = runner.once = runnerEvent('fail two args', 'fail', null, null, test, unescapedError);
runner = createMockRunner('fail two args', 'fail', null, null, test, unescapedError);
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
Expand Down
21 changes: 10 additions & 11 deletions test/reporters/dot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var reporters = require('../../').reporters;
var Dot = reporters.Dot;
var Base = reporters.Base;

var runnerEvent = require('./helpers.js').runnerEvent;
var createMockRunner = require('./helpers.js').createMockRunner;

describe('Dot reporter', function () {
var stdout;
Expand All @@ -15,7 +15,6 @@ describe('Dot reporter', function () {

beforeEach(function () {
stdout = [];
runner = {};
stdoutWrite = process.stdout.write;
process.stdout.write = function (string) {
stdout.push(string);
Expand All @@ -33,7 +32,7 @@ describe('Dot reporter', function () {

describe('on start', function () {
it('should return a new line', function () {
runner.on = runner.once = runnerEvent('start', 'start');
runner = createMockRunner('start', 'start');
Dot.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
Expand All @@ -48,7 +47,7 @@ describe('Dot reporter', function () {
Base.window.width = 2;
});
it('should return a new line and then a coma', function () {
runner.on = runner.once = runnerEvent('pending', 'pending');
runner = createMockRunner('pending', 'pending');
Dot.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
Expand All @@ -60,7 +59,7 @@ describe('Dot reporter', function () {
});
describe('if window width is equal to or less than 1', function () {
it('should return a coma', function () {
runner.on = runner.once = runnerEvent('pending', 'pending');
runner = createMockRunner('pending', 'pending');
Dot.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
Expand All @@ -81,7 +80,7 @@ describe('Dot reporter', function () {
});
describe('if test speed is fast', function () {
it('should return a new line and then a dot', function () {
runner.on = runner.once = runnerEvent('pass', 'pass', null, null, test);
runner = createMockRunner('pass', 'pass', null, null, test);
Dot.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
Expand All @@ -95,7 +94,7 @@ describe('Dot reporter', function () {
describe('if window width is equal to or less than 1', function () {
describe('if test speed is fast', function () {
it('should return a dot', function () {
runner.on = runner.once = runnerEvent('pass', 'pass', null, null, test);
runner = createMockRunner('pass', 'pass', null, null, test);
Dot.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
Expand All @@ -107,7 +106,7 @@ describe('Dot reporter', function () {
describe('if test speed is slow', function () {
it('should return a dot', function () {
test.duration = 2;
runner.on = runner.once = runnerEvent('pass', 'pass', null, null, test);
runner = createMockRunner('pass', 'pass', null, null, test);
Dot.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
Expand All @@ -129,7 +128,7 @@ describe('Dot reporter', function () {
Base.window.width = 2;
});
it('should return a new line and then an exclamation mark', function () {
runner.on = runner.once = runnerEvent('fail', 'fail', null, null, test);
runner = createMockRunner('fail', 'fail', null, null, test);
Dot.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
Expand All @@ -141,7 +140,7 @@ describe('Dot reporter', function () {
});
describe('if window width is equal to or less than 1', function () {
it('should return an exclamation mark', function () {
runner.on = runner.once = runnerEvent('fail', 'fail', null, null, test);
runner = createMockRunner('fail', 'fail', null, null, test);
Dot.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
Expand All @@ -153,7 +152,7 @@ describe('Dot reporter', function () {
});
describe('on end', function () {
it('should call the epilogue', function () {
runner.on = runner.once = runnerEvent('end', 'end');
runner = createMockRunner('end', 'end');
var epilogueCalled = false;
var epilogue = function () {
epilogueCalled = true;
Expand Down
Loading

0 comments on commit e059142

Please sign in to comment.