From 64c7051d5bc7f6126d720ff0da11e7387a2f82c0 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Sun, 5 Feb 2017 16:43:05 +0000 Subject: [PATCH 1/7] landing reporter 100% --- test/reporters/landing.spec.js | 151 +++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 test/reporters/landing.spec.js diff --git a/test/reporters/landing.spec.js b/test/reporters/landing.spec.js new file mode 100644 index 0000000000..343dd80c38 --- /dev/null +++ b/test/reporters/landing.spec.js @@ -0,0 +1,151 @@ +'use strict'; + +var reporters = require('../../').reporters; +var Landing = reporters.Landing; +var Base = reporters.Base; + +describe('Landing reporter', function () { + var stdout; + var stdoutWrite; + var runner; + var useColors; + var windowWidth; + + beforeEach(function () { + stdout = []; + runner = {}; + stdoutWrite = process.stdout.write; + process.stdout.write = function (string) { + stdout.push(string); + }; + useColors = Base.useColors; + Base.useColors = false; + windowWidth = Base.window.width; + Base.window.width = 1; + }); + + afterEach(function () { + Base.useColors = useColors; + Base.window.width = windowWidth; + }); + + describe('on start', function () { + it('should write new lines', function () { + var cachedCursor = Base.cursor; + Base.cursor.hide = function () {}; + runner.on = function (event, callback) { + if (event === 'start') { + callback(); + } + }; + Landing.call({}, runner); + + process.stdout.write = stdoutWrite; + + stdout[0].should.deepEqual('\n\n\n '); + Base.cursor = cachedCursor; + }); + + 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(); + } + }; + Landing.call({}, runner); + + process.stdout.write = stdoutWrite; + calledCursorHide.should.be.true(); + + Base.cursor = cachedCursor; + }); + }); + + describe('on test end', function () { + describe('if test has failed', function () { + it('should write expected landing strip', function () { + var test = { + state: 'failed' + }; + runner.on = function (event, callback) { + if (event === 'test end') { + callback(test); + } + }; + runner.total = 12; + Landing.call({}, runner); + + process.stdout.write = stdoutWrite; + + var expectedArray = [ '\u001b[1D\u001b[2A', + ' ', + '\n ', + '', + '✈', + '\n', + ' ', + '\u001b[0m' + ]; + stdout.should.deepEqual(expectedArray); + }); + }); + describe('if test has not failed', function () { + it('should write expected landing strip', function () { + var test = { + state: 'success' + }; + runner.on = function (event, callback) { + if (event === 'test end') { + callback(test); + } + }; + + Landing.call({}, runner); + + process.stdout.write = stdoutWrite; + + var expectedArray = [ '\u001b[1D\u001b[2A', + ' ', + '\n ', + '', + '✈', + '\n', + ' ', + '\u001b[0m' + ]; + stdout.should.deepEqual(expectedArray); + }); + }); + }); + 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; + Landing.call({ + epilogue: function () { + calledEpilogue = true; + } + }, runner); + + process.stdout.write = stdoutWrite; + calledEpilogue.should.be.true(); + calledCursorShow.should.be.true(); + + Base.cursor = cachedCursor; + }); + }); +}); From 474a6cbe5a3c2b333b14f2b0332a2f3574eace40 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Sun, 5 Feb 2017 22:00:48 +0000 Subject: [PATCH 2/7] min reporter 100% coverage --- test/reporters/landing.spec.js | 11 ++++--- test/reporters/min.spec.js | 56 ++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 test/reporters/min.spec.js diff --git a/test/reporters/landing.spec.js b/test/reporters/landing.spec.js index 343dd80c38..de0caccaec 100644 --- a/test/reporters/landing.spec.js +++ b/test/reporters/landing.spec.js @@ -10,6 +10,7 @@ describe('Landing reporter', function () { var runner; var useColors; var windowWidth; + var resetCode = '\u001b[0m'; beforeEach(function () { stdout = []; @@ -82,14 +83,15 @@ describe('Landing reporter', function () { process.stdout.write = stdoutWrite; - var expectedArray = [ '\u001b[1D\u001b[2A', + var expectedArray = [ + '\u001b[1D\u001b[2A', ' ', '\n ', '', '✈', '\n', ' ', - '\u001b[0m' + resetCode ]; stdout.should.deepEqual(expectedArray); }); @@ -109,14 +111,15 @@ describe('Landing reporter', function () { process.stdout.write = stdoutWrite; - var expectedArray = [ '\u001b[1D\u001b[2A', + var expectedArray = [ + '\u001b[1D\u001b[2A', ' ', '\n ', '', '✈', '\n', ' ', - '\u001b[0m' + resetCode ]; stdout.should.deepEqual(expectedArray); }); diff --git a/test/reporters/min.spec.js b/test/reporters/min.spec.js new file mode 100644 index 0000000000..dfdb3a05a4 --- /dev/null +++ b/test/reporters/min.spec.js @@ -0,0 +1,56 @@ +'use strict'; + +var reporters = require('../../').reporters; +var Min = reporters.Min; + +describe('Min 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 clear screen then set cursor position', function () { + runner.on = function (event, callback) { + if (event === 'start') { + callback(); + } + }; + Min.call({epilogue: function () {}}, runner); + + process.stdout.write = stdoutWrite; + var expectedArray = [ + '\u001b[2J', + '\u001b[1;3H' + ]; + stdout.should.deepEqual(expectedArray); + }); + }); + + describe('on end', function () { + it('should call epilogue', function () { + var calledEpilogue = false; + runner.on = function (event, callback) { + if (event === 'end') { + callback(); + } + }; + Min.call({ + epilogue: function () { + calledEpilogue = true; + } + }, runner); + process.stdout.write = stdoutWrite; + + calledEpilogue.should.be.true(); + }); + }); +}); From 3e2c010e712dd0d2887c2e6ec3f90eb61641cb4c Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Sun, 5 Feb 2017 22:33:56 +0000 Subject: [PATCH 3/7] 100% coverage for tap --- test/reporters/tap.spec.js | 212 +++++++++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 test/reporters/tap.spec.js diff --git a/test/reporters/tap.spec.js b/test/reporters/tap.spec.js new file mode 100644 index 0000000000..1d1305b777 --- /dev/null +++ b/test/reporters/tap.spec.js @@ -0,0 +1,212 @@ +'use strict'; + +var reporters = require('../../').reporters; +var TAP = reporters.TAP; + +describe('TAP 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 hand runners suite into grepTotal and log the total', function () { + var expectedSuite = 'some suite'; + var expectedTotal = 10; + var expectedString; + runner.on = function (event, callback) { + if (event === 'start') { + callback(); + } + }; + runner.suite = expectedSuite; + runner.grepTotal = function (string) { + expectedString = string; + return expectedTotal; + }; + TAP.call({}, runner); + + var expectedArray = [ + '1..10\n' + ]; + process.stdout.write = stdoutWrite; + + stdout.should.deepEqual(expectedArray); + expectedString.should.equal(expectedSuite); + }); + }); + + describe('on pending', function () { + it('should write expected message including count and title', function () { + var expectedTitle = 'some title'; + var countAfterTestEnd = 2; + var test = { + fullTitle: function () { + return expectedTitle; + } + }; + runner.on = function (event, callback) { + if (event === 'test end') { + callback(); + } + if (event === 'pending') { + callback(test); + } + }; + runner.suite = ''; + runner.grepTotal = function () { }; + TAP.call({}, runner); + + process.stdout.write = stdoutWrite; + + var expectedMessage = 'ok ' + countAfterTestEnd + ' ' + expectedTitle + ' # SKIP -\n'; + stdout[0].should.deepEqual(expectedMessage); + }); + }); + + describe('on pass', function () { + it('should write expected message including count and title', function () { + var expectedTitle = 'some title'; + var countAfterTestEnd = 2; + var test = { + fullTitle: function () { + return expectedTitle; + }, + slow: function () {} + }; + runner.on = function (event, callback) { + if (event === 'test end') { + callback(); + } + if (event === 'pass') { + callback(test); + } + }; + runner.suite = ''; + runner.grepTotal = function () { }; + TAP.call({}, runner); + + process.stdout.write = stdoutWrite; + + var expectedMessage = 'ok ' + countAfterTestEnd + ' ' + expectedTitle + '\n'; + stdout[0].should.deepEqual(expectedMessage); + }); + }); + + describe('on fail', function () { + describe('if there is an error stack', function () { + it('should write expected message and stack', function () { + var expectedTitle = 'some title'; + var countAfterTestEnd = 2; + var expectedStack = 'some stack'; + var test = { + fullTitle: function () { + return expectedTitle; + }, + slow: function () {} + }; + var error = { + stack: expectedStack + }; + runner.on = function (event, callback) { + if (event === 'test end') { + callback(); + } + if (event === 'fail') { + callback(test, error); + } + }; + runner.suite = ''; + runner.grepTotal = function () { }; + TAP.call({}, runner); + + process.stdout.write = stdoutWrite; + + var expectedArray = [ + 'not ok ' + countAfterTestEnd + ' ' + expectedTitle + '\n', + ' ' + expectedStack + '\n' + ]; + stdout.should.deepEqual(expectedArray); + }); + }); + describe('if there is no error stack', function () { + it('should write expected message only', function () { + var expectedTitle = 'some title'; + var countAfterTestEnd = 2; + var test = { + fullTitle: function () { + return expectedTitle; + }, + slow: function () {} + }; + var error = {}; + runner.on = function (event, callback) { + if (event === 'test end') { + callback(); + } + if (event === 'fail') { + callback(test, error); + } + }; + runner.suite = ''; + runner.grepTotal = function () { }; + TAP.call({}, runner); + + process.stdout.write = stdoutWrite; + + var expectedArray = [ + 'not ok ' + countAfterTestEnd + ' ' + expectedTitle + '\n' + ]; + stdout.should.deepEqual(expectedArray); + }); + }); + }); + + describe('on end', function () { + it('should write total tests, passes and failures', function () { + var expectedTitle = 'some title'; + var numberOfPasses = 1; + var numberOfFails = 1; + var test = { + fullTitle: function () { + return expectedTitle; + }, + slow: function () {} + }; + runner.on = function (event, callback) { + if (event === 'fail') { + callback(test, {}); + } + if (event === 'end') { + callback(test); + } + if (event === 'pass') { + callback(test); + } + }; + runner.suite = ''; + runner.grepTotal = function () { }; + TAP.call({}, runner); + + process.stdout.write = stdoutWrite; + + var totalTests = numberOfPasses + numberOfFails; + var expectedArray = [ + 'ok ' + numberOfPasses + ' ' + expectedTitle + '\n', + 'not ok ' + numberOfFails + ' ' + expectedTitle + '\n', + '# tests ' + totalTests + '\n', + '# pass ' + numberOfPasses + '\n', + '# fail ' + numberOfFails + '\n' + ]; + stdout.should.deepEqual(expectedArray); + }); + }); +}); From 3b9c6c93a70aae2759734459415c617f2671f587 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Sun, 5 Feb 2017 22:54:20 +0000 Subject: [PATCH 4/7] 100% list reporter --- test/reporters/list.spec.js | 211 ++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 test/reporters/list.spec.js diff --git a/test/reporters/list.spec.js b/test/reporters/list.spec.js new file mode 100644 index 0000000000..f2536e5a28 --- /dev/null +++ b/test/reporters/list.spec.js @@ -0,0 +1,211 @@ +'use strict'; + +var reporters = require('../../').reporters; +var List = reporters.List; +var Base = reporters.Base; + +describe('List reporter', function () { + var stdout; + var stdoutWrite; + var runner; + var useColors; + + beforeEach(function () { + stdout = []; + runner = {}; + stdoutWrite = process.stdout.write; + process.stdout.write = function (string) { + stdout.push(string); + }; + useColors = Base.useColors; + Base.useColors = false; + }); + + afterEach(function () { + Base.useColors = useColors; + }); + + describe('on start and test', function () { + it('should write expected new line and title to the console', function () { + var expectedTitle = 'some title'; + var test = { + fullTitle: function () { + return expectedTitle; + } + }; + runner.on = function (event, callback) { + if (event === 'start') { + callback(); + } + if (event === 'test') { + callback(test); + } + }; + List.call({epilogue: function () {}}, runner); + + process.stdout.write = stdoutWrite; + var startString = '\n'; + var testString = ' ' + expectedTitle + ': '; + var expectedArray = [ + startString, + testString + ]; + stdout.should.deepEqual(expectedArray); + }); + }); + describe('on pending', function () { + it('should write expected title to the console', function () { + var expectedTitle = 'some title'; + var test = { + fullTitle: function () { + return expectedTitle; + } + }; + runner.on = function (event, callback) { + if (event === 'pending') { + callback(test); + } + }; + List.call({epilogue: function () {}}, runner); + + process.stdout.write = stdoutWrite; + + stdout[0].should.deepEqual(' - ' + expectedTitle + '\n'); + }); + }); + describe('on pass', function () { + it('should call cursor CR', function () { + var calledCursorCR = false; + var cachedCursor = Base.cursor; + Base.cursor.CR = function () { + calledCursorCR = true; + }; + var expectedTitle = 'some title'; + var expectedDuration = 100; + var test = { + fullTitle: function () { + return expectedTitle; + }, + duration: expectedDuration, + slow: function () {} + }; + runner.on = function (event, callback) { + if (event === 'pass') { + callback(test); + } + }; + List.call({epilogue: function () {}}, runner); + + process.stdout.write = stdoutWrite; + + calledCursorCR.should.be.true(); + + Base.cursor = cachedCursor; + }); + it('should write expected symbol, title and duration to the console', function () { + var cachedCursor = Base.cursor; + Base.cursor.CR = function () {}; + var expectedTitle = 'some title'; + var expectedDuration = 100; + var test = { + fullTitle: function () { + return expectedTitle; + }, + duration: expectedDuration, + slow: function () {} + }; + runner.on = function (event, callback) { + if (event === 'pass') { + callback(test); + } + }; + List.call({epilogue: function () {}}, runner); + + process.stdout.write = stdoutWrite; + + stdout[0].should.equal(' ✓ ' + expectedTitle + ': ' + expectedDuration + 'ms\n'); + + Base.cursor = cachedCursor; + }); + }); + describe('on fail', function () { + it('should call cursor CR', function () { + var calledCursorCR = false; + var cachedCursor = Base.cursor; + Base.cursor.CR = function () { + calledCursorCR = true; + }; + var expectedTitle = 'some title'; + var expectedDuration = 100; + var test = { + fullTitle: function () { + return expectedTitle; + }, + duration: expectedDuration, + slow: function () {} + }; + runner.on = function (event, callback) { + if (event === 'fail') { + callback(test); + } + }; + List.call({epilogue: function () {}}, runner); + + process.stdout.write = stdoutWrite; + + calledCursorCR.should.be.true(); + + Base.cursor = cachedCursor; + }); + it('should write expected error number and title', function () { + var cachedCursor = Base.cursor; + var expectedErrorCount = 1; + Base.cursor.CR = function () {}; + var expectedTitle = 'some title'; + var expectedDuration = 100; + var test = { + fullTitle: function () { + return expectedTitle; + }, + duration: expectedDuration, + slow: function () {} + }; + runner.on = function (event, callback) { + if (event === 'fail') { + callback(test); + } + }; + runner.on = function (event, callback) { + if (event === 'fail') { + callback(test); + } + }; + List.call({epilogue: function () {}}, runner); + + process.stdout.write = stdoutWrite; + + stdout[0].should.equal(' ' + expectedErrorCount + ') ' + expectedTitle + '\n'); + + Base.cursor = cachedCursor; + }); + }); + + describe('on end', function () { + it('should call epilogue', function () { + var calledEpilogue = false; + runner.on = function (event, callback) { + if (event === 'end') { + callback(); + } + }; + List.call({ + epilogue: function () { + calledEpilogue = true; + } + }, runner); + process.stdout.write = stdoutWrite; + + calledEpilogue.should.be.true(); + }); + }); +}); From be441b35d09d8921bbd0efc2a7ed4ba4fdbe529c Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Sun, 5 Feb 2017 22:56:56 +0000 Subject: [PATCH 5/7] use variable for assertion --- test/reporters/tap.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/reporters/tap.spec.js b/test/reporters/tap.spec.js index 1d1305b777..0908f13e5f 100644 --- a/test/reporters/tap.spec.js +++ b/test/reporters/tap.spec.js @@ -35,7 +35,7 @@ describe('TAP reporter', function () { TAP.call({}, runner); var expectedArray = [ - '1..10\n' + '1..' + expectedTotal+ '\n' ]; process.stdout.write = stdoutWrite; From 614190daad082569b8e453aca6f859638056745b Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Sun, 5 Feb 2017 23:01:00 +0000 Subject: [PATCH 6/7] fix lint error --- test/reporters/tap.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/reporters/tap.spec.js b/test/reporters/tap.spec.js index 0908f13e5f..de84f613ee 100644 --- a/test/reporters/tap.spec.js +++ b/test/reporters/tap.spec.js @@ -35,7 +35,7 @@ describe('TAP reporter', function () { TAP.call({}, runner); var expectedArray = [ - '1..' + expectedTotal+ '\n' + '1..' + expectedTotal + '\n' ]; process.stdout.write = stdoutWrite; From 60652429a1f6ac5117488a406efc1fae28ef8c6f Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Sun, 5 Feb 2017 23:09:01 +0000 Subject: [PATCH 7/7] use stubbed symbol --- test/reporters/list.spec.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/reporters/list.spec.js b/test/reporters/list.spec.js index f2536e5a28..00fc58edde 100644 --- a/test/reporters/list.spec.js +++ b/test/reporters/list.spec.js @@ -103,6 +103,9 @@ describe('List reporter', function () { Base.cursor = cachedCursor; }); it('should write expected symbol, title and duration to the console', function () { + var cachedSymbols = Base.symbols; + var expectedOkSymbol = 'OK'; + Base.symbols.ok = expectedOkSymbol; var cachedCursor = Base.cursor; Base.cursor.CR = function () {}; var expectedTitle = 'some title'; @@ -123,9 +126,10 @@ describe('List reporter', function () { process.stdout.write = stdoutWrite; - stdout[0].should.equal(' ✓ ' + expectedTitle + ': ' + expectedDuration + 'ms\n'); + stdout[0].should.equal(' ' + expectedOkSymbol + ' ' + expectedTitle + ': ' + expectedDuration + 'ms\n'); Base.cursor = cachedCursor; + Base.symbols = cachedSymbols; }); }); describe('on fail', function () {