Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

chore(tslint) Add tslint check and do some cleanup. #12

Merged
merged 3 commits into from
Dec 13, 2016
Merged
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
8 changes: 6 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
dependencies:
override:
- npm update
cache_directories:
- testapp/node_modules
post:
- npm run webdriver:
background: true
- npm run install_testapp
- cd testapp && npm update
- npm run testapp:
background: true
test:
override:
- gulp lint
- ./node_modules/.bin/gulp lint
- npm test
- npm run test:e2e
11 changes: 5 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var gulp = require('gulp');
var runSequence = require('run-sequence');
var spawn = require('child_process').spawn;
var tslint = require('gulp-tslint');

var runSpawn = function(done, task, opt_arg) {
var child = spawn(task, opt_arg, {stdio: 'inherit'});
Expand All @@ -20,10 +21,8 @@ gulp.task('webdriver:update', function(done) {
runSpawn(done, 'webdriver-manager', ['update']);
});

gulp.task('jshint', function(done) {
runSpawn(done, 'node', ['node_modules/jshint/bin/jshint', 'lib', 'spec', 'scripts',
'--exclude=lib/selenium-webdriver/**/*.js,spec/dependencyTest/*.js,' +
'spec/install/**/*.js']);
gulp.task('tslint', function() {
return gulp.src(['lib/**/*.ts', 'spec/**/*.ts']).pipe(tslint()).pipe(tslint.report());
});

gulp.task('format:enforce', () => {
Expand All @@ -45,7 +44,7 @@ gulp.task('tsc', function(done) {
});

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

gulp.task('prepublish', function(done) {
Expand All @@ -54,7 +53,7 @@ gulp.task('prepublish', function(done) {

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

gulp.task('default', ['prepublish']);
Expand Down
31 changes: 15 additions & 16 deletions lib/blockingproxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Promise} from 'es6-promise';
import * as http from 'http';
import * as url from 'url';

var angularWaits = require('./angular/wait.js');
let angularWaits = require('./angular/wait.js');

/**
* The stability proxy is an http server responsible for intercepting
Expand Down Expand Up @@ -45,7 +45,7 @@ export class BlockingProxy {
* @param {string} originalUrl The URL from the incoming command.
*/
static executeAsyncUrl(originalUrl: string) {
var parts = originalUrl.split('/');
let parts = originalUrl.split('/');
return [parts[0], parts[1], parts[2], 'execute_async'].join('/');
}

Expand All @@ -70,12 +70,12 @@ export class BlockingProxy {
// See https://code.google.com/p/selenium/wiki/JsonWireProtocol for
// descriptions of the paths.
// We shouldn't stabilize if we haven't loaded the page yet.
var parts = commandPath.split('/');
let parts = commandPath.split('/');
if (parts.length < 4) {
return false;
}

var commandsToWaitFor = [
let commandsToWaitFor = [
'executeScript', 'screenshot', 'source', 'title', 'element', 'elements', 'execute', 'keys',
'moveto', 'click', 'buttondown', 'buttonup', 'doubleclick', 'touch', 'get'
];
Expand All @@ -98,21 +98,20 @@ export class BlockingProxy {
* @return {http.ClientRequest}
*/
createSeleniumRequest(method, messageUrl, callback) {
var parsedUrl = url.parse(this.seleniumAddress);
var options = {};
let parsedUrl = url.parse(this.seleniumAddress);
let options = {};
options['method'] = method;
options['path'] = parsedUrl.path + messageUrl;
options['hostname'] = parsedUrl.hostname;
options['port'] = parsedUrl.port;

var request = http.request(options, callback);
let request = http.request(options, callback);

return request;
};

handleProxyCommand(message, data, response) {
console.log('Got message: ' + message.url);
var command = message.url.split('/')[2];
let command = message.url.split('/')[2];
switch (command) {
case 'enabled':
if (message.method === 'GET') {
Expand Down Expand Up @@ -152,10 +151,10 @@ export class BlockingProxy {
}

sendRequestToStabilize(originalRequest) {
var self = this;
let self = this;
console.log('Waiting for stability...', originalRequest.url);
var deferred = new Promise((resolve, reject) => {
var stabilityRequest = self.createSeleniumRequest(
let deferred = new Promise((resolve, reject) => {
let stabilityRequest = self.createSeleniumRequest(
'POST', BlockingProxy.executeAsyncUrl(originalRequest.url), function(stabilityResponse) {
// TODO - If the response is that angular is not available on the
// page, should we just go ahead and continue?
Expand All @@ -170,7 +169,7 @@ export class BlockingProxy {
});

stabilityResponse.on('end', () => {
var value = JSON.parse(stabilityData).value;
let value = JSON.parse(stabilityData).value;
if (value) {
// waitForAngular only returns a value if there was an error
// in the browser.
Expand All @@ -193,8 +192,8 @@ export class BlockingProxy {
}

requestListener(originalRequest: http.IncomingMessage, response: http.ServerResponse) {
var self = this;
var stabilized = Promise.resolve(null);
let self = this;
let stabilized = Promise.resolve(null);

if (BlockingProxy.isProxyCommand(originalRequest.url)) {
let commandData = '';
Expand All @@ -216,7 +215,7 @@ export class BlockingProxy {

stabilized.then(
() => {
var seleniumRequest = self.createSeleniumRequest(
let seleniumRequest = self.createSeleniumRequest(
originalRequest.method, originalRequest.url, function(seleniumResponse) {
response.writeHead(seleniumResponse.statusCode, seleniumResponse.headers);
seleniumResponse.pipe(response);
Expand Down
2 changes: 1 addition & 1 deletion lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class BPClient {

let request = http.request(options, (response) => {
response.on('data', () => {});
response.on('error', (err) => {reject(err)});
response.on('error', (err) => reject(err));
response.on('end', () => {
resolve();
});
Expand Down
10 changes: 5 additions & 5 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import * as minimist from 'minimist';

export interface Config {
help?: boolean
seleniumAddress?: string
port?: number
rootElement?: string
help?: boolean;
seleniumAddress?: string;
port?: number;
rootElement?: string;
}

const opts: minimist.Opts = {
Expand Down Expand Up @@ -37,5 +37,5 @@ Options:
--port, -p The port to listen on
--selenumAddress, -s The address of the selenium remote server to proxy
--rootElement Element housing ng-app, if not html or body
`)
`);
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@
"clang-format": "^1.0.34",
"gulp": "^3.9.1",
"gulp-clang-format": "^1.0.23",
"gulp-tslint": "^7.0.1",
"jasmine": "2.3.2",
"jasmine-ts": "0.0.3",
"jshint": "2.9.1",
"run-sequence": "^1.2.2",
"ts-node": "^1.3.0",
"tslint": "^4.0.2",
"tslint-eslint-rules": "^3.1.0",
"typescript": "^2.0.3",
"vrsource-tslint-rules": "^0.14.1",
"webdriver-manager": "^10.2.2"
},
"repository": {
Expand All @@ -46,7 +50,6 @@
"test": "jasmine-ts spec/unit/**/*.ts",
"test:auto": "find lib spec | entr jasmine-ts spec/unit/**/*.ts",
"testapp": "cd testapp && npm start",
"install_testapp": "cd testapp && npm install",
"test:e2e": "jasmine-ts spec/e2e/**/*.ts"
},
"jshintConfig": {
Expand Down
2 changes: 1 addition & 1 deletion spec/e2e/ng1_async_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('ng1 synchronizing with slow pages', function() {

driver.getPageSource()
.then((source) => {
expect(source).toMatch('polling mechanism')
expect(source).toMatch('polling mechanism');
done();
})
.thenCatch(done.fail);
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/config_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {processArgs} from '../../lib/config';

describe('cli launcher', () => {
it('should read selenium address from commandline', () => {
let argv = processArgs(['--seleniumAddress', 'http://test.com'])
expect(argv.seleniumAddress).toBe('http://test.com')
let argv = processArgs(['--seleniumAddress', 'http://test.com']);
expect(argv.seleniumAddress).toBe('http://test.com');
});
});
11 changes: 5 additions & 6 deletions spec/unit/proxy_spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {BlockingProxy} from '../../lib/blockingproxy'
import {BlockingProxy} from '../../lib/blockingproxy';

describe('BlockingProxy', () => {
it('should be able to be created',
() => {
let proxy = new BlockingProxy(8111);
expect(proxy.stabilityEnabled).toBe(true);
});
it('should be able to be created', () => {
let proxy = new BlockingProxy(8111);
expect(proxy.stabilityEnabled).toBe(true);
});
});
15 changes: 15 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"rulesDirectory": [
"node_modules/vrsource-tslint-rules/rules",
"node_modules/tslint-eslint-rules/dist/rules"
],
"rules": {
"no-duplicate-imports": true,
"no-duplicate-variable": true,
"no-jasmine-focus": true,
"no-var-keyword": true,
"semicolon": [true],
"variable-name": [true, "ban-keywords"],
"no-inner-declarations": [true, "function"]
}
}