Skip to content

Commit

Permalink
fix angular#532, add tslint in ci, add tslint/karma/testnode/format i…
Browse files Browse the repository at this point in the history
…n git commit hook
  • Loading branch information
JiaLiPassion committed Dec 27, 2016
1 parent 1de7ea0 commit d28189f
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 35 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ before_script:
- ./scripts/sauce/sauce_connect_block.sh

script:
- node_modules/.bin/tslint -c tslint.json 'lib/**/*.ts' 'test/**/*.ts'
- node_modules/.bin/gulp format:enforce
- node_modules/.bin/gulp build
- node_modules/.bin/karma start karma-dist-sauce-jasmine.conf.js --single-run
Expand Down
59 changes: 28 additions & 31 deletions lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,9 @@ export interface ListenerTaskMeta extends TaskData {
handler: NestedEventListenerOrEventListenerObject;
target: any;
name: string;
invokeAddFunc: (addFnSymbol: any, delegate: Task|NestedEventListenerOrEventListenerObject) => any,
invokeRemoveFunc:
(removeFnSymbol: any, delegate: Task|
NestedEventListenerOrEventListenerObject) => any
invokeAddFunc: (addFnSymbol: any, delegate: Task|NestedEventListenerOrEventListenerObject) => any;
invokeRemoveFunc:
(removeFnSymbol: any, delegate: Task|NestedEventListenerOrEventListenerObject) => any;
}

function findExistingRegisteredTask(
Expand Down Expand Up @@ -210,34 +209,32 @@ function attachRegisteredEvent(target: any, eventTask: Task, isPrepend: boolean)
}
}

const defaultListenerMetaCreator =
(self: any, args: any[]) => {
return {
useCapturing: args[2],
eventName: args[0],
handler: args[1],
target: self || _global,
name: args[0],
invokeAddFunc: function(
addFnSymbol: any, delegate: Task|NestedEventListenerOrEventListenerObject) {
if (delegate && (<Task>delegate).invoke) {
return this.target[addFnSymbol](
this.eventName, (<Task>delegate).invoke, this.useCapturing);
} else {
return this.target[addFnSymbol](this.eventName, delegate, this.useCapturing);
}
},
invokeRemoveFunc: function(
removeFnSymbol: any, delegate: Task|NestedEventListenerOrEventListenerObject) {
if (delegate && (<Task>delegate).invoke) {
return this.target[removeFnSymbol](
this.eventName, (<Task>delegate).invoke, this.useCapturing);
} else {
return this.target[removeFnSymbol](this.eventName, delegate, this.useCapturing);
}
}
};
const defaultListenerMetaCreator = (self: any, args: any[]) => {
return {
useCapturing: args[2],
eventName: args[0],
handler: args[1],
target: self || _global,
name: args[0],
invokeAddFunc: function(
addFnSymbol: any, delegate: Task|NestedEventListenerOrEventListenerObject) {
if (delegate && (<Task>delegate).invoke) {
return this.target[addFnSymbol](this.eventName, (<Task>delegate).invoke, this.useCapturing);
} else {
return this.target[addFnSymbol](this.eventName, delegate, this.useCapturing);
}
},
invokeRemoveFunc: function(
removeFnSymbol: any, delegate: Task|NestedEventListenerOrEventListenerObject) {
if (delegate && (<Task>delegate).invoke) {
return this.target[removeFnSymbol](
this.eventName, (<Task>delegate).invoke, this.useCapturing);
} else {
return this.target[removeFnSymbol](this.eventName, delegate, this.useCapturing);
}
}
};
};

export function makeZoneAwareAddListener(
addFnName: string, removeFnName: string, useCapturingParam: boolean = true,
Expand Down
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@
},
"scripts": {
"changelog": "gulp changelog",
"ci": "npm run lint && npm run format && npm run test:single && npm run test-node",
"format": "gulp format",
"karma-jasmine": "karma start karma-build-jasmine.conf.js --single-run",
"karma-jasmine:single": "npm run karma-jasmine && npm run ws-client",
"lint": "tslint -c tslint.json 'test/**/*.ts' 'lib/**/*.ts'",
"prepublish": "tsc && gulp build",
"ws-client": "node ./test/ws-client.js",
"ws-server": "node ./test/ws-server.js",
"tsc": "tsc",
"tsc:w": "tsc -w",
"test": "npm run tsc && concurrently \"npm run tsc:w\" \"npm run ws-server\" \"karma start karma-build-jasmine.conf.js\"",
"test:single": "npm run tsc && concurrently \"npm run ws-server\" \"npm run karma-jasmine:single\"",
"test-dist": "concurrently \"npm run tsc:w\" \"npm run ws-server\" \"karma start karma-dist-jasmine.conf.js\"",
"test-node": "gulp test/node",
"test-mocha": "npm run tsc && concurrently \"npm run tsc:w\" \"npm run ws-server\" \"karma start karma-build-mocha.conf.js\"",
Expand Down Expand Up @@ -71,5 +78,10 @@
"tslint-eslint-rules": "^3.1.0",
"typescript": "^2.0.2",
"whatwg-fetch": "^2.0.1"
},
"config": {
"ghooks": {
"pre-commit": "echo \"Checking commit...\" && npm run ci"
}
}
}
4 changes: 2 additions & 2 deletions test/browser/XMLHttpRequest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe('XMLHttpRequest', function() {
req.onloadend = function() {
req.open('get', '/', true);
req.send();
}
};
});
})
});
});
3 changes: 2 additions & 1 deletion test/browser/browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ describe('Zone', function() {
button.setAttribute('onclick', 'return');
expect(button.onclick).not.toBe(null);
});
})
});

});
});
});
14 changes: 14 additions & 0 deletions test/ws-client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

var ws = require('nodejs-websocket');

var conn = ws.connect('ws://localhost:8001', {}, function() {
conn.send('close');
conn.close();
});
6 changes: 5 additions & 1 deletion test/ws-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
var ws = require('nodejs-websocket');

// simple echo server
ws.createServer(function (conn) {
var server = ws.createServer(function (conn) {
conn.on('text', function (str) {
if (str === 'close') {
server.close();
return;
}
conn.sendText(str.toString());
});
}).listen(8001);

0 comments on commit d28189f

Please sign in to comment.