Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
Merged
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/gulp lint
- 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
34 changes: 34 additions & 0 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,37 @@ Run the browser tests using Karma:
Run the node.js tests:

`npm run test-node`

Run tslint:

`npm run lint`

Run format with clang-format:

`npm run format`

Run all checks (lint/format/browser test/test-node):

`npm run ci`

Before Commit
------------

Please make sure you pass all following checks before commit

- tslint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm -1 on creating a commit hook.
Test should run in watch mode anyway ?

Copy link
Collaborator Author

@JiaLiPassion JiaLiPassion Dec 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, test in monitor mode can make sure all jasmine test passed.
But with pre commit, the hook can check format and lint.

Sometimes I forget to do gulp format and gulp lint, and make a commit, the format error was found by Travis, I just want to let developer find the error before commit.

Are you suggesting when code changes, automatically run format and lint check?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting when code changes, automatically run format and lint check?

you can set up your IDE/editor for that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I see, I have removed the hook

- format:enforce (clang-format)
- npm test (karma test)
- test-node (node test)

You can run

`npm run ci`

to do all those checks for you.
You can also add the script into your git pre-commit hook

```
echo -e 'exec npm run ci' > .git/hooks/pre-commit
chmod u+x .git/hooks/pre-commit
```
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@
},
"scripts": {
"changelog": "gulp changelog",
"ci": "npm run lint && npm run format && npm run test:single && npm run test-node",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document those in the README ?

Copy link
Collaborator Author

@JiaLiPassion JiaLiPassion Dec 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will organize all those scripts and add them into DEVELOPER.md

"format": "gulp format:enforce",
"karma-jasmine": "karma start karma-build-jasmine.conf.js",
"karma-jasmine:single": "karma start karma-build-jasmine.conf.js --single-run",
"karma-jasmine:autoclose": "npm run karma-jasmine:single && npm run ws-client",
"lint": "gulp lint",
"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": "npm run tsc && concurrently \"npm run tsc:w\" \"npm run ws-server\" \"npm run karma-jasmine\"",
"test:single": "npm run tsc && concurrently \"npm run ws-server\" \"npm run karma-jasmine:autoclose\"",
"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
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
*/

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

const conn = ws.connect('ws://localhost:8001', {}, function() {
conn.send('close');
conn.close();
});
8 changes: 6 additions & 2 deletions test/ws-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
* found in the LICENSE file at https://angular.io/license
*/

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

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