Skip to content

Commit

Permalink
100% markdown coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaub committed Feb 3, 2017
1 parent b4bf1f4 commit d7846b6
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 3 deletions.
6 changes: 3 additions & 3 deletions test/reporters/json-stream.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
100 changes: 100 additions & 0 deletions test/reporters/markdown.spec.js
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);
});
});
});

0 comments on commit d7846b6

Please sign in to comment.