-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2699 from craigtaub/jsonStreamCoverage
Increase tests coverage for json-stream, markdown and progress reporters
- Loading branch information
Showing
3 changed files
with
385 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
'use strict'; | ||
|
||
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/); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
'<a name="' + sluggedFullTitle + '"></a>\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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
'use strict'; | ||
|
||
var reporters = require('../../').reporters; | ||
var Progress = reporters.Progress; | ||
var Base = reporters.Base; | ||
|
||
describe('Progress 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 () { | ||
describe('if line has not changed', function () { | ||
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; | ||
|
||
var expectedTotal = 1; | ||
var expectedOptions = {}; | ||
runner.total = expectedTotal; | ||
runner.on = function (event, callback) { | ||
if (event === 'test end') { | ||
callback(); | ||
} | ||
}; | ||
Progress.call({}, runner, expectedOptions); | ||
|
||
process.stdout.write = stdoutWrite; | ||
|
||
stdout.should.deepEqual([]); | ||
|
||
Base.cursor = cachedCursor; | ||
Base.useColors = useColors; | ||
Base.window.width = windowWidth; | ||
}); | ||
}); | ||
describe('if line has changed', 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 = 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; | ||
}); | ||
}); | ||
}); | ||
|
||
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; | ||
}); | ||
}); | ||
}); |