Skip to content

Commit

Permalink
reporter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Apr 28, 2020
1 parent 1e9485e commit 7caf4f7
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 4 deletions.
58 changes: 58 additions & 0 deletions test/reporters/json-stream.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var EVENT_RUN_BEGIN = events.EVENT_RUN_BEGIN;
var EVENT_RUN_END = events.EVENT_RUN_END;
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('JSON Stream reporter', function() {
var runReporter = makeRunReporter(JSONStream);
Expand Down Expand Up @@ -79,6 +81,62 @@ describe('JSON Stream reporter', function() {
});
});

describe("on 'pending' event", function() {
it('should write stringified test data', function() {
var runner = createMockRunner(
'pending test',
EVENT_TEST_PENDING,
null,
null,
expectedTest
);
var options = {};
var stdout = runReporter({}, runner, options);

expect(
stdout[0],
'to equal',
'["pend",{"title":' +
dQuote(expectedTitle) +
',"fullTitle":' +
dQuote(expectedFullTitle) +
',"duration":' +
expectedDuration +
',"currentRetry":' +
currentRetry +
'}]\n'
);
});
});

describe("on 'skipped' event", function() {
it('should write stringified test data', function() {
var runner = createMockRunner(
'skipped test',
EVENT_TEST_SKIPPED,
null,
null,
expectedTest
);
var options = {};
var stdout = runReporter({}, runner, options);

expect(
stdout[0],
'to equal',
'["skip",{"title":' +
dQuote(expectedTitle) +
',"fullTitle":' +
dQuote(expectedFullTitle) +
',"duration":' +
expectedDuration +
',"currentRetry":' +
currentRetry +
'}]\n'
);
});
});

describe("on 'fail' event", function() {
describe('when error stack exists', function() {
it('should write stringified test data with error data', function() {
Expand Down
21 changes: 21 additions & 0 deletions test/reporters/list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var EVENT_TEST_BEGIN = events.EVENT_TEST_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('List reporter', function() {
var sandbox;
Expand Down Expand Up @@ -84,6 +85,26 @@ describe('List reporter', function() {
});
});

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

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

describe("on 'pass' event", function() {
var crStub;

Expand Down
43 changes: 39 additions & 4 deletions test/reporters/xunit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ var EVENT_TEST_END = events.EVENT_TEST_END;
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;

var STATE_FAILED = states.STATE_FAILED;
var STATE_PASSED = states.STATE_PASSED;
var STATE_PENDING = states.STATE_PENDING;
var STATE_SKIPPED = states.STATE_SKIPPED;

describe('XUnit reporter', function() {
var sandbox;
Expand Down Expand Up @@ -149,23 +151,29 @@ describe('XUnit reporter', function() {
});

describe('event handlers', function() {
describe("on 'pending', 'pass' and 'fail' events", function() {
describe("on 'pending', 'skip', 'pass' and 'fail' events", function() {
it("should add test to tests called on 'end' event", function() {
var pendingTest = {
name: 'pending',
slow: noop
};
var failTest = {
name: 'fail',
var skipTest = {
name: 'skip',
slow: noop
};
var passTest = {
name: 'pass',
slow: noop
};
var failTest = {
name: 'fail',
slow: noop
};
runner.on = runner.once = function(event, callback) {
if (event === EVENT_TEST_PENDING) {
callback(pendingTest);
} else if (event === EVENT_TEST_SKIPPED) {
callback(skipTest);
} else if (event === EVENT_TEST_PASS) {
callback(passTest);
} else if (event === EVENT_TEST_FAIL) {
Expand All @@ -184,7 +192,7 @@ describe('XUnit reporter', function() {
};
XUnit.call(fakeThis, runner);

var expectedCalledTests = [pendingTest, passTest, failTest];
var expectedCalledTests = [pendingTest, skipTest, passTest, failTest];
expect(calledTests, 'to equal', expectedCalledTests);
});
});
Expand Down Expand Up @@ -421,6 +429,33 @@ describe('XUnit reporter', function() {
});
});

describe('on test skipped', function() {
it('should write expected tag', function() {
var xunit = new XUnit(runner);
var expectedTest = {
title: expectedTitle,
parent: {
fullTitle: function() {
return expectedClassName;
}
},
state: STATE_SKIPPED,
duration: 1000
};

xunit.test.call(fakeThis, expectedTest);
sandbox.restore();

var expectedTag =
'<testcase classname="' +
expectedClassName +
'" name="' +
expectedTitle +
'" time="1"><skipped/></testcase>';
expect(expectedWrite, 'to be', expectedTag);
});
});

describe('on test in any other state', function() {
it('should write expected tag', function() {
var xunit = new XUnit(runner);
Expand Down

0 comments on commit 7caf4f7

Please sign in to comment.