From fb8d51ce74670c0dcd4ee1d4c9f55364597782a0 Mon Sep 17 00:00:00 2001 From: JiaLiPassion Date: Thu, 12 Jan 2017 09:06:42 +0900 Subject: [PATCH] Fix #532, Fix #566, add tslint in ci, add tslint/format/test/karma in precommit of git (#565) * fix #532, add tslint in ci, add tslint/karma/testnode/format in git commit hook * fix #532, add tslint in ci, add tslint/karma/testnode/format in git commit hook * use format:enforce * rename package.json script's name * update developer.md to add precommit details * change var to const * add scripts explaination into DEVELOPER.md, use gulp lint * remove pre-commit hooks * update DEVELOPER.md to add process for before commit * format DEVELOPMER.md --- .travis.yml | 1 + DEVELOPER.md | 34 ++++++++++++++++++++++++++++++++++ package.json | 10 +++++++++- test/ws-client.js | 14 ++++++++++++++ test/ws-server.js | 8 ++++++-- 5 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 test/ws-client.js diff --git a/.travis.yml b/.travis.yml index 020ab26ea..5e252c3fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/DEVELOPER.md b/DEVELOPER.md index 6ebb1e507..e5c42021b 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -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 +- 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 +``` diff --git a/package.json b/package.json index 97d6c6b8c..9f0325ddc 100644 --- a/package.json +++ b/package.json @@ -15,11 +15,19 @@ }, "scripts": { "changelog": "gulp changelog", + "ci": "npm run lint && npm run format && npm run test:single && npm run test-node", + "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\"", diff --git a/test/ws-client.js b/test/ws-client.js new file mode 100644 index 000000000..9b316e15d --- /dev/null +++ b/test/ws-client.js @@ -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(); +}); diff --git a/test/ws-server.js b/test/ws-server.js index 192646a63..85b38c735 100644 --- a/test/ws-server.js +++ b/test/ws-server.js @@ -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);