Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
chore(cleanup): jshint cleanup for spec (#3800)
Browse files Browse the repository at this point in the history
- update gulpfile to use .jshintrc
- address jshint errors in specs
- remove capture stack trace since ProtractorError extends Error
  • Loading branch information
cnishina authored Dec 7, 2016
1 parent 742f264 commit 4449112
Show file tree
Hide file tree
Showing 23 changed files with 40 additions and 58 deletions.
8 changes: 7 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,11 @@
"undef": true,
"quotmark": "single",
"evil": true,
"curly": true
"curly": true,
"esversion": 6,
"predef": ["$", "$$", "angular", "after", "afterAll", "afterEach",
"beforeAll", "beforeEach", "browser", "by", "By", "DartObject",
"describe", "document", "element", "expect", "ExpectedConditions",
"fdescribe", "fit", "it", "jasmine", "protractor", "spyOn",
"xdescribe", "xit"]
}
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ gulp.task('webdriver:update', function(done) {
});

gulp.task('jshint', function(done) {
runSpawn(done, 'node', ['node_modules/jshint/bin/jshint', 'lib', 'spec', 'scripts',
runSpawn(done, 'node', ['node_modules/jshint/bin/jshint', '-c', '.jshintrc', 'lib', 'spec', 'scripts',
'--exclude=lib/selenium-webdriver/**/*.js,spec/dependencyTest/*.js,' +
'spec/install/**/*.js']);
});
Expand Down
6 changes: 4 additions & 2 deletions lib/driverProviders/direct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export class Direct extends DriverProvider {
break;
default:
throw new BrowserError(
logger, 'browserName ' + this.config_.capabilities.browserName +
logger,
'browserName ' + this.config_.capabilities.browserName +
' is not supported with directConnect.');
}
return q.fcall(function() {});
Expand Down Expand Up @@ -83,7 +84,8 @@ export class Direct extends DriverProvider {
break;
default:
throw new BrowserError(
logger, 'browserName ' + this.config_.capabilities.browserName +
logger,
'browserName ' + this.config_.capabilities.browserName +
' is not supported with directConnect.');
}
this.drivers_.push(driver);
Expand Down
3 changes: 2 additions & 1 deletion lib/driverProviders/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export class Local extends DriverProvider {
}
if (!fs.existsSync(this.config_.seleniumServerJar)) {
throw new BrowserError(
logger, 'No selenium server jar found at the specified ' +
logger,
'No selenium server jar found at the specified ' +
'location (' + this.config_.seleniumServerJar +
'). Check that the version number is up to date.');
}
Expand Down
6 changes: 3 additions & 3 deletions lib/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1159,9 +1159,9 @@ export class ElementFinder extends WebdriverWebElement {
*/
equals(element: ElementFinder|WebElement): wdpromise.Promise<any> {
return WebElement.equals(
this.getWebElement(), (element as any).getWebElement ?
(element as ElementFinder).getWebElement() :
element as WebElement);
this.getWebElement(),
(element as any).getWebElement ? (element as ElementFinder).getWebElement() :
element as WebElement);
}
}

Expand Down
16 changes: 1 addition & 15 deletions lib/exitCodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,23 @@ export class ProtractorError extends IError {

message: string; // a one line message

/**
* Captures the stack trace to this.stack from the Error.captureStackTrace.
* this allows us to capture the error of this error object. Note:
* called with Error set to any to quiet typescript warnings.
*/
captureStackTrace() {
(Error as any).captureStackTrace(this, this.constructor);
}

constructor(logger: Logger, message: string, code: number, error?: Error) {
super(message);
this.message = message;
this.code = code;
this.captureStackTrace();

// replacing the stack trace with the thrown error stack trace.
if (error) {
let protractorError = error as ProtractorError;
this.stack = protractorError.stack;
}
this.logError(logger);
ProtractorError.log(logger, this.code, this.message, this.stack);

if (!ProtractorError.SUPRESS_EXIT_CODE) {
process.exit(this.code);
}
}

logError(logger: Logger) {
ProtractorError.log(logger, this.code, this.message, this.stack);
}

static log(logger: Logger, code: number, message: string, stack: string) {
let messages = message.split('\n');
if (messages.length > 1) {
Expand Down
18 changes: 9 additions & 9 deletions spec/basic/elements_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,21 @@ describe('ElementFinder', function() {

it('should allow handling errors', function() {
browser.get('index.html#/form');
var elmFinder = $('.nopenopenope').getText().then(function(success) {
$('.nopenopenope').getText().then(function(/* string */) {
// This should throw an error. Fail.
expect(true).toEqual(false);
}, function(err) {
}, function(/* error */) {
expect(true).toEqual(true);
});
});

it('should allow handling chained errors', function() {
browser.get('index.html#/form');
var elmFinder = $('.nopenopenope').$('furthernope').getText().then(
function(success) {
$('.nopenopenope').$('furthernope').getText().then(
function(/* string */) {
// This should throw an error. Fail.
expect(true).toEqual(false);
}, function(err) {
}, function(/* error */) {
expect(true).toEqual(true);
});
});
Expand Down Expand Up @@ -154,9 +154,9 @@ describe('ElementFinder', function() {
var successful = protractor.promise.defer();

var invalidElement = element(by.binding('INVALID'));
invalidElement.getText().then(function(value) {
invalidElement.getText().then(function(/* string */) {
successful.fulfill(true);
}, function(err) {
}, function(/* error */) {
successful.fulfill(false);
});
expect(successful).toEqual(false);
Expand Down Expand Up @@ -184,7 +184,6 @@ describe('ElementFinder', function() {
it('should allow null as success handler', function() {
browser.get('index.html#/form');

var usernameInput = element(by.model('username'));
var name = element(by.binding('username'));

expect(name.getText()).toEqual('Anon');
Expand Down Expand Up @@ -494,7 +493,8 @@ describe('ElementArrayFinder', function() {
it('should map each element from a literal and promise array', function() {
browser.get('index.html#/form');
var i = 1;
var labels = element.all(by.css('#animals ul li')).map(function(elm) {
var labels = element.all(by.css('#animals ul li'))
.map(function(/* element */) {
return i++;
});

Expand Down
4 changes: 0 additions & 4 deletions spec/basic/lib_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var util = require('util');

describe('no protractor at all', function() {
it('should still do normal tests', function() {
expect(true).toBe(true);
Expand Down Expand Up @@ -73,7 +71,6 @@ describe('protractor library', function() {
it('should allow adding custom locators', function() {
var findMenuItem = function() {
var itemName = arguments[0];
var using = arguments[1]; // unused
var menu = document.querySelectorAll('.menu li');
for (var i = 0; i < menu.length; ++i) {
if (menu[i].textContent == itemName) {
Expand All @@ -95,7 +92,6 @@ describe('protractor library', function() {
var findMenuItemWithName = function() {
var css = arguments[0];
var itemName = arguments[1];
var using = arguments[2]; // unused
var menu = document.querySelectorAll(css);
for (var i = 0; i < menu.length; ++i) {
if (menu[i].textContent == itemName) {
Expand Down
2 changes: 1 addition & 1 deletion spec/basic/locators_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('locators', function() {
expect(element(by.id('shower')).isDisplayed()).
toBe(true);

var colors = element(by.model('show')).click();
element(by.model('show')).click(); // colors

expect(element(by.id('shower')).isDisplayed()).
toBe(false);
Expand Down
4 changes: 1 addition & 3 deletions spec/basic/mockmodule_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var util = require('util');

describe('mock modules', function() {
// A module to override the 'version' service. This function will be
// executed in the context of the application under test, so it may
Expand All @@ -12,7 +10,7 @@ describe('mock modules', function() {
// A second module overriding the 'version' service.
// This module shows the use of a string for the load
// function.
var mockModuleB = "angular.module('moduleB', []).value('version', '3');";
var mockModuleB = `angular.module('moduleB', []).value('version', '3');`;

// A third module overriding the 'version' service. This function
// references the additional arguments provided through addMockModule().
Expand Down
2 changes: 0 additions & 2 deletions spec/basic/navigation_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var env = require('../environment.js');

describe('navigation', function() {
beforeEach(function() {
browser.get('index.html#/form');
Expand Down
2 changes: 0 additions & 2 deletions spec/basic/polling_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var util = require('util');

/**
* These tests show how to turn off Protractor's synchronization
* when using applications which poll with $http or $timeout.
Expand Down
2 changes: 0 additions & 2 deletions spec/basic/synchronize_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var util = require('util');

describe('synchronizing with slow pages', function() {
beforeEach(function() {
browser.get('index.html#/async');
Expand Down
2 changes: 1 addition & 1 deletion spec/errorTest/baseCase/error_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('finding an element that does not exist', function() {
it('should throw an error', function() {
browser.get('index.html');
var greeting = element(by.binding('INVALID'));
element(by.binding('INVALID')); // greeting
});
});
3 changes: 0 additions & 3 deletions spec/interaction/interaction_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var util = require('util');

describe('Browser', function() {

var newBrowser;
Expand Down Expand Up @@ -52,7 +50,6 @@ describe('Browser', function() {

var Person = function(name, browser) {
var $ = browser.$;
var $$ = browser.$$;
var element = browser.element;

this.openApp = function() {
Expand Down
2 changes: 1 addition & 1 deletion spec/onCleanUpNoReturnValueConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports.config = {

baseUrl: env.baseUrl + '/ng1/',

onCleanUp: function(exitCode) {
onCleanUp: function(/* exitCode */) {
// no return
}
};
3 changes: 1 addition & 2 deletions spec/plugins/skipStabilityConf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var env = require('../environment.js'),
q = require('q');
var env = require('../environment.js');

// Verifies that plugins can change skipAngularStability on the fly.
exports.config = {
Expand Down
2 changes: 1 addition & 1 deletion spec/plugins/waitForAngularConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports.config = {
// Plugin patterns are relative to this directory.
plugins: [{
inline: {
waitForPromise: function(oldURL) {
waitForPromise: function(/* oldURL */) {
return q.delay(5000).then(function() {
protractor.WAIT_FOR_PROMISE = true;
});
Expand Down
6 changes: 4 additions & 2 deletions spec/unit/configParser_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ describe('the config parser', function() {
getConfig();

expect(config.rootElement).toEqual('.mycontainer');
expect(config.onPrepare.indexOf(path.normalize('/spec/unit/data/foo/bar.js'))).not.toEqual(-1);
expect(config.onPrepare.indexOf(
path.normalize('/spec/unit/data/foo/bar.js'))).not.toEqual(-1);
expect(config.specs.length).toEqual(1);
expect(config.specs[0]).toEqual('fakespec[AB].js');
});
Expand All @@ -97,7 +98,8 @@ describe('the config parser', function() {
});

describe('getSpecs()', function() {
it('should return all the specs from "config.suites" if no other sources are provided', function() {
it(`should return all the specs from "config.suites" if no other sources
are provided`, function() {
var config = {
specs: [],
suites: {
Expand Down
1 change: 1 addition & 0 deletions spec/unit/driverProviders/direct_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var fs = require('fs'),
var BrowserError = require('../../../built/exitCodes').BrowserError,
Logger = require('../../../built/logger2').Logger,
WriteTo = require('../../../built/logger2').WriteTo;
var webdriver, file;

describe('direct connect', function() {
beforeEach(function() {
Expand Down
1 change: 1 addition & 0 deletions spec/unit/driverProviders/local_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var fs = require('fs'),
var BrowserError = require('../../../built/exitCodes').BrowserError,
Logger = require('../../../built/logger2').Logger,
WriteTo = require('../../../built/logger2').WriteTo;
var webdriver, file;

describe('local connect', function() {
beforeEach(function() {
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/logger_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('the logger', function() {
Logger.setWrite(WriteTo.FILE, logFile);
});

writeString = function() {
var writeString = function() {
logger.debug('hello debug');
logger.info('hello info');
logger.warn('hello warn');
Expand Down
1 change: 0 additions & 1 deletion spec/unit/runner_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var Runner = require('../../built/runner').Runner;
var q = require('q');
var Logger = require('../../built/logger').Logger,
WriteTo = require('../../built/logger').WriteTo;

Expand Down

0 comments on commit 4449112

Please sign in to comment.