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

Commit

Permalink
chore(tslint): add tslint to gulpfile (#3833)
Browse files Browse the repository at this point in the history
- add gulp task tslint and lint
- update `**/*.ts` with tslint fixes
- update circle.yml to run `gulp lint`
- update `gulp pretest` to run both jshint and tslint
  • Loading branch information
cnishina authored Dec 20, 2016
1 parent 075a512 commit 989759a
Show file tree
Hide file tree
Showing 19 changed files with 91 additions and 68 deletions.
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies:
cache_directories:
- testapp/node_modules
post:
- ./node_modules/.bin/gulp format:enforce
- ./node_modules/.bin/gulp lint
- ./node_modules/.bin/webdriver-manager update
- ./node_modules/.bin/webdriver-manager start:
background: true
Expand Down
20 changes: 15 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var gulpFormat = require('gulp-clang-format');
var runSequence = require('run-sequence');
var spawn = require('child_process').spawn;
var spawnSync = require('child_process').spawnSync;
var tslint = require('gulp-tslint');
var fs = require('fs');
var path = require('path');
var glob = require('glob');
Expand Down Expand Up @@ -34,6 +35,15 @@ var runSpawn = function(done, task, opt_arg, opt_io) {
});
};

gulp.task('tslint', function() {
return gulp.src(['lib/**/*.ts', 'spec/**/*.ts', '!spec/install/**/*.ts'])
.pipe(tslint()).pipe(tslint.report());
});

gulp.task('lint', function(done) {
runSequence('tslint', 'jshint', 'format:enforce', done);
});

// prevent contributors from using the wrong version of node
gulp.task('checkVersion', function(done) {
// read minimum node on package.json
Expand All @@ -44,8 +54,8 @@ gulp.task('checkVersion', function(done) {
if (semver.satisfies(process.version, nodeVersion)) {
done();
} else {
throw new Error('minimum node version for Protractor ' + protractorVersion +
' is node ' + nodeVersion);
throw new Error('minimum node version for Protractor ' +
protractorVersion + ' is node ' + nodeVersion);
}
});

Expand All @@ -60,7 +70,8 @@ gulp.task('webdriver:update', function(done) {
});

gulp.task('jshint', function(done) {
runSpawn(done, 'node', ['node_modules/jshint/bin/jshint', '-c', '.jshintrc', '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 Expand Up @@ -90,8 +101,7 @@ gulp.task('prepublish', function(done) {

gulp.task('pretest', function(done) {
runSequence('checkVersion',
['webdriver:update', 'jshint', 'format'], 'tsc',
'built:copy', done);
['webdriver:update', 'jshint', 'tslint', 'format'], 'tsc', 'built:copy', done);
});

gulp.task('default',['prepublish']);
9 changes: 4 additions & 5 deletions lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class Webdriver {
*/
function ptorMixin(to: any, from: any, fnName: string, setupFn?: Function) {
to[fnName] = function() {
for (var i = 0; i < arguments.length; i++) {
for (let i = 0; i < arguments.length; i++) {
if (arguments[i] instanceof ElementFinder) {
arguments[i] = arguments[i].getWebElement();
}
Expand Down Expand Up @@ -103,10 +103,9 @@ function buildElementHelper(browser: ProtractorBrowser): ElementHelper {
return new ElementArrayFinder(browser).all(locator).toElementFinder_();
}) as ElementHelper;

element.all =
(locator: Locator) => {
return new ElementArrayFinder(browser).all(locator);
}
element.all = (locator: Locator) => {
return new ElementArrayFinder(browser).all(locator);
};

return element;
};
Expand Down
8 changes: 4 additions & 4 deletions lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import * as path from 'path';
* Values from command line options override values from the config.
*/

var args: Array<string> = [];
let args: Array<string> = [];

process.argv.slice(2).forEach(function(arg: string) {
var flag: string = arg.split('=')[0];
let flag: string = arg.split('=')[0];

switch (flag) {
case 'debug':
Expand Down Expand Up @@ -72,7 +72,7 @@ optimist
}
});

var argv: any = optimist.parse(args);
let argv: any = optimist.parse(args);

if (argv.help) {
optimist.showHelp();
Expand Down Expand Up @@ -105,7 +105,7 @@ if (argv.exclude) {
}

// Use default configuration, if it exists.
var configFile: string = argv._[0];
let configFile: string = argv._[0];
if (!configFile) {
if (fs.existsSync('./protractor.conf.js')) {
configFile = './protractor.conf.js';
Expand Down
2 changes: 1 addition & 1 deletion lib/debugger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as net from 'net';
import {promise as wdpromise, WebElement} from 'selenium-webdriver';
import * as util from 'util'
import * as util from 'util';

import {ProtractorBrowser} from './browser';
import {Locator} from './locators';
Expand Down
4 changes: 2 additions & 2 deletions lib/driverProviders/attachSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export class AttachSession extends DriverProvider {
* @return {WebDriver} webdriver instance
*/
getNewDriver(): WebDriver {
var executor = executors.createExecutor(this.config_.seleniumAddress);
var newDriver = WebDriver.attachToSession(executor, this.config_.seleniumSessionId);
let executor = executors.createExecutor(this.config_.seleniumAddress);
let newDriver = WebDriver.attachToSession(executor, this.config_.seleniumSessionId);
this.drivers_.push(newDriver);
return newDriver;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/driverProviders/browserStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class BrowserStack extends DriverProvider {

let req = https.request(options, (res) => {
res.on('data', (data: Buffer) => {
var info = JSON.parse(data.toString());
let info = JSON.parse(data.toString());
if (info && info.automation_session && info.automation_session.browser_url) {
logger.info(
'BrowserStack results available at ' + info.automation_session.browser_url);
Expand Down Expand Up @@ -95,7 +95,7 @@ export class BrowserStack extends DriverProvider {
* ready to test.
*/
setupEnv(): q.Promise<any> {
var deferred = q.defer();
let deferred = q.defer();
this.config_.capabilities['browserstack.user'] = this.config_.browserstackUser;
this.config_.capabilities['browserstack.key'] = this.config_.browserstackKey;
this.config_.seleniumAddress = 'http://hub.browserstack.com/wd/hub';
Expand Down
4 changes: 2 additions & 2 deletions lib/driverProviders/sauce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export class Sauce extends DriverProvider {
* @return {q.promise} A promise that will resolve when the update is complete.
*/
updateJob(update: any): q.Promise<any> {
var deferredArray = this.drivers_.map((driver: WebDriver) => {
var deferred = q.defer();
let deferredArray = this.drivers_.map((driver: WebDriver) => {
let deferred = q.defer();
driver.getSession().then((session: Session) => {
logger.info('SauceLabs results available at http://saucelabs.com/jobs/' + session.getId());
this.sauceServer_.updateJob(session.getId(), update, (err: Error) => {
Expand Down
3 changes: 1 addition & 2 deletions lib/element.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {By, error, ILocation, ISize, promise as wdpromise, WebDriver, WebElement, WebElementPromise} from 'selenium-webdriver';

import {ElementHelper} from './browser';
import {ProtractorBrowser} from './browser';
import {ElementHelper, ProtractorBrowser} from './browser';
import {IError} from './exitCodes';
import {Locator} from './locators';
import {Logger} from './logger';
Expand Down
8 changes: 3 additions & 5 deletions lib/expectedConditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {ElementFinder} from './element';

const webdriver = require('selenium-webdriver');

declare var global: any;

/**
* Represents a library of canned expected conditions that are useful for
* protractor, especially when dealing with non-angular apps.
Expand Down Expand Up @@ -88,7 +86,7 @@ export class ProtractorExpectedConditions {
if (fns.length === 0) {
return defaultRet;
}
var fn = fns[0];
let fn = fns[0];
return fn().then((bool: boolean): boolean => {
if (bool === defaultRet) {
return self.logicalChain_(defaultRet, fns.slice(1))();
Expand Down Expand Up @@ -208,7 +206,7 @@ export class ProtractorExpectedConditions {
* representing whether the text is present in the element.
*/
textToBePresentInElement(elementFinder: ElementFinder, text: string): Function {
var hasText = () => {
let hasText = () => {
return elementFinder.getText().then((actualText: string): boolean => {
// MSEdge does not properly remove newlines, which causes false
// negatives
Expand All @@ -235,7 +233,7 @@ export class ProtractorExpectedConditions {
* representing whether the text is present in the element's value.
*/
textToBePresentInElementValue(elementFinder: ElementFinder, text: string): Function {
var hasText = () => {
let hasText = () => {
return elementFinder.getAttribute('value').then((actualText: string): boolean => {
return actualText.indexOf(text) > -1;
});
Expand Down
4 changes: 2 additions & 2 deletions lib/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ let initFn = function(configFile: string, additionalConfig: Config) {

let deferred = q.defer<any>(); // Resolved when all tasks are completed
let createNextTaskRunner = () => {
var task = scheduler.nextTask();
let task = scheduler.nextTask();
if (task) {
let taskRunner = new TaskRunner(configFile, additionalConfig, task, forkProcess);
taskRunner.run()
Expand Down Expand Up @@ -267,7 +267,7 @@ let initFn = function(configFile: string, additionalConfig: Config) {
// the beginning. As a worker finishes a task, it will pick up the next
// task
// from the scheduler's queue until all tasks are gone.
for (var i = 0; i < scheduler.maxConcurrentTasks(); ++i) {
for (let i = 0; i < scheduler.maxConcurrentTasks(); ++i) {
createNextTaskRunner();
}
logger.info('Running ' + scheduler.countActiveTasks() + ' instances of WebDriver');
Expand Down
4 changes: 2 additions & 2 deletions lib/locators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class ProtractorBy extends WebdriverBy {
*/
addLocator(name: string, script: Function|string) {
this[name] = (...args: any[]): Locator => {
var locatorArguments = args;
let locatorArguments = args;
return {
findElementsOverride: (driver: WebDriver, using: WebElement, rootSelector: string):
wdpromise.Promise<WebElement[]> => {
Expand Down Expand Up @@ -247,7 +247,7 @@ export class ProtractorBy extends WebdriverBy {

// Generate either by.repeater or by.exactRepeater
private byRepeaterInner(exact: boolean, repeatDescriptor: string): Locator {
var name = 'by.' + (exact ? 'exactR' : 'r') + 'epeater';
let name = 'by.' + (exact ? 'exactR' : 'r') + 'epeater';
return {
findElementsOverride: (driver: WebDriver, using: WebElement, rootSelector: string):
wdpromise.Promise<WebElement[]> => {
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ export class Plugins {

export interface SpecResult {
description: string;
assertions: AssertionResult[]
assertions: AssertionResult[];
}

export interface AssertionResult {
Expand Down
4 changes: 2 additions & 2 deletions lib/ptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class Ptor {
firefox: require('selenium-webdriver/firefox'),
http: require('selenium-webdriver/http'),
remote: require('selenium-webdriver/remote')
}
};
}

export var protractor = new Ptor();
export let protractor = new Ptor();
40 changes: 19 additions & 21 deletions lib/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ import * as util from 'util';

import {ProtractorBrowser} from './browser';
import {Config} from './config';
import {AttachSession, BrowserStack, Direct, Hosted, Local, Mock, Sauce} from './driverProviders';
import {DriverProvider} from './driverProviders';
import {AttachSession, BrowserStack, Direct, DriverProvider, Hosted, Local, Mock, Sauce} from './driverProviders';
import {Logger} from './logger';
import {Plugins} from './plugins';
import {protractor} from './ptor';
import * as helper from './util';

declare var global: any;
declare var process: any;
declare let global: any;
declare let process: any;

var webdriver = require('selenium-webdriver');
const webdriver = require('selenium-webdriver');
let logger = new Logger('runner');
/*
* Runner is responsible for starting the execution of a test run and triggering
Expand Down Expand Up @@ -127,17 +126,16 @@ export class Runner extends EventEmitter {
* @private
* @param {int} Standard unix exit code
*/
exit_ = function(exitCode: number):
any {
return helper.runFilenameOrFn_(this.config_.configDir, this.config_.onCleanUp, [exitCode])
.then((returned): number | any => {
if (typeof returned === 'number') {
return returned;
} else {
return exitCode;
}
});
}
exit_ = function(exitCode: number): any {
return helper.runFilenameOrFn_(this.config_.configDir, this.config_.onCleanUp, [exitCode])
.then((returned): number | any => {
if (typeof returned === 'number') {
return returned;
} else {
return exitCode;
}
});
};

/**
* Getter for the Runner config object
Expand Down Expand Up @@ -205,10 +203,10 @@ export class Runner extends EventEmitter {
* @public
*/
createBrowser(plugins: any): any {
var config = this.config_;
var driver = this.driverprovider_.getNewDriver();
let config = this.config_;
let driver = this.driverprovider_.getNewDriver();

var browser_ = ProtractorBrowser.wrapDriver(
let browser_ = ProtractorBrowser.wrapDriver(
driver, config.baseUrl, config.rootElement, config.untrackOutstandingTimeouts);

browser_.params = config.params;
Expand Down Expand Up @@ -341,7 +339,7 @@ export class Runner extends EventEmitter {
}

if (this.config_.restartBrowserBetweenTests) {
var restartDriver = () => {
let restartDriver = () => {
browser_.restart();
};
this.on('testPass', restartDriver);
Expand Down Expand Up @@ -393,7 +391,7 @@ export class Runner extends EventEmitter {
// 9) Exit process
})
.then(() => {
var exitCode = testPassed ? 0 : 1;
let exitCode = testPassed ? 0 : 1;
return this.exit_(exitCode);
})
.fin(() => {
Expand Down
6 changes: 3 additions & 3 deletions lib/taskLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export class TaskLogger {
* @param {string} data
*/
public log(data: string): void {
var tag = '[';
var capabilities = this.task.capabilities;
let tag = '[';
let capabilities = this.task.capabilities;
tag += (capabilities.logName) ? capabilities.logName :
(capabilities.browserName) ? capabilities.browserName : '';
tag += (capabilities.version) ? (' ' + capabilities.version) : '';
Expand All @@ -72,7 +72,7 @@ export class TaskLogger {
tag += '] ';

data = data.toString();
for (var i = 0; i < data.length; i++) {
for (let i = 0; i < data.length; i++) {
if (this.insertTag) {
this.insertTag = false;
// This ensures that the '\x1B[0m' appears before the tag, so that
Expand Down
Loading

0 comments on commit 989759a

Please sign in to comment.