From b4bf1f4cda8df16954b0ba604928af57bb1e361e Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Fri, 3 Feb 2017 13:25:34 +0000 Subject: [PATCH 1/6] added 100% coverage for json stream --- test/reporters/json-stream.spec.js | 138 +++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 test/reporters/json-stream.spec.js diff --git a/test/reporters/json-stream.spec.js b/test/reporters/json-stream.spec.js new file mode 100644 index 0000000000..e8ec69e032 --- /dev/null +++ b/test/reporters/json-stream.spec.js @@ -0,0 +1,138 @@ +var reporters = require('../../').reporters; +var JSONStream = reporters.JSONStream; + +describe('Json Stream reporter', function () { + var runner; + var stdout; + var stdoutWrite; + + beforeEach(function () { + stdout = []; + runner = {}; + stdoutWrite = process.stdout.write; + process.stdout.write = function (string) { + stdout.push(string); + }; + }); + + describe('on start', function () { + it('should write stringified start with expected total', function () { + runner.on = function (event, callback) { + if (event === 'start') { + callback(); + } + }; + var expectedTotal = 12; + runner.total = expectedTotal; + JSONStream.call({}, runner); + + process.stdout.write = stdoutWrite; + + stdout[0].should.deepEqual('[\"start\",{\"total\":' + expectedTotal + '}]\n'); + }); + }); + + describe('on pass', function () { + it('should write stringified test data', function () { + var expectedTitle = 'some title'; + var expectedFullTitle = 'full title'; + var expectedDuration = 1000; + var currentRetry = 1; + var expectedTest = { + title: expectedTitle, + fullTitle: function () { return expectedFullTitle; }, + duration: expectedDuration, + currentRetry: function () { return currentRetry; }, + slow: function () {} + }; + runner.on = function (event, callback) { + if (event === 'pass') { + callback(expectedTest); + } + }; + JSONStream.call({}, runner); + + process.stdout.write = stdoutWrite; + + stdout[0].should.deepEqual('["pass",{"title":"' + expectedTitle + '","fullTitle":"' + expectedFullTitle + '","duration":' + expectedDuration + ',"currentRetry":' + currentRetry + '}]\n'); + }); + }); + + describe('on fail', function () { + describe('if error stack exists', function () { + it('should write stringified test data with error data', function () { + var expectedTitle = 'some title'; + var expectedFullTitle = 'full title'; + var expectedDuration = 1000; + var currentRetry = 1; + var expectedTest = { + title: expectedTitle, + fullTitle: function () { return expectedFullTitle; }, + duration: expectedDuration, + currentRetry: function () { return currentRetry; }, + slow: function () {} + }; + var expectedErrorMessage = 'error message'; + var expectedErrorStack = 'error stack'; + var expectedError = { + message: expectedErrorMessage, + stack: expectedErrorStack + } + runner.on = function (event, callback) { + if (event === 'fail') { + callback(expectedTest, expectedError); + } + }; + JSONStream.call({}, runner); + + process.stdout.write = stdoutWrite; + + stdout[0].should.deepEqual('["fail",{"title":"' + expectedTitle + '","fullTitle":"' + expectedFullTitle + '","duration":' + expectedDuration + ',"currentRetry":' + currentRetry + ',"err":"' + expectedErrorMessage + '","stack":"' + expectedErrorStack + '"}]\n'); + }); + }); + describe('if error stack does not exist', function () { + it('should write stringified test data with error data', function () { + var expectedTitle = 'some title'; + var expectedFullTitle = 'full title'; + var expectedDuration = 1000; + var currentRetry = 1; + var expectedTest = { + title: expectedTitle, + fullTitle: function () { return expectedFullTitle; }, + duration: expectedDuration, + currentRetry: function () { return currentRetry; }, + slow: function () {} + }; + var expectedErrorMessage = 'error message'; + var expectedError = { + message: expectedErrorMessage + } + runner.on = function (event, callback) { + if (event === 'fail') { + callback(expectedTest, expectedError); + } + }; + JSONStream.call({}, runner); + + process.stdout.write = stdoutWrite; + + stdout[0].should.deepEqual('["fail",{"title":"' + expectedTitle + '","fullTitle":"' + expectedFullTitle + '","duration":' + expectedDuration + ',"currentRetry":' + currentRetry + ',"err":"' + expectedErrorMessage + '","stack":null}]\n'); + }); + }); + }); + + describe('on end', function () { + it('should write end details', function () { + runner.on = function (event, callback) { + if (event === 'end') { + callback(); + } + }; + JSONStream.call({}, runner); + + process.stdout.write = stdoutWrite; + + stdout[0].should.match(/end/); + }); + }); +}); From d7846b672813d25946f50bcd34ab4874dbdd33ef Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Fri, 3 Feb 2017 14:18:36 +0000 Subject: [PATCH 2/6] 100% markdown coverage --- test/reporters/json-stream.spec.js | 6 +- test/reporters/markdown.spec.js | 100 +++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 test/reporters/markdown.spec.js diff --git a/test/reporters/json-stream.spec.js b/test/reporters/json-stream.spec.js index e8ec69e032..660b5239ae 100644 --- a/test/reporters/json-stream.spec.js +++ b/test/reporters/json-stream.spec.js @@ -28,7 +28,7 @@ describe('Json Stream reporter', function () { process.stdout.write = stdoutWrite; - stdout[0].should.deepEqual('[\"start\",{\"total\":' + expectedTotal + '}]\n'); + stdout[0].should.deepEqual('["start",{"total":' + expectedTotal + '}]\n'); }); }); @@ -77,7 +77,7 @@ describe('Json Stream reporter', function () { var expectedError = { message: expectedErrorMessage, stack: expectedErrorStack - } + }; runner.on = function (event, callback) { if (event === 'fail') { callback(expectedTest, expectedError); @@ -106,7 +106,7 @@ describe('Json Stream reporter', function () { var expectedErrorMessage = 'error message'; var expectedError = { message: expectedErrorMessage - } + }; runner.on = function (event, callback) { if (event === 'fail') { callback(expectedTest, expectedError); diff --git a/test/reporters/markdown.spec.js b/test/reporters/markdown.spec.js new file mode 100644 index 0000000000..67acc783f4 --- /dev/null +++ b/test/reporters/markdown.spec.js @@ -0,0 +1,100 @@ +'use strict'; + +var reporters = require('../../').reporters; +var Markdown = reporters.Markdown; + +describe('Markdown 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 \'suite\'', function () { + it('should write expected slugged titles on \'end\' event', function () { + var expectedTitle = 'expected title'; + var expectedFullTitle = 'full title'; + var sluggedFullTitle = 'full-title'; + var expectedSuite = { + title: expectedTitle, + fullTitle: function () { return expectedFullTitle; }, + suites: [{ + title: expectedTitle, + fullTitle: function () { return expectedFullTitle; }, + suites: [] + }] + }; + runner.on = function (event, callback) { + if (event === 'suite') { + callback(expectedSuite); + } + if (event === 'suite end') { + callback(); + } + if (event === 'end') { + callback(); + } + }; + runner.suite = expectedSuite; + Markdown.call({}, runner); + process.stdout.write = stdoutWrite; + + var expectedArray = [ + '# TOC\n', + ' - [' + expectedTitle + '](#' + sluggedFullTitle + ')\n - [' + expectedTitle + '](#' + sluggedFullTitle + ')\n', + '\n ' + expectedTitle + '\n' + ]; + + stdout.should.deepEqual(expectedArray); + }); + }); + describe('on \'pass\'', function () { + it('should write test code inside js code block, on \'end\' event', function () { + var expectedTitle = 'expected title'; + var expectedFullTitle = 'full title'; + var sluggedFullTitle = 'full-title'; + var expectedSuite = { + title: expectedTitle, + fullTitle: function () { return expectedFullTitle; }, + suites: [] + }; + var expectedDuration = 1000; + var currentRetry = 1; + var expectedBody = 'some body'; + var expectedTest = { + title: expectedTitle, + fullTitle: function () { return expectedFullTitle; }, + duration: expectedDuration, + currentRetry: function () { return currentRetry; }, + slow: function () {}, + body: expectedBody + }; + runner.on = function (event, callback) { + if (event === 'pass') { + callback(expectedTest); + } + if (event === 'end') { + callback(); + } + }; + runner.suite = expectedSuite; + Markdown.call({}, runner); + process.stdout.write = stdoutWrite; + + var expectedArray = [ + '# TOC\n', + ' - [' + expectedTitle + '](#' + sluggedFullTitle + ')\n', + expectedTitle + '.\n\n```js\n' + expectedBody + '\n```\n\n' + ]; + + stdout.should.deepEqual(expectedArray); + }); + }); +}); From fd6e9799eae78e6fd974f3ef23306d19188fc0d5 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Fri, 3 Feb 2017 14:48:54 +0000 Subject: [PATCH 3/6] added test for progress reporter --- test/reporters/json-stream.spec.js | 2 + test/reporters/progress.spec.js | 114 +++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 test/reporters/progress.spec.js diff --git a/test/reporters/json-stream.spec.js b/test/reporters/json-stream.spec.js index 660b5239ae..0290589bdc 100644 --- a/test/reporters/json-stream.spec.js +++ b/test/reporters/json-stream.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var reporters = require('../../').reporters; var JSONStream = reporters.JSONStream; diff --git a/test/reporters/progress.spec.js b/test/reporters/progress.spec.js new file mode 100644 index 0000000000..a181e75cfc --- /dev/null +++ b/test/reporters/progress.spec.js @@ -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; + }); + }); +}); From e82c671c26740b8dc802526de84605dca663d2f0 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Fri, 3 Feb 2017 15:08:24 +0000 Subject: [PATCH 4/6] catch when line not changed --- test/reporters/progress.spec.js | 111 ++++++++++++++++++++------------ 1 file changed, 71 insertions(+), 40 deletions(-) diff --git a/test/reporters/progress.spec.js b/test/reporters/progress.spec.js index a181e75cfc..8ed5167ecb 100644 --- a/test/reporters/progress.spec.js +++ b/test/reporters/progress.spec.js @@ -40,48 +40,79 @@ describe('Progrss reporter', function () { }); 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); + describe('if line has not changed', () => { + it('should return and not write anything', function () { + var cachedCursor = Base.cursor; + var useColors = Base.useColors; + Base.useColors = false; + Base.cursor.CR = function () {}; + var windowWidth = Base.window.width; + Base.window.width = -3; - process.stdout.write = stdoutWrite; - var expectedArray = [ - '\u001b[J', - ' ' + expectedOpen, - '', - '', - expectedClose - ]; - calledCursorCR.should.be.true(); - stdout.should.deepEqual(expectedArray); + var expectedTotal = 1; + var expectedOptions = {}; + runner.total = expectedTotal; + runner.on = function (event, callback) { + if (event === 'test end') { + callback(); + } + }; + Progress.call({}, runner, expectedOptions); - Base.cursor = cachedCursor; - Base.useColors = useColors; - Base.window.width = windowWidth; + process.stdout.write = stdoutWrite; + + stdout.should.deepEqual([]); + + Base.cursor = cachedCursor; + Base.useColors = useColors; + Base.window.width = windowWidth; + }); + }); + describe('if line has changed', () => { + 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 = 5; + + var expectedTotal = 12; + var expectedOpen = 'OpEn'; + var expectedClose = 'cLoSe'; + var expectedIncomplete = 'iNcOmPlEtE'; + var expectedOptions = { + open: expectedOpen, + complete: 'cOmPlEtE', + incomplete: expectedIncomplete, + 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, + '', + expectedIncomplete, + expectedClose + ]; + calledCursorCR.should.be.true(); + stdout.should.deepEqual(expectedArray); + + Base.cursor = cachedCursor; + Base.useColors = useColors; + Base.window.width = windowWidth; + }); }); }); From 6e52f408c0f84ca9e2a5a0d584a5829757aaaebd Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Fri, 3 Feb 2017 15:10:02 +0000 Subject: [PATCH 5/6] fix spec typo --- test/reporters/progress.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/reporters/progress.spec.js b/test/reporters/progress.spec.js index 8ed5167ecb..007c40f680 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; -describe('Progrss reporter', function () { +describe('Progress reporter', function () { var stdout; var stdoutWrite; var runner; From 5eac3a06042e5d5db6ce4450f323152d2dd11f16 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Fri, 3 Feb 2017 15:24:37 +0000 Subject: [PATCH 6/6] remove mistaken arrow functions --- test/reporters/progress.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/reporters/progress.spec.js b/test/reporters/progress.spec.js index 007c40f680..83a78b2b1d 100644 --- a/test/reporters/progress.spec.js +++ b/test/reporters/progress.spec.js @@ -40,7 +40,7 @@ describe('Progress reporter', function () { }); describe('on test end', function () { - describe('if line has not changed', () => { + describe('if line has not changed', function () { it('should return and not write anything', function () { var cachedCursor = Base.cursor; var useColors = Base.useColors; @@ -68,7 +68,7 @@ describe('Progress reporter', function () { Base.window.width = windowWidth; }); }); - describe('if line has changed', () => { + describe('if line has changed', function () { it('should write expected progress of open and close options', function () { var calledCursorCR = false; var cachedCursor = Base.cursor;