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

Commit 0403058

Browse files
authored
chore(tests): Set up CI and run clang-format (#10)
1 parent 565c4e8 commit 0403058

18 files changed

+137
-134
lines changed

.clang-format

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Language: JavaScript
2+
BasedOnStyle: Google
3+
ColumnLimit: 100

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
# TypeScript output
55
built/
6+
testapp/typings/
67

78
# Logs
89
logs

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Blocking Proxy [![Build Status](https://circleci.com/gh/angular/blocking-proxy.svg?style=shield)](https://circleci.com/gh/angular/blocking-proxy)
2+
13
# TODO
24

35
- API commands

circle.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
dependencies:
2+
post:
3+
- npm run webdriver:
4+
background: true
5+
- npm run install_testapp
6+
- npm run testapp:
7+
background: true
8+
test:
9+
override:
10+
- gulp lint
11+
- npm test
12+
- npm run test:e2e

gulpfile.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
'use strict';
22

33
var gulp = require('gulp');
4-
var clangFormat = require('clang-format');
5-
var gulpFormat = require('gulp-clang-format');
64
var runSequence = require('run-sequence');
75
var spawn = require('child_process').spawn;
86

@@ -28,28 +26,30 @@ gulp.task('jshint', function(done) {
2826
'spec/install/**/*.js']);
2927
});
3028

31-
gulp.task('clang-check', function() {
32-
return gulp.src(['lib/**/*.ts', 'spec/**/*.ts'])
33-
.pipe(gulpFormat.checkFormat('file', clangFormat))
34-
.on('warning', function(e) {
35-
console.log(e);
36-
});
29+
gulp.task('format:enforce', () => {
30+
const format = require('gulp-clang-format');
31+
const clangFormat = require('clang-format');
32+
return gulp.src(['lib/**/*.ts', 'spec/**/*.ts']).pipe(
33+
format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
3734
});
3835

39-
gulp.task('clang', function() {
40-
return gulp.src(['lib/**/*.ts', 'spec/**/*.ts'])
41-
.pipe(gulpFormat.format('file', clangFormat))
42-
.on('warning', function(e) {
43-
console.log(e);
44-
});
36+
gulp.task('format', () => {
37+
const format = require('gulp-clang-format');
38+
const clangFormat = require('clang-format');
39+
return gulp.src(['lib/**/*.ts', 'spec/**/*.ts'], { base: '.' }).pipe(
40+
format.format('file', clangFormat)).pipe(gulp.dest('.'));
4541
});
4642

4743
gulp.task('tsc', function(done) {
4844
runSpawn(done, 'node', ['node_modules/typescript/bin/tsc']);
4945
});
5046

47+
gulp.task('lint', function(done) {
48+
runSequence('jshint', 'format:enforce', done);
49+
});
50+
5151
gulp.task('prepublish', function(done) {
52-
runSequence(['jshint', 'clang'],'tsc', 'built:copy', done);
52+
runSequence('lint' ,'tsc', 'built:copy', done);
5353
});
5454

5555
gulp.task('pretest', function(done) {

lib/blockingproxy.ts

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ export class BlockingProxy {
2727

2828
waitForAngularData() {
2929
return JSON.stringify({
30-
script :
31-
'return (' + angularWaits.NG_WAIT_FN + ').apply(null, arguments);',
32-
args : [ this.rootElement, this.ng12hybrid ]
30+
script: 'return (' + angularWaits.NG_WAIT_FN + ').apply(null, arguments);',
31+
args: [this.rootElement, this.ng12hybrid]
3332
});
3433
}
3534

@@ -47,7 +46,7 @@ export class BlockingProxy {
4746
*/
4847
static executeAsyncUrl(originalUrl: string) {
4948
var parts = originalUrl.split('/');
50-
return [ parts[0], parts[1], parts[2], 'execute_async' ].join('/');
49+
return [parts[0], parts[1], parts[2], 'execute_async'].join('/');
5150
}
5251

5352
/**
@@ -77,9 +76,8 @@ export class BlockingProxy {
7776
}
7877

7978
var commandsToWaitFor = [
80-
'executeScript', 'screenshot', 'source', 'title', 'element', 'elements',
81-
'execute', 'keys', 'moveto', 'click', 'buttondown', 'buttonup',
82-
'doubleclick', 'touch', 'get'
79+
'executeScript', 'screenshot', 'source', 'title', 'element', 'elements', 'execute', 'keys',
80+
'moveto', 'click', 'buttondown', 'buttonup', 'doubleclick', 'touch', 'get'
8381
];
8482

8583
if (commandsToWaitFor.indexOf(parts[3]) != -1) {
@@ -116,40 +114,40 @@ export class BlockingProxy {
116114
console.log('Got message: ' + message.url);
117115
var command = message.url.split('/')[2];
118116
switch (command) {
119-
case 'enabled':
120-
if (message.method === 'GET') {
121-
response.writeHead(200);
122-
response.write(JSON.stringify({value : this.stabilityEnabled}));
123-
response.end();
124-
} else if (message.method === 'POST') {
125-
response.writeHead(200);
126-
this.stabilityEnabled = JSON.parse(data).value;
127-
response.end();
128-
} else {
129-
response.writeHead(405);
130-
response.write('Invalid method');
131-
response.end();
132-
}
133-
break;
134-
case 'selenium_address':
135-
if (message.method === 'GET') {
136-
response.writeHead(200);
137-
response.write(JSON.stringify({value : this.seleniumAddress}));
138-
response.end();
139-
} else if (message.method === 'POST') {
140-
response.writeHead(200);
141-
this.seleniumAddress = JSON.parse(data).value;
142-
response.end();
143-
} else {
144-
response.writeHead(405);
145-
response.write('Invalid method');
117+
case 'enabled':
118+
if (message.method === 'GET') {
119+
response.writeHead(200);
120+
response.write(JSON.stringify({value: this.stabilityEnabled}));
121+
response.end();
122+
} else if (message.method === 'POST') {
123+
response.writeHead(200);
124+
this.stabilityEnabled = JSON.parse(data).value;
125+
response.end();
126+
} else {
127+
response.writeHead(405);
128+
response.write('Invalid method');
129+
response.end();
130+
}
131+
break;
132+
case 'selenium_address':
133+
if (message.method === 'GET') {
134+
response.writeHead(200);
135+
response.write(JSON.stringify({value: this.seleniumAddress}));
136+
response.end();
137+
} else if (message.method === 'POST') {
138+
response.writeHead(200);
139+
this.seleniumAddress = JSON.parse(data).value;
140+
response.end();
141+
} else {
142+
response.writeHead(405);
143+
response.write('Invalid method');
144+
response.end();
145+
}
146+
break;
147+
default:
148+
response.writeHead(404);
149+
response.write('Unknown stabilizer proxy command');
146150
response.end();
147-
}
148-
break;
149-
default:
150-
response.writeHead(404);
151-
response.write('Unknown stabilizer proxy command');
152-
response.end();
153151
}
154152
}
155153

@@ -158,12 +156,13 @@ export class BlockingProxy {
158156
console.log('Waiting for stability...', originalRequest.url);
159157
var deferred = new Promise((resolve, reject) => {
160158
var stabilityRequest = self.createSeleniumRequest(
161-
'POST', BlockingProxy.executeAsyncUrl(originalRequest.url),
162-
function(stabilityResponse) {
159+
'POST', BlockingProxy.executeAsyncUrl(originalRequest.url), function(stabilityResponse) {
163160
// TODO - If the response is that angular is not available on the
164161
// page, should we just go ahead and continue?
165162
let stabilityData = '';
166-
stabilityResponse.on('data', (data) => { stabilityData += data; });
163+
stabilityResponse.on('data', (data) => {
164+
stabilityData += data;
165+
});
167166

168167
stabilityResponse.on('error', (err) => {
169168
console.log(err);
@@ -177,8 +176,8 @@ export class BlockingProxy {
177176
// in the browser.
178177
// TODO(heathkit): Extract more useful information from
179178
// webdriver errors.
180-
console.log('Error while waiting for page to stabilize: ',
181-
value['localizedMessage']);
179+
console.log(
180+
'Error while waiting for page to stabilize: ', value['localizedMessage']);
182181
reject(value);
183182
return;
184183
}
@@ -193,14 +192,15 @@ export class BlockingProxy {
193192
return deferred;
194193
}
195194

196-
requestListener(originalRequest: http.IncomingMessage,
197-
response: http.ServerResponse) {
195+
requestListener(originalRequest: http.IncomingMessage, response: http.ServerResponse) {
198196
var self = this;
199197
var stabilized = Promise.resolve(null);
200198

201199
if (BlockingProxy.isProxyCommand(originalRequest.url)) {
202200
let commandData = '';
203-
originalRequest.on('data', (d) => { commandData += d; });
201+
originalRequest.on('data', (d) => {
202+
commandData += d;
203+
});
204204
originalRequest.on('end', () => {
205205
self.handleProxyCommand(originalRequest, commandData, response);
206206
});
@@ -217,10 +217,8 @@ export class BlockingProxy {
217217
stabilized.then(
218218
() => {
219219
var seleniumRequest = self.createSeleniumRequest(
220-
originalRequest.method, originalRequest.url,
221-
function(seleniumResponse) {
222-
response.writeHead(seleniumResponse.statusCode,
223-
seleniumResponse.headers);
220+
originalRequest.method, originalRequest.url, function(seleniumResponse) {
221+
response.writeHead(seleniumResponse.statusCode, seleniumResponse.headers);
224222
seleniumResponse.pipe(response);
225223
});
226224
originalRequest.pipe(seleniumRequest);
@@ -238,6 +236,8 @@ export class BlockingProxy {
238236
}
239237

240238
quit() {
241-
return new Promise((resolve) => { this.server.close(resolve); });
239+
return new Promise((resolve) => {
240+
this.server.close(resolve);
241+
});
242242
}
243243
}

lib/client.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,12 @@ export class BPClient {
1313

1414
setSynchronization(enabled: boolean) {
1515
return new Promise((resolve, reject) => {
16-
let options = {
17-
host: this.hostname,
18-
port: this.port,
19-
method: 'POST',
20-
path: '/stabilize_proxy/enabled'
21-
};
16+
let options =
17+
{host: this.hostname, port: this.port, method: 'POST', path: '/stabilize_proxy/enabled'};
2218

2319
let request = http.request(options, (response) => {
24-
response.on('data', () => {
25-
});
26-
response.on('error', (err) => {
27-
reject(err)
28-
});
20+
response.on('data', () => {});
21+
response.on('error', (err) => {reject(err)});
2922
response.on('end', () => {
3023
resolve();
3124
});
@@ -37,11 +30,7 @@ export class BPClient {
3730

3831
isSyncEnabled() {
3932
return new Promise((res) => {
40-
let options = {
41-
host: this.hostname,
42-
port: this.port,
43-
path: '/stabilize_proxy/enabled'
44-
};
33+
let options = {host: this.hostname, port: this.port, path: '/stabilize_proxy/enabled'};
4534

4635
http.get(options, (response) => {
4736
let body = '';

lib/config.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@ export interface Config {
1010
}
1111

1212
const opts: minimist.Opts = {
13-
boolean : [ 'help' ],
14-
string : [ 'port', 'seleniumAddress' ],
15-
alias : {
16-
help : [ 'h' ],
17-
port : [ 'p' ],
18-
seleniumAddress : [ 's' ],
13+
boolean: ['help'],
14+
string: ['port', 'seleniumAddress'],
15+
alias: {
16+
help: ['h'],
17+
port: ['p'],
18+
seleniumAddress: ['s'],
1919
},
20-
default : {
21-
port : process.env.BP_PORT || 8111,
22-
seleniumAddress :
23-
process.env.BP_SELENIUM_ADDRESS || 'http://localhost:4444/wd/hub',
20+
default: {
21+
port: process.env.BP_PORT || 8111,
22+
seleniumAddress: process.env.BP_SELENIUM_ADDRESS || 'http://localhost:4444/wd/hub',
2423
rootElement: 'body'
2524
}
2625
};

lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1+
export {BlockingProxy} from './blockingproxy';
12
export {BPClient} from './client';
2-
export {BlockingProxy} from './blockingproxy';

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@
4242
"scripts": {
4343
"prepublish": "gulp prepublish",
4444
"start": "node built/lib/bin.js",
45+
"webdriver": "webdriver-manager update && webdriver-manager start",
4546
"test": "jasmine-ts spec/unit/**/*.ts",
4647
"test:auto": "find lib spec | entr jasmine-ts spec/unit/**/*.ts",
47-
"testapp": "node testapp/scripts/web-server.js",
48+
"testapp": "cd testapp && npm start",
49+
"install_testapp": "cd testapp && npm install",
4850
"test:e2e": "jasmine-ts spec/e2e/**/*.ts"
4951
},
5052
"jshintConfig": {

spec/e2e/e2e_spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import {getTestEnv} from './environment';
33
describe('blocking proxy', function() {
44
let driver: webdriver.WebDriver;
55

6-
beforeAll(() => { ({driver} = getTestEnv()); });
6+
beforeAll(() => {
7+
({driver} = getTestEnv());
8+
});
79

810
it('should fail when angular is not available', function(done) {
911
driver.manage().timeouts().setScriptTimeout(20000);

spec/e2e/environment.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ let driver: webdriver.WebDriver;
1010
let bp: BlockingProxy;
1111
let client: BPClient;
1212

13-
export function getTestEnv() { return {driver, bp, client}; }
13+
export function getTestEnv() {
14+
return {driver, bp, client};
15+
}
1416

1517
beforeAll(() => {
1618
bp = new BlockingProxy(WD_URL);
1719
bp.listen(BP_PORT);
1820

1921
let capabilities = webdriver.Capabilities.chrome();
20-
driver = new webdriver.Builder()
21-
.usingServer(BP_URL)
22-
.withCapabilities(capabilities)
23-
.build();
22+
driver = new webdriver.Builder().usingServer(BP_URL).withCapabilities(capabilities).build();
2423
driver.manage().timeouts().setScriptTimeout(20000);
2524

2625
client = new BPClient(BP_URL);
2726
});
2827

29-
afterAll((done) => { driver.quit().then(done, done.fail); });
28+
afterAll((done) => {
29+
driver.quit().then(done, done.fail);
30+
});

0 commit comments

Comments
 (0)