From e05914266c25248105fa9d4bfbaa13d1488d202d Mon Sep 17 00:00:00 2001 From: jmuzsik Date: Sun, 18 Mar 2018 18:19:52 -0400 Subject: [PATCH] fix - improvements to helper functions --- test/reporters/doc.spec.js | 21 ++- test/reporters/dot.spec.js | 21 ++- test/reporters/helpers.js | 201 ++++++++++++++++------------- test/reporters/json-stream.spec.js | 42 +++--- test/reporters/landing.spec.js | 13 +- test/reporters/list.spec.js | 17 ++- test/reporters/markdown.spec.js | 7 +- test/reporters/min.spec.js | 7 +- test/reporters/nyan.spec.js | 17 ++- test/reporters/progress.spec.js | 11 +- test/reporters/spec.spec.js | 21 +-- test/reporters/tap.spec.js | 18 +-- 12 files changed, 190 insertions(+), 206 deletions(-) diff --git a/test/reporters/doc.spec.js b/test/reporters/doc.spec.js index 1005b25121..4f3b48868a 100644 --- a/test/reporters/doc.spec.js +++ b/test/reporters/doc.spec.js @@ -3,7 +3,7 @@ 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; @@ -11,7 +11,6 @@ describe('Doc reporter', function () { var runner; beforeEach(function () { stdout = []; - runner = {}; stdoutWrite = process.stdout.write; process.stdout.write = function (string) { stdout.push(string); @@ -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 = [ @@ -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 = [ @@ -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(); @@ -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 = [ @@ -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(); @@ -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 = [ @@ -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 = [ @@ -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 = [ @@ -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 = [ diff --git a/test/reporters/dot.spec.js b/test/reporters/dot.spec.js index 749bb08810..228487ff0d 100644 --- a/test/reporters/dot.spec.js +++ b/test/reporters/dot.spec.js @@ -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; @@ -15,7 +15,6 @@ describe('Dot reporter', function () { beforeEach(function () { stdout = []; - runner = {}; stdoutWrite = process.stdout.write; process.stdout.write = function (string) { stdout.push(string); @@ -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 = [ @@ -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 = [ @@ -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 = [ @@ -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 = [ @@ -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 = [ @@ -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 = [ @@ -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 = [ @@ -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 = [ @@ -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; diff --git a/test/reporters/helpers.js b/test/reporters/helpers.js index cb6fd75010..b4b24e1ca0 100644 --- a/test/reporters/helpers.js +++ b/test/reporters/helpers.js @@ -2,100 +2,112 @@ /* This function prevents the constant use of creating a runnerEvent. - runStr is the argument that solely defines the runnerEvent. + runStr is the argument that defines the runnerEvent. ifStr1 is one possible reporter argument, as is ifStr2, and ifStr3 - arg1 and arg2 are the possible variables that need to be put into the scope of this function for the tests to run properly. + arg1 and arg2 are the possible variables that need to be put into the + scope of this function for the tests to run properly. */ -function runnerEvent (runStr, ifStr1, ifStr2, ifStr3, arg1, arg2) { + +function createMockRunner (runStr, ifStr1, ifStr2, ifStr3, arg1, arg2) { + var runnerFunction = createRunnerFunction(runStr, ifStr1, ifStr2, ifStr3, arg1, arg2); + return { + on: runnerFunction, + once: runnerFunction + }; +} + +function createRunnerFunction (runStr, ifStr1, ifStr2, ifStr3, arg1, arg2) { var test = null; - if (runStr === 'start' || runStr === 'pending' || runStr === 'end') { - return function (event, callback) { - if (event === ifStr1) { - callback(); - } - }; - } else if ( - runStr === 'pending test' || - runStr === 'pass' || - runStr === 'fail' || - runStr === 'end' || - runStr === 'suite' || - runStr === 'suite end' || - runStr === 'test end' - ) { - test = arg1; - return function (event, callback) { - if (event === ifStr1) { - callback(test); - } - }; - } else if (runStr === 'fail two args') { - test = arg1; - var expectedError = arg2; - return function (event, callback) { - if (event === ifStr1) { - callback(test, expectedError); - } - }; - } else if (runStr === 'start test') { - test = arg1; - return function (event, callback) { - if (event === ifStr1) { - callback(); - } - if (event === ifStr2) { - callback(test); - } - }; - } else if (runStr === 'suite suite end') { - var expectedSuite = arg1; - return function (event, callback) { - if (event === ifStr1) { - callback(expectedSuite); - } - if (event === ifStr2) { - callback(); - } - if (event === ifStr3) { - callback(); - } - }; - } else if (runStr === 'pass end') { - test = arg1; - return function (event, callback) { - if (event === ifStr1) { - callback(test); - } - if (event === ifStr2) { - callback(); - } - }; - } else if (runStr === 'test end fail') { - test = arg1; - var error = arg2; - return function (event, callback) { - if (event === ifStr1) { - callback(); - } - if (event === ifStr2) { - callback(test, error); - } - }; - } else if (runStr === 'fail end pass') { - return function (event, callback) { + switch (runStr) { + case 'start': + case 'pending': + case 'end': + return function (event, callback) { + if (event === ifStr1) { + callback(); + } + }; + case 'pending test': + case 'pass': + case 'fail': + case 'suite': + case 'suite end': + case 'test end': + test = arg1; + return function (event, callback) { + if (event === ifStr1) { + callback(test); + } + }; + case 'fail two args': + test = arg1; + var expectedError = arg2; + return function (event, callback) { + if (event === ifStr1) { + callback(test, expectedError); + } + }; + case 'start test': + test = arg1; + return function (event, callback) { + if (event === ifStr1) { + callback(); + } + if (event === ifStr2) { + callback(test); + } + }; + case 'suite suite end': + var expectedSuite = arg1; + return function (event, callback) { + if (event === ifStr1) { + callback(expectedSuite); + } + if (event === ifStr2) { + callback(); + } + if (event === ifStr3) { + callback(); + } + }; + case 'pass end': + test = arg1; + return function (event, callback) { + if (event === ifStr1) { + callback(test); + } + if (event === ifStr2) { + callback(); + } + }; + case 'test end fail': test = arg1; - if (event === ifStr1) { - callback(test, {}); - } - if (event === ifStr2) { - callback(test); - } - if (event === ifStr3) { - callback(test); - } - }; - } else { - throw new Error('This function does not support the runner string specified.'); + var error = arg2; + return function (event, callback) { + if (event === ifStr1) { + callback(); + } + if (event === ifStr2) { + callback(test, error); + } + }; + case 'fail end pass': + return function (event, callback) { + test = arg1; + if (event === ifStr1) { + callback(test, {}); + } + if (event === ifStr2) { + callback(test); + } + if (event === ifStr3) { + callback(test); + } + }; + default: + throw new Error( + 'This function does not support the runner string specified.' + ); } } @@ -110,7 +122,7 @@ function makeTest (err) { function createElements (argObj) { var res = []; - for (var i = argObj.from; i <= argObj.to; i += 1) { + for (var i = argObj.from; i <= argObj.to; i++) { res.push('element ' + i); } return res; @@ -136,4 +148,9 @@ function makeExpectedTest ( }; } -module.exports = { runnerEvent, makeTest, createElements, makeExpectedTest }; +module.exports = { + createMockRunner, + makeTest, + createElements, + makeExpectedTest +}; diff --git a/test/reporters/json-stream.spec.js b/test/reporters/json-stream.spec.js index 062fabdd12..0d11597038 100644 --- a/test/reporters/json-stream.spec.js +++ b/test/reporters/json-stream.spec.js @@ -3,7 +3,7 @@ var reporters = require('../../').reporters; var JSONStream = reporters.JSONStream; -var runnerEvent = require('./helpers').runnerEvent; +var createMockRunner = require('./helpers').createMockRunner; var makeExpectedTest = require('./helpers').makeExpectedTest; describe('Json Stream reporter', function () { @@ -11,38 +11,28 @@ describe('Json Stream reporter', function () { var stdout; var stdoutWrite; - var expectedTitle; - var expectedFullTitle; - var expectedDuration; - var currentRetry; - var expectedTest; - var expectedErrorMessage; - var expectedErrorStack; - var expectedError; + var expectedTitle = 'some title'; + var expectedFullTitle = 'full title'; + var expectedDuration = 1000; + var currentRetry = 1; + var expectedTest = makeExpectedTest(expectedTitle, expectedFullTitle, expectedDuration, currentRetry); + var expectedErrorMessage = 'error message'; + var expectedErrorStack = 'error stack'; + var expectedError = { + message: expectedErrorMessage + }; beforeEach(function () { stdout = []; - runner = {}; stdoutWrite = process.stdout.write; process.stdout.write = function (string) { stdout.push(string); }; - - expectedTitle = 'some title'; - expectedFullTitle = 'full title'; - expectedDuration = 1000; - currentRetry = 1; - expectedTest = makeExpectedTest(expectedTitle, expectedFullTitle, expectedDuration, currentRetry); - expectedErrorMessage = 'error message'; - expectedErrorStack = 'error stack'; - expectedError = { - message: expectedErrorMessage - }; }); describe('on start', function () { it('should write stringified start with expected total', function () { - runner.on = runner.once = runnerEvent('start', 'start'); + runner = createMockRunner('start', 'start'); var expectedTotal = 12; runner.total = expectedTotal; JSONStream.call({}, runner); @@ -55,7 +45,7 @@ describe('Json Stream reporter', function () { describe('on pass', function () { it('should write stringified test data', function () { - runner.on = runner.once = runnerEvent('pass', 'pass', null, null, expectedTest); + runner = createMockRunner('pass', 'pass', null, null, expectedTest); JSONStream.call({}, runner); process.stdout.write = stdoutWrite; @@ -68,7 +58,7 @@ describe('Json Stream reporter', function () { describe('if error stack exists', function () { it('should write stringified test data with error data', function () { expectedError.stack = expectedErrorStack; - runner.on = runner.once = runnerEvent('fail two args', 'fail', null, null, expectedTest, expectedError); + runner = createMockRunner('fail two args', 'fail', null, null, expectedTest, expectedError); JSONStream.call({}, runner); @@ -81,7 +71,7 @@ describe('Json Stream reporter', function () { describe('if error stack does not exist', function () { it('should write stringified test data with error data', function () { expectedError.stack = null; - runner.on = runner.once = runnerEvent('fail two args', 'fail', null, null, expectedTest, expectedError); + runner = createMockRunner('fail two args', 'fail', null, null, expectedTest, expectedError); JSONStream.call({}, runner); process.stdout.write = stdoutWrite; @@ -93,7 +83,7 @@ describe('Json Stream reporter', function () { describe('on end', function () { it('should write end details', function () { - runner.on = runner.once = runnerEvent('end', 'end'); + runner = createMockRunner('end', 'end'); JSONStream.call({}, runner); process.stdout.write = stdoutWrite; expect(stdout[0]).to.match(/end/); diff --git a/test/reporters/landing.spec.js b/test/reporters/landing.spec.js index 834a2efb2f..633c29e823 100644 --- a/test/reporters/landing.spec.js +++ b/test/reporters/landing.spec.js @@ -4,7 +4,7 @@ var reporters = require('../../').reporters; var Landing = reporters.Landing; var Base = reporters.Base; -var runnerEvent = require('./helpers').runnerEvent; +var createMockRunner = require('./helpers').createMockRunner; describe('Landing reporter', function () { var stdout; @@ -26,7 +26,6 @@ describe('Landing reporter', function () { beforeEach(function () { stdout = []; - runner = {}; stdoutWrite = process.stdout.write; process.stdout.write = function (string) { stdout.push(string); @@ -46,7 +45,7 @@ describe('Landing reporter', function () { it('should write new lines', function () { var cachedCursor = Base.cursor; Base.cursor.hide = function () {}; - runner.on = runner.once = runnerEvent('start', 'start'); + runner = createMockRunner('start', 'start'); Landing.call({}, runner); process.stdout.write = stdoutWrite; @@ -61,7 +60,7 @@ describe('Landing reporter', function () { Base.cursor.hide = function () { calledCursorHide = true; }; - runner.on = runner.once = runnerEvent('start', 'start'); + runner = createMockRunner('start', 'start'); Landing.call({}, runner); process.stdout.write = stdoutWrite; @@ -77,7 +76,7 @@ describe('Landing reporter', function () { var test = { state: 'failed' }; - runner.on = runner.once = runnerEvent('test end', 'test end', null, null, test); + runner = createMockRunner('test end', 'test end', null, null, test); runner.total = 12; Landing.call({}, runner); @@ -91,7 +90,7 @@ describe('Landing reporter', function () { var test = { state: 'success' }; - runner.on = runner.once = runnerEvent('test end', 'test end', null, null, test); + runner = createMockRunner('test end', 'test end', null, null, test); Landing.call({}, runner); @@ -108,7 +107,7 @@ describe('Landing reporter', function () { Base.cursor.show = function () { calledCursorShow = true; }; - runner.on = runner.once = runnerEvent('end', 'end'); + runner = createMockRunner('end', 'end'); var calledEpilogue = false; Landing.call({ diff --git a/test/reporters/list.spec.js b/test/reporters/list.spec.js index 73ab11afde..7871caf82e 100644 --- a/test/reporters/list.spec.js +++ b/test/reporters/list.spec.js @@ -4,7 +4,7 @@ var reporters = require('../../').reporters; var List = reporters.List; var Base = reporters.Base; -var runnerEvent = require('./helpers').runnerEvent; +var createMockRunner = require('./helpers').createMockRunner; describe('List reporter', function () { var stdout; @@ -22,7 +22,6 @@ describe('List reporter', function () { }; beforeEach(function () { stdout = []; - runner = {}; stdoutWrite = process.stdout.write; process.stdout.write = function (string) { stdout.push(string); @@ -37,7 +36,7 @@ describe('List reporter', function () { describe('on start and test', function () { it('should write expected new line and title to the console', function () { - runner.on = runner.once = runnerEvent('start test', 'start', 'test', null, test); + runner = createMockRunner('start test', 'start', 'test', null, test); List.call({epilogue: function () {}}, runner); process.stdout.write = stdoutWrite; @@ -52,7 +51,7 @@ describe('List reporter', function () { }); describe('on pending', function () { it('should write expected title to the console', function () { - runner.on = runner.once = runnerEvent('pending test', 'pending', null, null, test); + runner = createMockRunner('pending test', 'pending', null, null, test); List.call({epilogue: function () {}}, runner); process.stdout.write = stdoutWrite; @@ -67,7 +66,7 @@ describe('List reporter', function () { Base.cursor.CR = function () { calledCursorCR = true; }; - runner.on = runner.once = runnerEvent('pass', 'pass', null, null, test); + runner = createMockRunner('pass', 'pass', null, null, test); List.call({epilogue: function () {}}, runner); process.stdout.write = stdoutWrite; @@ -82,7 +81,7 @@ describe('List reporter', function () { Base.symbols.ok = expectedOkSymbol; var cachedCursor = Base.cursor; Base.cursor.CR = function () {}; - runner.on = runner.once = runnerEvent('pass', 'pass', null, null, test); + runner = createMockRunner('pass', 'pass', null, null, test); List.call({epilogue: function () {}}, runner); process.stdout.write = stdoutWrite; @@ -100,7 +99,7 @@ describe('List reporter', function () { Base.cursor.CR = function () { calledCursorCR = true; }; - runner.on = runner.once = runnerEvent('fail', 'fail', null, null, test); + runner = createMockRunner('fail', 'fail', null, null, test); List.call({epilogue: function () {}}, runner); process.stdout.write = stdoutWrite; @@ -113,7 +112,7 @@ describe('List reporter', function () { var cachedCursor = Base.cursor; var expectedErrorCount = 1; Base.cursor.CR = function () {}; - runner.on = runner.once = runnerEvent('fail', 'fail', null, null, test); + runner = createMockRunner('fail', 'fail', null, null, test); List.call({epilogue: function () {}}, runner); process.stdout.write = stdoutWrite; @@ -149,7 +148,7 @@ describe('List reporter', function () { describe('on end', function () { it('should call epilogue', function () { var calledEpilogue = false; - runner.on = runner.once = runnerEvent('end', 'end'); + runner = createMockRunner('end', 'end'); List.call({ epilogue: function () { calledEpilogue = true; diff --git a/test/reporters/markdown.spec.js b/test/reporters/markdown.spec.js index 18fd218a60..f6fcf095e0 100644 --- a/test/reporters/markdown.spec.js +++ b/test/reporters/markdown.spec.js @@ -3,7 +3,7 @@ var reporters = require('../../').reporters; var Markdown = reporters.Markdown; -var runnerEvent = require('./helpers').runnerEvent; +var createMockRunner = require('./helpers').createMockRunner; describe('Markdown reporter', function () { var stdout; @@ -15,7 +15,6 @@ describe('Markdown reporter', function () { beforeEach(function () { stdout = []; - runner = {}; stdoutWrite = process.stdout.write; process.stdout.write = function (string) { stdout.push(string); @@ -33,7 +32,7 @@ describe('Markdown reporter', function () { suites: [] }] }; - runner.on = runner.once = runnerEvent('suite suite end', 'suite', 'suite end', 'end', expectedSuite); + runner = createMockRunner('suite suite end', 'suite', 'suite end', 'end', expectedSuite); runner.suite = expectedSuite; Markdown.call({}, runner); process.stdout.write = stdoutWrite; @@ -65,7 +64,7 @@ describe('Markdown reporter', function () { slow: function () {}, body: expectedBody }; - runner.on = runner.once = runnerEvent('pass end', 'pass', 'end', null, expectedTest); + runner = createMockRunner('pass end', 'pass', 'end', null, expectedTest); runner.suite = expectedSuite; Markdown.call({}, runner); process.stdout.write = stdoutWrite; diff --git a/test/reporters/min.spec.js b/test/reporters/min.spec.js index 747ff1049d..1312e21ea8 100644 --- a/test/reporters/min.spec.js +++ b/test/reporters/min.spec.js @@ -3,7 +3,7 @@ var reporters = require('../../').reporters; var Min = reporters.Min; -var runnerEvent = require('./helpers').runnerEvent; +var createMockRunner = require('./helpers').createMockRunner; describe('Min reporter', function () { var stdout; @@ -12,7 +12,6 @@ describe('Min reporter', function () { beforeEach(function () { stdout = []; - runner = {}; stdoutWrite = process.stdout.write; process.stdout.write = function (string) { stdout.push(string); @@ -21,7 +20,7 @@ describe('Min reporter', function () { describe('on start', function () { it('should clear screen then set cursor position', function () { - runner.on = runner.once = runnerEvent('start', 'start'); + runner = createMockRunner('start', 'start'); Min.call({epilogue: function () {}}, runner); process.stdout.write = stdoutWrite; @@ -36,7 +35,7 @@ describe('Min reporter', function () { describe('on end', function () { it('should call epilogue', function () { var calledEpilogue = false; - runner.on = runner.once = runnerEvent('end', 'end'); + runner = createMockRunner('end', 'end'); Min.call({ epilogue: function () { calledEpilogue = true; diff --git a/test/reporters/nyan.spec.js b/test/reporters/nyan.spec.js index 0834363b33..43e8c778e1 100644 --- a/test/reporters/nyan.spec.js +++ b/test/reporters/nyan.spec.js @@ -4,7 +4,7 @@ var reporters = require('../../').reporters; var NyanCat = reporters.Nyan; var Base = reporters.Base; -var runnerEvent = require('./helpers').runnerEvent; +var createMockRunner = require('./helpers').createMockRunner; describe('Nyan reporter', function () { describe('events', function () { @@ -15,7 +15,6 @@ describe('Nyan reporter', function () { beforeEach(function () { stdout = []; - runner = {}; stdoutWrite = process.stdout.write; process.stdout.write = function (string) { stdout.push(string); @@ -25,7 +24,7 @@ describe('Nyan reporter', function () { describe('on start', function () { it('should call draw', function () { calledDraw = false; - runner.on = runner.once = runnerEvent('start', 'start'); + runner = createMockRunner('start', 'start'); NyanCat.call({ draw: function () { calledDraw = true; @@ -40,7 +39,7 @@ describe('Nyan reporter', function () { describe('on pending', function () { it('should call draw', function () { calledDraw = false; - runner.on = runner.once = runnerEvent('pending', 'pending'); + runner = createMockRunner('pending', 'pending'); NyanCat.call({ draw: function () { calledDraw = true; @@ -59,7 +58,7 @@ describe('Nyan reporter', function () { duration: '', slow: function () {} }; - runner.on = runner.once = runnerEvent('pass', 'pass', null, null, test); + runner = createMockRunner('pass', 'pass', null, null, test); NyanCat.call({ draw: function () { calledDraw = true; @@ -77,7 +76,7 @@ describe('Nyan reporter', function () { var test = { err: '' }; - runner.on = runner.once = runnerEvent('fail', 'fail', null, null, test); + runner = createMockRunner('fail', 'fail', null, null, test); NyanCat.call({ draw: function () { calledDraw = true; @@ -92,7 +91,7 @@ describe('Nyan reporter', function () { describe('on end', function () { it('should call epilogue', function () { var calledEpilogue = false; - runner.on = runner.once = runnerEvent('end', 'end'); + runner = createMockRunner('end', 'end'); NyanCat.call({ draw: function () {}, generateColors: function () {}, @@ -106,7 +105,7 @@ describe('Nyan reporter', function () { }); it('should write numberOfLines amount of new lines', function () { var expectedNumberOfLines = 4; - runner.on = runner.once = runnerEvent('end', 'end'); + runner = createMockRunner('end', 'end'); NyanCat.call({ draw: function () {}, generateColors: function () {}, @@ -124,7 +123,7 @@ describe('Nyan reporter', function () { Base.cursor.show = function () { showCalled = true; }; - runner.on = runner.once = runnerEvent('end', 'end'); + runner = createMockRunner('end', 'end'); NyanCat.call({ draw: function () {}, generateColors: function () {}, diff --git a/test/reporters/progress.spec.js b/test/reporters/progress.spec.js index d484e62bc5..47818f841d 100644 --- a/test/reporters/progress.spec.js +++ b/test/reporters/progress.spec.js @@ -4,7 +4,7 @@ var reporters = require('../../').reporters; var Progress = reporters.Progress; var Base = reporters.Base; -var runnerEvent = require('./helpers').runnerEvent; +var createMockRunner = require('./helpers').createMockRunner; describe('Progress reporter', function () { var stdout; @@ -13,7 +13,6 @@ describe('Progress reporter', function () { beforeEach(function () { stdout = []; - runner = {}; stdoutWrite = process.stdout.write; process.stdout.write = function (string) { stdout.push(string); @@ -27,7 +26,7 @@ describe('Progress reporter', function () { Base.cursor.hide = function () { calledCursorHide = true; }; - runner.on = runner.once = runnerEvent('start', 'start'); + runner = createMockRunner('start', 'start'); Progress.call({}, runner); process.stdout.write = stdoutWrite; @@ -49,8 +48,8 @@ describe('Progress reporter', function () { var expectedTotal = 1; var expectedOptions = {}; + runner = createMockRunner('test end', 'test end'); runner.total = expectedTotal; - runner.on = runner.once = runnerEvent('test end', 'test end'); Progress.call({}, runner, expectedOptions); process.stdout.write = stdoutWrite; @@ -87,8 +86,8 @@ describe('Progress reporter', function () { var options = { reporterOptions: expectedOptions }; + runner = createMockRunner('test end', 'test end'); runner.total = expectedTotal; - runner.on = runner.once = runnerEvent('test end', 'test end'); Progress.call({}, runner, options); process.stdout.write = stdoutWrite; @@ -116,7 +115,7 @@ describe('Progress reporter', function () { Base.cursor.show = function () { calledCursorShow = true; }; - runner.on = runner.once = runnerEvent('end', 'end'); + runner = createMockRunner('end', 'end'); var calledEpilogue = false; Progress.call({ epilogue: function () { diff --git a/test/reporters/spec.spec.js b/test/reporters/spec.spec.js index bca3c92c93..cb662e4530 100644 --- a/test/reporters/spec.spec.js +++ b/test/reporters/spec.spec.js @@ -4,7 +4,7 @@ var reporters = require('../../').reporters; var Spec = reporters.Spec; var Base = reporters.Base; -var runnerEvent = require('./helpers').runnerEvent; +var createMockRunner = require('./helpers').createMockRunner; describe('Spec reporter', function () { var stdout; @@ -15,7 +15,6 @@ describe('Spec reporter', function () { beforeEach(function () { stdout = []; - runner = {}; stdoutWrite = process.stdout.write; process.stdout.write = function (string) { stdout.push(string); @@ -33,7 +32,7 @@ describe('Spec reporter', function () { var suite = { title: expectedTitle }; - runner.on = runner.once = runnerEvent('suite', 'suite', null, null, suite); + runner = createMockRunner('suite', 'suite', null, null, suite); Spec.call({epilogue: function () {}}, runner); process.stdout.write = stdoutWrite; var expectedArray = [ @@ -47,7 +46,7 @@ describe('Spec reporter', function () { var suite = { title: expectedTitle }; - runner.on = runner.once = runnerEvent('pending test', 'pending', null, null, suite); + runner = createMockRunner('pending test', 'pending', null, null, suite); Spec.call({epilogue: function () {}}, runner); process.stdout.write = stdoutWrite; var expectedArray = [ @@ -65,11 +64,7 @@ describe('Spec reporter', function () { duration: expectedDuration, slow: function () { return 1; } }; - runner.on = runner.once = function (event, callback) { - if (event === 'pass') { - callback(test); - } - }; + runner = createMockRunner('pass', 'pass', null, null, test); Spec.call({epilogue: function () {}}, runner); process.stdout.write = stdoutWrite; var expectedString = ' ' + Base.symbols.ok + ' ' + expectedTitle + ' (' + expectedDuration + 'ms)' + '\n'; @@ -84,11 +79,7 @@ describe('Spec reporter', function () { duration: expectedDuration, slow: function () { return 2; } }; - runner.on = runner.once = function (event, callback) { - if (event === 'pass') { - callback(test); - } - }; + runner = createMockRunner('pass', 'pass', null, null, test); Spec.call({epilogue: function () {}}, runner); process.stdout.write = stdoutWrite; var expectedString = ' ' + Base.symbols.ok + ' ' + expectedTitle + '\n'; @@ -102,7 +93,7 @@ describe('Spec reporter', function () { var test = { title: expectedTitle }; - runner.on = runner.once = runnerEvent('fail', 'fail', null, null, test); + runner = createMockRunner('fail', 'fail', null, null, test); Spec.call({epilogue: function () {}}, runner); process.stdout.write = stdoutWrite; var expectedArray = [ diff --git a/test/reporters/tap.spec.js b/test/reporters/tap.spec.js index 312927acc8..6a29ffbe26 100644 --- a/test/reporters/tap.spec.js +++ b/test/reporters/tap.spec.js @@ -3,7 +3,7 @@ var reporters = require('../../').reporters; var TAP = reporters.TAP; -var runnerEvent = require('./helpers').runnerEvent; +var createMockRunner = require('./helpers').createMockRunner; describe('TAP reporter', function () { var stdout; @@ -15,7 +15,6 @@ describe('TAP reporter', function () { beforeEach(function () { stdout = []; - runner = {}; stdoutWrite = process.stdout.write; process.stdout.write = function (string) { stdout.push(string); @@ -33,7 +32,7 @@ describe('TAP reporter', function () { var expectedSuite = 'some suite'; var expectedTotal = 10; var expectedString; - runner.on = runner.once = runnerEvent('start', 'start'); + runner = createMockRunner('start', 'start'); runner.suite = expectedSuite; runner.grepTotal = function (string) { expectedString = string; @@ -53,12 +52,7 @@ describe('TAP reporter', function () { describe('on pending', function () { it('should write expected message including count and title', function () { - // var test = { - // fullTitle: function () { - // return expectedTitle; - // } - // }; - runner.on = runner.once = runnerEvent('start test', 'test end', 'pending', null, test); + runner = createMockRunner('start test', 'test end', 'pending', null, test); runner.suite = ''; runner.grepTotal = function () { }; TAP.call({}, runner); @@ -72,7 +66,7 @@ describe('TAP reporter', function () { describe('on pass', function () { it('should write expected message including count and title', function () { - runner.on = runner.once = runnerEvent('start test', 'test end', 'pass', null, test); + runner = createMockRunner('start test', 'test end', 'pass', null, test); runner.suite = ''; runner.grepTotal = function () { }; @@ -92,7 +86,7 @@ describe('TAP reporter', function () { var error = { stack: expectedStack }; - runner.on = runner.once = runnerEvent('test end fail', 'test end', 'fail', null, test, error); + runner = createMockRunner('test end fail', 'test end', 'fail', null, test, error); runner.suite = ''; runner.grepTotal = function () { }; TAP.call({}, runner); @@ -135,7 +129,7 @@ describe('TAP reporter', function () { it('should write total tests, passes and failures', function () { var numberOfPasses = 1; var numberOfFails = 1; - runner.on = runner.once = runnerEvent('fail end pass', 'fail', 'end', 'pass', test); + runner = createMockRunner('fail end pass', 'fail', 'end', 'pass', test); runner.suite = ''; runner.grepTotal = function () { }; TAP.call({}, runner);