Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add failOnSevere #12

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ exports.config = {

### Configuration
* `logLevels`: Inclusive `Array` filter for which log levels to show. Can be any of `'debug'`, `'info'`, `'warning'` and `'severe'`. Defaults to `['severe', 'warning']`.

* `failOnSevere`: `Boolean` for failing the tests when `'severe'` level errors detected. Disabled by default.
13 changes: 12 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ module.exports = {
});
},

postTest: function() {
postTest: function () {
// this == ProtractorPlugin
// from: https://github.com/angular/protractor/blob/c6703a5ea8ce7a837193ecf478c2096d8c6e99e9/lib/plugins.ts#L25
let config = this.config;
// addFailure == ProtractorPlugin.addFailure
// https://github.com/angular/protractor/blob/c6703a5ea8ce7a837193ecf478c2096d8c6e99e9/lib/plugins.ts#L243
let addFailure = this.addFailure;

if (!this.enabled) {
return;
Expand All @@ -66,6 +71,12 @@ module.exports = {
return;
}

result.forEach(resultLine => {
if (config.failOnSevere && resultLine.level.name.toLowerCase() === LEVELS.severe.name) {
addFailure(`Test failed due to ${LEVELS.severe.name} level message`);
}
});

printHeader.call(config);

_(result)
Expand Down
35 changes: 34 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let expect = chai.expect;
chai.use(sinonChai);

describe('protractor-console', () => {
let reporter, printerSpy, headerSpy;
let reporter, printerSpy, headerSpy, addFailureSpy;

beforeEach(() => {
let browser = global.browser = {};
Expand All @@ -32,11 +32,44 @@ describe('protractor-console', () => {

headerSpy = sinon.spy();
reporter.config.headerPrinter = headerSpy;

addFailureSpy = sinon.spy();
reporter.addFailure = addFailureSpy;
});

afterEach(() => {
printerSpy.reset();
headerSpy.reset();
addFailureSpy.reset();
});

it('should fail tests when severe error and failOnSevere==true', () => {
reporter.config.failOnSevere = true;
expect(addFailureSpy).to.have.callCount(0);

return reporter.postTest()
.then(() => {
expect(addFailureSpy).to.have.callCount(1);
});
});

it('should not fail tests when severe error and failOnSevere==false', () => {
reporter.config.failOnSevere = false;
expect(addFailureSpy).to.have.callCount(0);

return reporter.postTest()
.then(() => {
expect(addFailureSpy).to.have.callCount(0);
});
});

it('should not fail tests when severe error and failOnSevere undefined', () => {
expect(addFailureSpy).to.have.callCount(0);

return reporter.postTest()
.then(() => {
expect(addFailureSpy).to.have.callCount(0);
});
});

it('should filter by log level', () => {
Expand Down