Skip to content

Commit

Permalink
convert all individual reporter tests to unexpected
Browse files Browse the repository at this point in the history
also don't eat `STDOUT`--this means the tests have more output--could be
useful for debugging.

Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
  • Loading branch information
boneskull committed Apr 21, 2018
1 parent 190f5ed commit 0d7635e
Show file tree
Hide file tree
Showing 13 changed files with 233 additions and 168 deletions.
25 changes: 15 additions & 10 deletions test/reporters/doc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -34,7 +39,7 @@ describe('Doc reporter', function () {
' <h1>' + expectedTitle + '</h1>\n',
' <dl>\n'
];
expect(stdout).to.eql(expectedArray);
expect(stdout, 'to equal', expectedArray);
});
it('should escape title where necessary', function () {
var suite = {
Expand All @@ -50,7 +55,7 @@ describe('Doc reporter', function () {
' <h1>' + expectedTitle + '</h1>\n',
' <dl>\n'
];
expect(stdout).to.eql(expectedArray);
expect(stdout, 'to equal', expectedArray);
});
});
describe('if suite root does exist', function () {
Expand All @@ -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');
});
});
});
Expand All @@ -78,7 +83,7 @@ describe('Doc reporter', function () {
var expectedArray = [
' </dl>\n', '</section>\n'
];
expect(stdout).to.eql(expectedArray);
expect(stdout, 'to equal', expectedArray);
});
});
describe('if suite root does exist', function () {
Expand All @@ -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');
});
});
});
Expand All @@ -112,7 +117,7 @@ describe('Doc reporter', function () {
' <dt>' + expectedTitle + '</dt>\n',
' <dd><pre><code>' + expectedBody + '</code></pre></dd>\n'
];
expect(stdout).to.eql(expectedArray);
expect(stdout, 'to equal', expectedArray);
});
it('should escape title and body where necessary', function () {
var unescapedTitle = '<div>' + expectedTitle + '</div>';
Expand All @@ -129,7 +134,7 @@ describe('Doc reporter', function () {
' <dt>' + expectedEscapedTitle + '</dt>\n',
' <dd><pre><code>' + expectedEscapedBody + '</code></pre></dd>\n'
];
expect(stdout).to.eql(expectedArray);
expect(stdout, 'to equal', expectedArray);
});
});

Expand All @@ -153,7 +158,7 @@ describe('Doc reporter', function () {
' <dd class="error"><pre><code>' + expectedBody + '</code></pre></dd>\n',
' <dd class="error">' + expectedError + '</dd>\n'
];
expect(stdout).to.eql(expectedArray);
expect(stdout, 'to equal', expectedArray);
});
it('should escape title, body and error where necessary', function () {
var unescapedTitle = '<div>' + expectedTitle + '</div>';
Expand All @@ -173,7 +178,7 @@ describe('Doc reporter', function () {
' <dd class="error"><pre><code>' + expectedEscapedBody + '</code></pre></dd>\n',
' <dd class="error">' + expectedEscapedError + '</dd>\n'
];
expect(stdout).to.eql(expectedArray);
expect(stdout, 'to equal', expectedArray);
});
});
});
22 changes: 12 additions & 10 deletions test/reporters/dot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -65,7 +67,7 @@ describe('Dot reporter', function () {
var expectedArray = [
Base.symbols.comma
];
expect(stdout).to.eql(expectedArray);
expect(stdout, 'to equal', expectedArray);
});
});
});
Expand All @@ -87,7 +89,7 @@ describe('Dot reporter', function () {
'\n ',
Base.symbols.dot
];
expect(stdout).to.eql(expectedArray);
expect(stdout, 'to equal', expectedArray);
});
});
});
Expand All @@ -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 () {
Expand All @@ -112,7 +114,7 @@ describe('Dot reporter', function () {
var expectedArray = [
Base.symbols.dot
];
expect(stdout).to.eql(expectedArray);
expect(stdout, 'to equal', expectedArray);
});
});
});
Expand All @@ -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 () {
Expand All @@ -146,7 +148,7 @@ describe('Dot reporter', function () {
var expectedArray = [
Base.symbols.bang
];
expect(stdout).to.eql(expectedArray);
expect(stdout, 'to equal', expectedArray);
});
});
});
Expand All @@ -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);
});
});
});
17 changes: 11 additions & 6 deletions test/reporters/json-stream.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
});
});

Expand All @@ -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');
});
});

Expand All @@ -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');
});
});

Expand All @@ -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');
});
});
});
Expand All @@ -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/);
});
});
});
60 changes: 30 additions & 30 deletions test/reporters/json.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand All @@ -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();
});
});
Expand All @@ -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();
});
});
Expand Down
Loading

0 comments on commit 0d7635e

Please sign in to comment.