Skip to content

Commit

Permalink
reporter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Apr 20, 2020
1 parent 1bf8137 commit e02df82
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
26 changes: 22 additions & 4 deletions test/reporters/base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,25 +426,43 @@ describe('Base reporter', function() {
});

describe('when reporter output immune to user test changes', function() {
var sandbox;
var baseConsoleLog;

beforeEach(function() {
sandbox = sinon.createSandbox();
sandbox.stub(console, 'log');
baseConsoleLog = sandbox.stub(Base, 'consoleLog');
});

it('should let you stub out console.log without effecting reporters output', function() {
Base.list([]);
baseConsoleLog.restore();

expect(baseConsoleLog, 'was called');
expect(console.log, 'was not called');
sandbox.restore();
});
});

describe('epilogue', function() {
it('should include "pending" count', function() {
var ctx = {stats: {passes: 0, pending: 2, skipped: 0, duration: 12}};
var epilogue = Base.prototype.epilogue.bind(ctx);

afterEach(function() {
epilogue();
sandbox.restore();

var out = stdout.join('\n').trim();
expect(out, 'to contain', '2 pending').and('not to contain', 'skipped');
});

it('should include "skipped" count', function() {
var ctx = {stats: {passes: 0, pending: 0, skipped: 3, duration: 12}};
var epilogue = Base.prototype.epilogue.bind(ctx);

epilogue();
sandbox.restore();

var out = stdout.join('\n').trim();
expect(out, 'to contain', '3 skipped').and('not to contain', 'pending');
});
});
});
1 change: 1 addition & 0 deletions test/reporters/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function createRunnerFunction(runStr, ifStr1, ifStr2, ifStr3, arg1, arg2) {
}
};
case 'pending test':
case 'skipped test':
case 'pass':
case 'fail':
case 'suite':
Expand Down
20 changes: 20 additions & 0 deletions test/reporters/json.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ describe('JSON reporter', function() {
});
});

it('should have 1 test skipped', function(done) {
suite.skipped = true;
suite.addTest(new Test(testTitle, noop));

runner.run(function(failureCount) {
sandbox.restore();
expect(runner, 'to satisfy', {
testResults: {
skipped: [
{
title: testTitle
}
]
}
});
expect(failureCount, 'to be', 0);
done();
});
});

it('should handle circular objects in errors', function(done) {
var testTitle = 'json test 1';
function CircleError() {
Expand Down
22 changes: 22 additions & 0 deletions test/reporters/spec.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var EVENT_SUITE_BEGIN = events.EVENT_SUITE_BEGIN;
var EVENT_TEST_FAIL = events.EVENT_TEST_FAIL;
var EVENT_TEST_PASS = events.EVENT_TEST_PASS;
var EVENT_TEST_PENDING = events.EVENT_TEST_PENDING;
var EVENT_TEST_SKIPPED = events.EVENT_TEST_SKIPPED;

describe('Spec reporter', function() {
var runReporter = makeRunReporter(Spec);
Expand Down Expand Up @@ -73,6 +74,27 @@ describe('Spec reporter', function() {
});
});

describe("on 'skipped' event", function() {
it('should return title', function() {
var suite = {
title: expectedTitle
};
var runner = createMockRunner(
'skipped test',
EVENT_TEST_SKIPPED,
null,
null,
suite
);
var options = {};
var stdout = runReporter({epilogue: noop}, runner, options);
sandbox.restore();

var expectedArray = [' - ' + expectedTitle + '\n'];
expect(stdout, 'to equal', expectedArray);
});
});

describe("on 'pass' event", function() {
describe('when test speed is slow', function() {
it('should return expected tick, title, and duration', function() {
Expand Down

0 comments on commit e02df82

Please sign in to comment.