From 0d7635e92209697e9163352d0f1860c063cafebb Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Fri, 20 Apr 2018 16:02:51 -0700 Subject: [PATCH] convert all individual reporter tests to unexpected also don't eat `STDOUT`--this means the tests have more output--could be useful for debugging. Signed-off-by: Christopher Hiller --- test/reporters/doc.spec.js | 25 +++--- test/reporters/dot.spec.js | 22 ++--- test/reporters/json-stream.spec.js | 17 ++-- test/reporters/json.spec.js | 60 ++++++------- test/reporters/landing.spec.js | 16 ++-- test/reporters/list.spec.js | 22 ++--- test/reporters/markdown.spec.js | 11 ++- test/reporters/min.spec.js | 11 ++- test/reporters/nyan.spec.js | 133 +++++++++++++++++------------ test/reporters/progress.spec.js | 19 +++-- test/reporters/spec.spec.js | 14 +-- test/reporters/tap.spec.js | 25 +++--- test/reporters/xunit.spec.js | 26 +++--- 13 files changed, 233 insertions(+), 168 deletions(-) diff --git a/test/reporters/doc.spec.js b/test/reporters/doc.spec.js index 4f3b48868a..b41aa7823b 100644 --- a/test/reporters/doc.spec.js +++ b/test/reporters/doc.spec.js @@ -12,11 +12,16 @@ describe('Doc reporter', function () { beforeEach(function () { stdout = []; stdoutWrite = process.stdout.write; - process.stdout.write = function (string) { + process.stdout.write = function (string, enc, callback) { stdout.push(string); + stdoutWrite.call(process.stdout, string, enc, callback); }; }); + afterEach(function () { + process.stdout.write = stdoutWrite; + }); + describe('on suite', function () { describe('if suite root does not exist', function () { var expectedTitle = 'expectedTitle'; @@ -34,7 +39,7 @@ describe('Doc reporter', function () { '

' + expectedTitle + '

\n', '
\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); it('should escape title where necessary', function () { var suite = { @@ -50,7 +55,7 @@ describe('Doc reporter', function () { '

' + expectedTitle + '

\n', '
\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); describe('if suite root does exist', function () { @@ -61,7 +66,7 @@ describe('Doc reporter', function () { runner = createMockRunner('suite', 'suite', null, null, suite); Doc.call(this, runner); process.stdout.write = stdoutWrite; - expect(stdout).to.be.empty(); + expect(stdout, 'to be empty'); }); }); }); @@ -78,7 +83,7 @@ describe('Doc reporter', function () { var expectedArray = [ '
\n', '\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); describe('if suite root does exist', function () { @@ -89,7 +94,7 @@ describe('Doc reporter', function () { runner = createMockRunner('suite end', 'suite end', null, null, suite); Doc.call(this, runner); process.stdout.write = stdoutWrite; - expect(stdout).to.be.empty(); + expect(stdout, 'to be empty'); }); }); }); @@ -112,7 +117,7 @@ describe('Doc reporter', function () { '
' + expectedTitle + '
\n', '
' + expectedBody + '
\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); it('should escape title and body where necessary', function () { var unescapedTitle = '
' + expectedTitle + '
'; @@ -129,7 +134,7 @@ describe('Doc reporter', function () { '
' + expectedEscapedTitle + '
\n', '
' + expectedEscapedBody + '
\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); @@ -153,7 +158,7 @@ describe('Doc reporter', function () { '
' + expectedBody + '
\n', '
' + expectedError + '
\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); it('should escape title, body and error where necessary', function () { var unescapedTitle = '
' + expectedTitle + '
'; @@ -173,7 +178,7 @@ describe('Doc reporter', function () { '
' + expectedEscapedBody + '
\n', '
' + expectedEscapedError + '
\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); }); diff --git a/test/reporters/dot.spec.js b/test/reporters/dot.spec.js index 228487ff0d..b423f20b24 100644 --- a/test/reporters/dot.spec.js +++ b/test/reporters/dot.spec.js @@ -16,8 +16,9 @@ describe('Dot reporter', function () { beforeEach(function () { stdout = []; stdoutWrite = process.stdout.write; - process.stdout.write = function (string) { + process.stdout.write = function (string, enc, callback) { stdout.push(string); + stdoutWrite.call(process.stdout, string, enc, callback); }; useColors = Base.useColors; windowWidth = Base.window.width; @@ -28,6 +29,7 @@ describe('Dot reporter', function () { afterEach(function () { Base.useColors = useColors; Base.window.width = windowWidth; + process.stdout.write = stdoutWrite; }); describe('on start', function () { @@ -38,7 +40,7 @@ describe('Dot reporter', function () { var expectedArray = [ '\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); describe('on pending', function () { @@ -54,7 +56,7 @@ describe('Dot reporter', function () { '\n ', Base.symbols.comma ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); describe('if window width is equal to or less than 1', function () { @@ -65,7 +67,7 @@ describe('Dot reporter', function () { var expectedArray = [ Base.symbols.comma ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); }); @@ -87,7 +89,7 @@ describe('Dot reporter', function () { '\n ', Base.symbols.dot ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); }); @@ -100,7 +102,7 @@ describe('Dot reporter', function () { var expectedArray = [ Base.symbols.dot ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); describe('if test speed is slow', function () { @@ -112,7 +114,7 @@ describe('Dot reporter', function () { var expectedArray = [ Base.symbols.dot ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); }); @@ -135,7 +137,7 @@ describe('Dot reporter', function () { '\n ', Base.symbols.bang ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); describe('if window width is equal to or less than 1', function () { @@ -146,7 +148,7 @@ describe('Dot reporter', function () { var expectedArray = [ Base.symbols.bang ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); }); @@ -159,7 +161,7 @@ describe('Dot reporter', function () { }; Dot.call({epilogue: epilogue}, runner); process.stdout.write = stdoutWrite; - expect(epilogueCalled).to.be(true); + expect(epilogueCalled, 'to be', true); }); }); }); diff --git a/test/reporters/json-stream.spec.js b/test/reporters/json-stream.spec.js index 0d11597038..a264eb9db8 100644 --- a/test/reporters/json-stream.spec.js +++ b/test/reporters/json-stream.spec.js @@ -25,11 +25,16 @@ describe('Json Stream reporter', function () { beforeEach(function () { stdout = []; stdoutWrite = process.stdout.write; - process.stdout.write = function (string) { + process.stdout.write = function (string, enc, callback) { stdout.push(string); + stdoutWrite.call(process.stdout, string, enc, callback); }; }); + afterEach(function () { + process.stdout.write = stdoutWrite; + }); + describe('on start', function () { it('should write stringified start with expected total', function () { runner = createMockRunner('start', 'start'); @@ -39,7 +44,7 @@ describe('Json Stream reporter', function () { process.stdout.write = stdoutWrite; - expect(stdout[0]).to.eql('["start",{"total":' + expectedTotal + '}]\n'); + expect(stdout[0], 'to equal', '["start",{"total":' + expectedTotal + '}]\n'); }); }); @@ -50,7 +55,7 @@ describe('Json Stream reporter', function () { process.stdout.write = stdoutWrite; - expect(stdout[0]).to.eql('["pass",{"title":"' + expectedTitle + '","fullTitle":"' + expectedFullTitle + '","duration":' + expectedDuration + ',"currentRetry":' + currentRetry + '}]\n'); + expect(stdout[0], 'to equal', '["pass",{"title":"' + expectedTitle + '","fullTitle":"' + expectedFullTitle + '","duration":' + expectedDuration + ',"currentRetry":' + currentRetry + '}]\n'); }); }); @@ -64,7 +69,7 @@ describe('Json Stream reporter', function () { process.stdout.write = stdoutWrite; - expect(stdout[0]).to.eql('["fail",{"title":"' + expectedTitle + '","fullTitle":"' + expectedFullTitle + '","duration":' + expectedDuration + ',"currentRetry":' + currentRetry + ',"err":"' + expectedErrorMessage + '","stack":"' + expectedErrorStack + '"}]\n'); + expect(stdout[0], 'to equal', '["fail",{"title":"' + expectedTitle + '","fullTitle":"' + expectedFullTitle + '","duration":' + expectedDuration + ',"currentRetry":' + currentRetry + ',"err":"' + expectedErrorMessage + '","stack":"' + expectedErrorStack + '"}]\n'); }); }); @@ -76,7 +81,7 @@ describe('Json Stream reporter', function () { JSONStream.call({}, runner); process.stdout.write = stdoutWrite; - expect(stdout[0]).to.eql('["fail",{"title":"' + expectedTitle + '","fullTitle":"' + expectedFullTitle + '","duration":' + expectedDuration + ',"currentRetry":' + currentRetry + ',"err":"' + expectedErrorMessage + '","stack":null}]\n'); + expect(stdout[0], 'to equal', '["fail",{"title":"' + expectedTitle + '","fullTitle":"' + expectedFullTitle + '","duration":' + expectedDuration + ',"currentRetry":' + currentRetry + ',"err":"' + expectedErrorMessage + '","stack":null}]\n'); }); }); }); @@ -86,7 +91,7 @@ describe('Json Stream reporter', function () { runner = createMockRunner('end', 'end'); JSONStream.call({}, runner); process.stdout.write = stdoutWrite; - expect(stdout[0]).to.match(/end/); + expect(stdout[0], 'to match', /end/); }); }); }); diff --git a/test/reporters/json.spec.js b/test/reporters/json.spec.js index a40eead75f..82ac385d7d 100644 --- a/test/reporters/json.spec.js +++ b/test/reporters/json.spec.js @@ -27,17 +27,17 @@ describe('json reporter', function () { })); runner.run(function (failureCount) { - expect(failureCount).to.be(1); - expect(runner).to.have.property('testResults'); - expect(runner.testResults).to.have.property('failures'); - expect(runner.testResults.failures).to.be.an('array'); - expect(runner.testResults.failures).to.have.length(1); - - var failure = runner.testResults.failures[0]; - expect(failure).to.have.property('title', testTitle); - expect(failure.err.message).to.equal(error.message); - expect(failure).to.have.property('err'); - + expect(runner, 'to satisfy', { + testResults: { + failures: [{ + title: testTitle, + err: { + message: error.message + } + }] + } + }); + expect(failureCount, 'to be', 1); done(); }); }); @@ -46,15 +46,14 @@ describe('json reporter', function () { suite.addTest(new Test(testTitle)); runner.run(function (failureCount) { - expect(failureCount).to.be(0); - expect(runner).to.have.property('testResults'); - expect(runner.testResults).to.have.property('pending'); - expect(runner.testResults.pending).to.be.an('array'); - expect(runner.testResults.pending).to.have.length(1); - - var pending = runner.testResults.pending[0]; - expect(pending).to.have.property('title', testTitle); - + expect(runner, 'to satisfy', { + testResults: { + pending: [{ + title: testTitle + }] + } + }); + expect(failureCount, 'to be', 0); done(); }); }); @@ -72,16 +71,17 @@ describe('json reporter', function () { })); runner.run(function (failureCount) { - expect(failureCount).to.equal(1); - expect(runner).to.have.property('testResults'); - expect(runner.testResults).to.have.property('failures'); - expect(runner.testResults.failures).to.be.an(Array); - expect(runner.testResults.failures).to.have.length(1); - - var failure = runner.testResults.failures[0]; - expect(failure).to.have.property('title', testTitle); - expect(failure).to.have.property('err'); - + expect(runner, 'to satisfy', { + testResults: { + failures: [{ + title: testTitle, + err: { + message: error.message + } + }] + } + }); + expect(failureCount, 'to be', 1); done(); }); }); diff --git a/test/reporters/landing.spec.js b/test/reporters/landing.spec.js index 633c29e823..adfe5b4c44 100644 --- a/test/reporters/landing.spec.js +++ b/test/reporters/landing.spec.js @@ -27,8 +27,9 @@ describe('Landing reporter', function () { beforeEach(function () { stdout = []; stdoutWrite = process.stdout.write; - process.stdout.write = function (string) { + process.stdout.write = function (string, enc, callback) { stdout.push(string); + stdoutWrite.call(process.stdout, string, enc, callback); }; useColors = Base.useColors; Base.useColors = false; @@ -39,6 +40,7 @@ describe('Landing reporter', function () { afterEach(function () { Base.useColors = useColors; Base.window.width = windowWidth; + process.stdout.write = stdoutWrite; }); describe('on start', function () { @@ -50,7 +52,7 @@ describe('Landing reporter', function () { process.stdout.write = stdoutWrite; - expect(stdout[0]).to.eql('\n\n\n '); + expect(stdout[0], 'to equal', '\n\n\n '); Base.cursor = cachedCursor; }); @@ -64,7 +66,7 @@ describe('Landing reporter', function () { Landing.call({}, runner); process.stdout.write = stdoutWrite; - expect(calledCursorHide).to.be(true); + expect(calledCursorHide, 'to be', true); Base.cursor = cachedCursor; }); @@ -82,7 +84,7 @@ describe('Landing reporter', function () { process.stdout.write = stdoutWrite; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); describe('if test has not failed', function () { @@ -96,7 +98,7 @@ describe('Landing reporter', function () { process.stdout.write = stdoutWrite; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); }); @@ -117,8 +119,8 @@ describe('Landing reporter', function () { }, runner); process.stdout.write = stdoutWrite; - expect(calledEpilogue).to.be(true); - expect(calledCursorShow).to.be(true); + expect(calledEpilogue, 'to be', true); + expect(calledCursorShow, 'to be', true); Base.cursor = cachedCursor; }); diff --git a/test/reporters/list.spec.js b/test/reporters/list.spec.js index 7871caf82e..2e8b0d3967 100644 --- a/test/reporters/list.spec.js +++ b/test/reporters/list.spec.js @@ -23,8 +23,9 @@ describe('List reporter', function () { beforeEach(function () { stdout = []; stdoutWrite = process.stdout.write; - process.stdout.write = function (string) { + process.stdout.write = function (string, enc, callback) { stdout.push(string); + stdoutWrite.call(process.stdout, string, enc, callback); }; useColors = Base.useColors; Base.useColors = false; @@ -32,6 +33,7 @@ describe('List reporter', function () { afterEach(function () { Base.useColors = useColors; + process.stdout.write = stdoutWrite; }); describe('on start and test', function () { @@ -46,7 +48,7 @@ describe('List reporter', function () { startString, testString ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); describe('on pending', function () { @@ -56,7 +58,7 @@ describe('List reporter', function () { process.stdout.write = stdoutWrite; - expect(stdout[0]).to.eql(' - ' + expectedTitle + '\n'); + expect(stdout[0], 'to equal', ' - ' + expectedTitle + '\n'); }); }); describe('on pass', function () { @@ -71,7 +73,7 @@ describe('List reporter', function () { process.stdout.write = stdoutWrite; - expect(calledCursorCR).to.be(true); + expect(calledCursorCR, 'to be', true); Base.cursor = cachedCursor; }); @@ -86,7 +88,7 @@ describe('List reporter', function () { process.stdout.write = stdoutWrite; - expect(stdout[0]).to.equal(' ' + expectedOkSymbol + ' ' + expectedTitle + ': ' + expectedDuration + 'ms\n'); + expect(stdout[0], 'to be', ' ' + expectedOkSymbol + ' ' + expectedTitle + ': ' + expectedDuration + 'ms\n'); Base.cursor = cachedCursor; Base.symbols = cachedSymbols; @@ -104,7 +106,7 @@ describe('List reporter', function () { process.stdout.write = stdoutWrite; - expect(calledCursorCR).to.be(true); + expect(calledCursorCR, 'to be', true); Base.cursor = cachedCursor; }); @@ -117,7 +119,7 @@ describe('List reporter', function () { process.stdout.write = stdoutWrite; - expect(stdout[0]).to.equal(' ' + expectedErrorCount + ') ' + expectedTitle + '\n'); + expect(stdout[0], 'to be', ' ' + expectedErrorCount + ') ' + expectedTitle + '\n'); Base.cursor = cachedCursor; }); @@ -140,8 +142,8 @@ describe('List reporter', function () { List.call({epilogue: function () {}}, runner); process.stdout.write = stdoutWrite; - expect(typeof err.actual).to.equal('string'); - expect(typeof err.expected).to.equal('string'); + expect(typeof err.actual, 'to be', 'string'); + expect(typeof err.expected, 'to be', 'string'); }); }); @@ -156,7 +158,7 @@ describe('List reporter', function () { }, runner); process.stdout.write = stdoutWrite; - expect(calledEpilogue).to.be(true); + expect(calledEpilogue, 'to be', true); }); }); }); diff --git a/test/reporters/markdown.spec.js b/test/reporters/markdown.spec.js index f6fcf095e0..e711187cc9 100644 --- a/test/reporters/markdown.spec.js +++ b/test/reporters/markdown.spec.js @@ -16,11 +16,16 @@ describe('Markdown reporter', function () { beforeEach(function () { stdout = []; stdoutWrite = process.stdout.write; - process.stdout.write = function (string) { + process.stdout.write = function (string, enc, callback) { stdout.push(string); + stdoutWrite.call(process.stdout, string, enc, callback); }; }); + afterEach(function () { + process.stdout.write = stdoutWrite; + }); + describe('on \'suite\'', function () { it('should write expected slugged titles on \'end\' event', function () { var expectedSuite = { @@ -43,7 +48,7 @@ describe('Markdown reporter', function () { '\n ' + expectedTitle + '\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); describe('on \'pass\'', function () { @@ -75,7 +80,7 @@ describe('Markdown reporter', function () { expectedTitle + '.\n\n```js\n' + expectedBody + '\n```\n\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); }); diff --git a/test/reporters/min.spec.js b/test/reporters/min.spec.js index 1312e21ea8..640876c578 100644 --- a/test/reporters/min.spec.js +++ b/test/reporters/min.spec.js @@ -13,11 +13,16 @@ describe('Min reporter', function () { beforeEach(function () { stdout = []; stdoutWrite = process.stdout.write; - process.stdout.write = function (string) { + process.stdout.write = function (string, enc, callback) { stdout.push(string); + stdoutWrite.call(process.stdout, string, enc, callback); }; }); + afterEach(function () { + process.stdout.write = stdoutWrite; + }); + describe('on start', function () { it('should clear screen then set cursor position', function () { runner = createMockRunner('start', 'start'); @@ -28,7 +33,7 @@ describe('Min reporter', function () { '\u001b[2J', '\u001b[1;3H' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); @@ -43,7 +48,7 @@ describe('Min reporter', function () { }, runner); process.stdout.write = stdoutWrite; - expect(calledEpilogue).to.be(true); + expect(calledEpilogue, 'to be', true); }); }); }); diff --git a/test/reporters/nyan.spec.js b/test/reporters/nyan.spec.js index 43e8c778e1..a6fe221f2c 100644 --- a/test/reporters/nyan.spec.js +++ b/test/reporters/nyan.spec.js @@ -16,11 +16,16 @@ describe('Nyan reporter', function () { beforeEach(function () { stdout = []; stdoutWrite = process.stdout.write; - process.stdout.write = function (string) { + process.stdout.write = function (string, enc, callback) { stdout.push(string); + stdoutWrite.call(process.stdout, string, enc, callback); }; }); + afterEach(function () { + process.stdout.write = stdoutWrite; + }); + describe('on start', function () { it('should call draw', function () { calledDraw = false; @@ -33,7 +38,7 @@ describe('Nyan reporter', function () { }, runner); process.stdout.write = stdoutWrite; - expect(calledDraw).to.be(true); + expect(calledDraw, 'to be', true); }); }); describe('on pending', function () { @@ -48,7 +53,7 @@ describe('Nyan reporter', function () { }, runner); process.stdout.write = stdoutWrite; - expect(calledDraw).to.be(true); + expect(calledDraw, 'to be', true); }); }); describe('on pass', function () { @@ -67,7 +72,7 @@ describe('Nyan reporter', function () { }, runner); process.stdout.write = stdoutWrite; - expect(calledDraw).to.be(true); + expect(calledDraw, 'to be', true); }); }); describe('on fail', function () { @@ -85,7 +90,7 @@ describe('Nyan reporter', function () { }, runner); process.stdout.write = stdoutWrite; - expect(calledDraw).to.be(true); + expect(calledDraw, 'to be', true); }); }); describe('on end', function () { @@ -101,7 +106,7 @@ describe('Nyan reporter', function () { }, runner); process.stdout.write = stdoutWrite; - expect(calledEpilogue).to.be(true); + expect(calledEpilogue, 'to be', true); }); it('should write numberOfLines amount of new lines', function () { var expectedNumberOfLines = 4; @@ -115,7 +120,7 @@ describe('Nyan reporter', function () { var arrayOfNewlines = stdout.filter(function (value) { return value === '\n'; }); process.stdout.write = stdoutWrite; - expect(arrayOfNewlines).to.have.length(expectedNumberOfLines); + expect(arrayOfNewlines, 'to have length', expectedNumberOfLines); }); it('should call Base show', function () { var showCalled = false; @@ -131,7 +136,7 @@ describe('Nyan reporter', function () { }, runner); process.stdout.write = stdoutWrite; - expect(showCalled).to.be(true); + expect(showCalled, 'to be', true); Base.cursor.show = cachedShow; }); }); @@ -144,11 +149,15 @@ describe('Nyan reporter', function () { beforeEach(function () { stdout = []; stdoutWrite = process.stdout.write; - process.stdout.write = function (string) { + process.stdout.write = function (string, enc, callback) { stdout.push(string); }; }); + afterEach(function () { + process.stdout.write = stdoutWrite; + }); + describe('if tick is false', function () { it('should draw face with expected spaces, _ and ^', function () { var nyanCat = new NyanCat({on: function () {}, once: function () {}}); @@ -182,7 +191,7 @@ describe('Nyan reporter', function () { ' "" "" ', '\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); describe('if tick is true', function () { @@ -203,7 +212,7 @@ describe('Nyan reporter', function () { cursorUp: function () {} }); - process.stdout.write = stdoutWrite; + // process.stdout.write = stdoutWrite; var expectedArray = [ '\u001b[0C', '_,------,', @@ -218,7 +227,7 @@ describe('Nyan reporter', function () { ' "" "" ', '\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); }); @@ -235,6 +244,10 @@ describe('Nyan reporter', function () { }; }); + afterEach(function () { + process.stdout.write = stdoutWrite; + }); + it('should write cursor down interaction with expected number', function () { var nyanCat = new NyanCat({on: function () {}, once: function () {}}); var expectedNumber = 25; @@ -244,7 +257,7 @@ describe('Nyan reporter', function () { var expectedArray = [ '\u001b[' + expectedNumber + 'B' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); @@ -255,11 +268,15 @@ describe('Nyan reporter', function () { beforeEach(function () { stdout = []; stdoutWrite = process.stdout.write; - process.stdout.write = function (string) { + process.stdout.write = function (string, enc, callback) { stdout.push(string); }; }); + afterEach(function () { + process.stdout.write = stdoutWrite; + }); + it('should write cursor up interaction with expected number', function () { var nyanCat = new NyanCat({on: function () {}, once: function () {}}); var expectedNumber = 25; @@ -269,7 +286,7 @@ describe('Nyan reporter', function () { var expectedArray = [ '\u001b[' + expectedNumber + 'A' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); @@ -291,7 +308,7 @@ describe('Nyan reporter', function () { var expectedString = 'hello'; var outputString = nyanCat.rainbowify(expectedString); - expect(outputString).to.equal(expectedString); + expect(outputString, 'to be', expectedString); }); }); describe('useColors is true', function () { @@ -319,7 +336,7 @@ describe('Nyan reporter', function () { }, expectedString); - expect(outputString).to.equal(expectedRainbowifyString); + expect(outputString, 'to be', expectedRainbowifyString); }); }); }); @@ -341,7 +358,7 @@ describe('Nyan reporter', function () { trajectories: trajectories }); - expect(expectedSegment).to.equal('_'); + expect(expectedSegment, 'to be', '_'); }); it('should shift each trajectory item, if its length is greater of equal to its max width', function () { var nyanCat = new NyanCat({on: function () {}, once: function () {}}); @@ -359,7 +376,7 @@ describe('Nyan reporter', function () { trajectories: trajectories }); - expect(trajectories).to.eql(expectedTrajectories); + expect(trajectories, 'to equal', expectedTrajectories); }); }); describe('if tick is false', function () { @@ -378,23 +395,35 @@ describe('Nyan reporter', function () { trajectories: trajectories }); - expect(expectedSegment).to.eql('-'); + expect(expectedSegment, 'to equal', '-'); }); }); }); describe('drawScoreboard', function () { - it('should write scoreboard with color set with each stat', function () { - var cachedColor = Base.color; + var stdoutWrite; + var stdout; + var cachedColor; + + beforeEach(function () { + stdout = []; + stdoutWrite = process.stdout.write; + process.stdout.write = function (string, enc, callback) { + stdout.push(string); + stdoutWrite.call(process.stdout, string, enc, callback); + }; + cachedColor = Base.color; Base.color = function (type, n) { return type + n; }; - var stdout = []; - var stdoutWrite = process.stdout.write; - process.stdout.write = function (string) { - stdout.push(string); - }; + }); + afterEach(function () { + process.stdout.write = stdoutWrite; + Base.color = cachedColor; + }); + + it('should write scoreboard with color set with each stat', function () { var passes = 2; var pending = 1; var failures = 1; @@ -416,16 +445,10 @@ describe('Nyan reporter', function () { '\n', '\n' ]; - expect(stdout).to.eql(expectedArray); - process.stdout.write = stdoutWrite; - Base.color = cachedColor; + expect(stdout, 'to equal', expectedArray); }); + it('should call cursorUp with given numberOfLines', function () { - var stdout = []; - var stdoutWrite = process.stdout.write; - process.stdout.write = function (string) { - stdout.push(string); - }; var expectedCursorArgument = null; var expectedNumberOfLines = 1000; @@ -438,18 +461,28 @@ describe('Nyan reporter', function () { numberOfLines: expectedNumberOfLines }); - expect(expectedCursorArgument).to.equal(expectedNumberOfLines); - process.stdout.write = stdoutWrite; + expect(expectedCursorArgument, 'to be', expectedNumberOfLines); }); }); describe('drawRainbow', function () { - it('should write width, contents and newline for each trajectory', function () { - var stdout = []; - var stdoutWrite = process.stdout.write; - process.stdout.write = function (string) { + var stdoutWrite; + var stdout; + + beforeEach(function () { + stdout = []; + stdoutWrite = process.stdout.write; + process.stdout.write = function (string, enc, callback) { stdout.push(string); + stdoutWrite.call(process.stdout, string, enc, callback); }; + }); + + afterEach(function () { + process.stdout.write = stdoutWrite; + }); + + it('should write width, contents and newline for each trajectory', function () { var expectedWidth = 444; var expectedContents = 'input'; @@ -469,15 +502,10 @@ describe('Nyan reporter', function () { expectedContents, '\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); it('should call cursorUp with given numberOfLines', function () { - var stdout = []; - var stdoutWrite = process.stdout.write; - process.stdout.write = function (string) { - stdout.push(string); - }; var expectedCursorArgument = null; var expectedNumberOfLines = 1000; @@ -491,33 +519,32 @@ describe('Nyan reporter', function () { numberOfLines: expectedNumberOfLines }); - expect(expectedCursorArgument).to.equal(expectedNumberOfLines); - process.stdout.write = stdoutWrite; + expect(expectedCursorArgument, 'to be', expectedNumberOfLines); }); }); describe('face', function () { it('expected face:(x .x) when "failures" at least one', function () { var nyanCat = new NyanCat({on: function () {}, once: function () {}}); nyanCat.stats = { passes: 2, pending: 1, failures: 1 }; - expect(nyanCat.face()).to.equal('( x .x)'); + expect(nyanCat.face(), 'to be', '( x .x)'); }); it('expected face:(x .x) when "pending" at least one and no failing', function () { var nyanCat = new NyanCat({on: function () {}, once: function () {}}); nyanCat.stats = { passes: 2, pending: 1, failures: 0 }; - expect(nyanCat.face()).to.equal('( o .o)'); + expect(nyanCat.face(), 'to be', '( o .o)'); }); it('expected face:(^ .^) when "passing" only', function () { var nyanCat = new NyanCat({on: function () {}, once: function () {}}); nyanCat.stats = { passes: 1, pending: 0, failures: 0 }; - expect(nyanCat.face()).to.equal('( ^ .^)'); + expect(nyanCat.face(), 'to be', '( ^ .^)'); }); it('expected face:(- .-) when otherwise', function (done) { var nyanCat = new NyanCat({on: function () {}, once: function () {}}); nyanCat.stats = { passes: 0, pending: 0, failures: 0 }; - expect(nyanCat.face()).to.equal('( - .-)'); + expect(nyanCat.face(), 'to be', '( - .-)'); done(); }); }); diff --git a/test/reporters/progress.spec.js b/test/reporters/progress.spec.js index 47818f841d..9c8c5d99cb 100644 --- a/test/reporters/progress.spec.js +++ b/test/reporters/progress.spec.js @@ -14,11 +14,16 @@ describe('Progress reporter', function () { beforeEach(function () { stdout = []; stdoutWrite = process.stdout.write; - process.stdout.write = function (string) { + process.stdout.write = function (string, enc, callback) { stdout.push(string); + stdoutWrite.call(process.stdout, string, enc, callback); }; }); + afterEach(function () { + process.stdout.write = stdoutWrite; + }); + describe('on start', function () { it('should call cursor hide', function () { var cachedCursor = Base.cursor; @@ -30,7 +35,7 @@ describe('Progress reporter', function () { Progress.call({}, runner); process.stdout.write = stdoutWrite; - expect(calledCursorHide).to.be(true); + expect(calledCursorHide, 'to be', true); Base.cursor = cachedCursor; }); @@ -54,7 +59,7 @@ describe('Progress reporter', function () { process.stdout.write = stdoutWrite; - expect(stdout).to.eql([]); + expect(stdout, 'to equal', []); Base.cursor = cachedCursor; Base.useColors = useColors; @@ -98,8 +103,8 @@ describe('Progress reporter', function () { expectedIncomplete, expectedClose ]; - expect(calledCursorCR).to.be(true); - expect(stdout).to.eql(expectedArray); + expect(calledCursorCR, 'to be', true); + expect(stdout, 'to equal', expectedArray); Base.cursor = cachedCursor; Base.useColors = useColors; @@ -124,8 +129,8 @@ describe('Progress reporter', function () { }, runner); process.stdout.write = stdoutWrite; - expect(calledEpilogue).to.be(true); - expect(calledCursorShow).to.be(true); + expect(calledEpilogue, 'to be', true); + expect(calledCursorShow, 'to be', true); Base.cursor = cachedCursor; }); diff --git a/test/reporters/spec.spec.js b/test/reporters/spec.spec.js index cb662e4530..ec801334f1 100644 --- a/test/reporters/spec.spec.js +++ b/test/reporters/spec.spec.js @@ -16,8 +16,9 @@ describe('Spec reporter', function () { beforeEach(function () { stdout = []; stdoutWrite = process.stdout.write; - process.stdout.write = function (string) { + process.stdout.write = function (string, enc, callback) { stdout.push(string); + stdoutWrite.call(process.stdout, string, enc, callback); }; useColors = Base.useColors; Base.useColors = false; @@ -25,6 +26,7 @@ describe('Spec reporter', function () { afterEach(function () { Base.useColors = useColors; + process.stdout.write = stdoutWrite; }); describe('on suite', function () { @@ -38,7 +40,7 @@ describe('Spec reporter', function () { var expectedArray = [ expectedTitle + '\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); describe('on pending', function () { @@ -52,7 +54,7 @@ describe('Spec reporter', function () { var expectedArray = [ ' - ' + expectedTitle + '\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); describe('on pass', function () { @@ -68,7 +70,7 @@ describe('Spec reporter', function () { Spec.call({epilogue: function () {}}, runner); process.stdout.write = stdoutWrite; var expectedString = ' ' + Base.symbols.ok + ' ' + expectedTitle + ' (' + expectedDuration + 'ms)' + '\n'; - expect(stdout[0]).to.equal(expectedString); + expect(stdout[0], 'to be', expectedString); }); }); describe('if test speed is fast', function () { @@ -83,7 +85,7 @@ describe('Spec reporter', function () { Spec.call({epilogue: function () {}}, runner); process.stdout.write = stdoutWrite; var expectedString = ' ' + Base.symbols.ok + ' ' + expectedTitle + '\n'; - expect(stdout[0]).to.equal(expectedString); + expect(stdout[0], 'to be', expectedString); }); }); }); @@ -99,7 +101,7 @@ describe('Spec reporter', function () { var expectedArray = [ ' ' + functionCount + ') ' + expectedTitle + '\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); }); diff --git a/test/reporters/tap.spec.js b/test/reporters/tap.spec.js index 9b7eac9491..ac0fe46260 100644 --- a/test/reporters/tap.spec.js +++ b/test/reporters/tap.spec.js @@ -16,8 +16,9 @@ describe('TAP reporter', function () { beforeEach(function () { stdout = []; stdoutWrite = process.stdout.write; - process.stdout.write = function (string) { + process.stdout.write = function (string, enc, callback) { stdout.push(string); + stdoutWrite.call(process.stdout, string, enc, callback); }; test = { fullTitle: function () { @@ -27,6 +28,10 @@ describe('TAP reporter', function () { }; }); + afterEach(function () { + process.stdout.write = stdoutWrite; + }); + describe('on start', function () { it('should hand runners suite into grepTotal and log the total', function () { var expectedSuite = 'some suite'; @@ -45,8 +50,8 @@ describe('TAP reporter', function () { ]; process.stdout.write = stdoutWrite; - expect(stdout).to.eql(expectedArray); - expect(expectedString).to.equal(expectedSuite); + expect(stdout, 'to equal', expectedArray); + expect(expectedString, 'to be', expectedSuite); }); }); @@ -60,7 +65,7 @@ describe('TAP reporter', function () { process.stdout.write = stdoutWrite; var expectedMessage = 'ok ' + countAfterTestEnd + ' ' + expectedTitle + ' # SKIP -\n'; - expect(stdout[0]).to.eql(expectedMessage); + expect(stdout[0], 'to equal', expectedMessage); }); }); @@ -75,7 +80,7 @@ describe('TAP reporter', function () { process.stdout.write = stdoutWrite; var expectedMessage = 'ok ' + countAfterTestEnd + ' ' + expectedTitle + '\n'; - expect(stdout[0]).to.eql(expectedMessage); + expect(stdout[0], 'to equal', expectedMessage); }); }); @@ -112,7 +117,7 @@ describe('TAP reporter', function () { 'not ok ' + countAfterTestEnd + ' ' + expectedTitle + '\n', ' ' + expectedErrorMessage + '\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); describe('if there is an error stack', function () { @@ -132,7 +137,7 @@ describe('TAP reporter', function () { 'not ok ' + countAfterTestEnd + ' ' + expectedTitle + '\n', ' ' + expectedStack + '\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); describe('if there is an error stack and error message', function () { @@ -170,7 +175,7 @@ describe('TAP reporter', function () { ' ' + expectedErrorMessage + '\n', ' ' + expectedStack + '\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); describe('if there is no error stack or error message', function () { @@ -193,7 +198,7 @@ describe('TAP reporter', function () { var expectedArray = [ 'not ok ' + countAfterTestEnd + ' ' + expectedTitle + '\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); }); @@ -217,7 +222,7 @@ describe('TAP reporter', function () { '# pass ' + numberOfPasses + '\n', '# fail ' + numberOfFails + '\n' ]; - expect(stdout).to.eql(expectedArray); + expect(stdout, 'to equal', expectedArray); }); }); }); diff --git a/test/reporters/xunit.spec.js b/test/reporters/xunit.spec.js index c0c066d60b..cfe532b694 100644 --- a/test/reporters/xunit.spec.js +++ b/test/reporters/xunit.spec.js @@ -39,7 +39,7 @@ describe('XUnit reporter', function () { fs.createWriteStream = false; var boundXUnit = XUnit.bind({}, runner, options); - expect(boundXUnit).to.throwException('file output not supported in browser'); + expect(boundXUnit, 'to throw', 'file output not supported in browser'); fs.createWriteStream = fsCreateWriteStream; }); }); @@ -58,8 +58,8 @@ describe('XUnit reporter', function () { }; XUnit.call(contextVariables, runner, options); - expect(expectedDirectory).to.equal(expectedOutput); - expect(contextVariables.fileStream).to.equal(expectedOutput); + expect(expectedDirectory, 'to be', expectedOutput); + expect(contextVariables.fileStream, 'to be', expectedOutput); fs.createWriteStream = fsCreateWriteStream; mkdirp.sync = mkdirpSync; @@ -110,7 +110,7 @@ describe('XUnit reporter', function () { passTest, failTest ]; - expect(calledTests).to.eql(expectedCalledTests); + expect(calledTests, 'to equal', expectedCalledTests); }); }); @@ -134,8 +134,8 @@ describe('XUnit reporter', function () { callback ); - expect(calledEnd).to.be(true); - expect(callbackArgument).to.equal(expectedFailure); + expect(calledEnd, 'to be', true); + expect(callbackArgument, 'to be', expectedFailure); }); }); describe('if fileStream is falsy', function () { @@ -150,7 +150,7 @@ describe('XUnit reporter', function () { callback ); - expect(callbackArgument).to.equal(expectedFailure); + expect(callbackArgument, 'to be', expectedFailure); }); }); }); @@ -169,7 +169,7 @@ describe('XUnit reporter', function () { expectedLine ); - expect(expectedWrite).to.equal(expectedLine + '\n'); + expect(expectedWrite, 'to be', expectedLine + '\n'); }); }); describe('if fileStream is falsy and stdout exists', function () { @@ -187,7 +187,7 @@ describe('XUnit reporter', function () { process.stdout.write = stdoutWrite; - expect(stdout[0]).to.equal(expectedLine + '\n'); + expect(stdout[0], 'to be', expectedLine + '\n'); }); }); describe('if fileStream is falsy and stdout does not exist', function () { @@ -207,7 +207,7 @@ describe('XUnit reporter', function () { console.log = cachedConsoleLog; process = stdoutWrite; // eslint-disable-line no-native-reassign, no-global-assign - expect(stdout[0]).to.equal(expectedLine); + expect(stdout[0], 'to be', expectedLine); }); }); }); @@ -241,7 +241,7 @@ describe('XUnit reporter', function () { var expectedTag = '' + expectedMessage + '\n' + expectedStack + ''; - expect(expectedWrite).to.equal(expectedTag); + expect(expectedWrite, 'to be', expectedTag); }); }); describe('on test pending', function () { @@ -269,7 +269,7 @@ describe('XUnit reporter', function () { var expectedTag = ''; - expect(expectedWrite).to.equal(expectedTag); + expect(expectedWrite, 'to be', expectedTag); }); }); describe('on test in any other state', function () { @@ -297,7 +297,7 @@ describe('XUnit reporter', function () { var expectedTag = ''; - expect(expectedWrite).to.equal(expectedTag); + expect(expectedWrite, 'to be', expectedTag); }); }); });