Skip to content

Commit

Permalink
Merge pull request #7 from Updater/chore/modernize
Browse files Browse the repository at this point in the history
Chore/modernize
  • Loading branch information
pmowrer authored Jun 14, 2017
2 parents 6c36b40 + 20fc8fe commit 55e213a
Show file tree
Hide file tree
Showing 10 changed files with 266 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/dist
/node_modules
*.sublime*
.idea
11 changes: 0 additions & 11 deletions .jshintrc

This file was deleted.

1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: node_js
node_js:
- "0.10"
- "0.12"
- "iojs"
- "6"
- "7"
notifications:
email: false
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 3.0.0
##### Breaking
Remove Babel transpilation. Node 6.4.0 or greater is now required.

##### Fixes
Handle `browser.manage.logs()` failing. GeckoDriver currently doesn't support it and blows up with a stack trace.

## 2.0.1
##### Fixes
* Don't print header when there are 0 results after filtering.
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "protractor-console",
"version": "2.0.1",
"version": "3.0.0",
"description": "Print console logging statements that occur during Protractor test runs.",
"main": "dist/protractor-console.js",
"main": "src/index.js",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -15,9 +15,10 @@
"console"
],
"scripts": {
"compile": "mkdirp dist && babel -o dist/protractor-console.js src/index.js",
"test": "mocha --compilers js:babel/register",
"prepublish": "npm run compile"
"test": "mocha"
},
"engines": {
"node": ">=6.4.0"
},
"peerDependencies": {
"protractor": ">= 2.2.0"
Expand All @@ -27,10 +28,8 @@
"lodash": "^3.10.0"
},
"devDependencies": {
"babel": "^5.8.3",
"chai": "^3.2.0",
"chai-as-promised": "^5.1.0",
"mkdirp": "^0.5.1",
"mocha": "^2.2.4",
"sinon": "^1.15.4",
"sinon-chai": "^2.8.0"
Expand Down
26 changes: 23 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash';
import Chalk from 'chalk';
const _ = require('lodash');
const Chalk = require('chalk');

// Need to explicitly enable colors, probably for the same reason as:
// https://github.com/bcaudan/jasmine-spec-reporter/issues/36
Expand Down Expand Up @@ -34,10 +34,30 @@ const DEFAULT_LOG_LEVELS = [
// http://stackoverflow.com/questions/1879860/most-reliable-split-character
const SPLIT_CHAR = '\u0007';

export default {
module.exports = {
enabled: true,

setup: function() {
// Disable the plugin if `browser.manage().logs()` isn't supported by the browser driver.
// E.g. GeckoDriver currently doesn't support this call and blows up with a stacktrace.
// https://github.com/SeleniumHQ/selenium/issues/2972
browser.manage().logs().get('browser').then(null, () => {
this.enabled = false;

logPrinter({
message: 'Protractor Console: This browser does not appear to support retrieving logs.',
level: 'warning',
});
});
},

postTest: function() {
let config = this.config;

if (!this.enabled) {
return;
}

return browser.manage().logs().get('browser')
.then(result => {
result = result.filter(byLogLevel, config);
Expand Down
5 changes: 0 additions & 5 deletions test/.jshintrc

This file was deleted.

36 changes: 15 additions & 21 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import sinon from 'sinon';
import chai from 'chai';
import sinonChai from 'sinon-chai';
const sinon = require('sinon');
const chai = require('chai');
const sinonChai = require('sinon-chai');
const _ = require('lodash');
const Reporter = require('../src/index');

let expect = chai.expect;
chai.use(sinonChai);

import _ from 'lodash';
import Reporter from '../src/index';

describe('protractor-console', () => {

let reporter, context, printerSpy, headerSpy;
let reporter, printerSpy, headerSpy;

beforeEach(() => {
let browser = global.browser = {};
Expand All @@ -28,14 +26,12 @@ describe('protractor-console', () => {

// Workaround for lack of "new"ing the plugin, resetting before each test run.
reporter = _.cloneDeep(Reporter);

context = {};
context.config = {};
reporter.config = {};
printerSpy = sinon.spy();
context.config.logPrinter = printerSpy;
reporter.config.logPrinter = printerSpy;

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

afterEach(() => {
Expand All @@ -44,15 +40,15 @@ describe('protractor-console', () => {
});

it('should filter by log level', () => {
context.config.logLevels = ['debug'];
reporter.config.logLevels = ['debug'];

return reporter.postTest.call(context)
return reporter.postTest()
.then(() => {
expect(printerSpy).to.have.callCount(0);
expect(headerSpy).to.have.callCount(0);

context.config.logLevels = ['severe'];
return reporter.postTest.call(context);
reporter.config.logLevels = ['severe'];
return reporter.postTest.call(reporter);
})
.then(() => {
expect(printerSpy).to.have.callCount(1);
Expand All @@ -61,9 +57,9 @@ describe('protractor-console', () => {
});

it('should group identical logs into a single line', () => {
context.config.logLevels = ['warning'];
reporter.config.logLevels = ['warning'];

return reporter.postTest.call(context).then(() => {
return reporter.postTest().then(() => {
let match1 = getSampleOutput()[1];
let match2 = getSampleOutput()[6];

Expand All @@ -82,8 +78,6 @@ describe('protractor-console', () => {
});
});

/*jslint maxlen: 250 */

function getSampleOutput() {
return [{
level: {
Expand Down
Loading

0 comments on commit 55e213a

Please sign in to comment.