From 8c19861a947db3e9aca629de66af221c53ab23eb Mon Sep 17 00:00:00 2001 From: Malte-Thorben Bruns Date: Tue, 25 Sep 2012 22:26:45 +0200 Subject: [PATCH] code coverage & cleanup --- .gitignore | 3 +++ .jshintignore | 3 +++ LICENSE | 2 +- Makefile | 31 +++++++++++++++++++++++++++---- README.markdown | 34 ++++++++++++++++++++++++++++++++++ index.js | 8 ++++---- lib/caster.js | 4 +--- lib/index.js | 4 +--- lib/middleware/crypto.js | 10 +++++----- lib/middleware/hash.js | 4 +--- lib/middleware/index.js | 4 +--- lib/middleware/json.js | 4 +--- lib/node.js | 4 +--- test/mocha.opts | 1 - test/test-caster.js | 8 +++++--- test/test-node.js | 6 ++++-- 16 files changed, 92 insertions(+), 38 deletions(-) create mode 100644 .jshintignore diff --git a/.gitignore b/.gitignore index 93f1361..82e1a43 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ node_modules npm-debug.log +coverage.html +lib-cov +node-jscoverage diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 0000000..3e80f63 --- /dev/null +++ b/.jshintignore @@ -0,0 +1,3 @@ +node_modules +lib-cov +node-jscoverage diff --git a/LICENSE b/LICENSE index 92ebfcc..5792d84 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ (The MIT License) -Copyright (c) 2012 Malte-Thorben Bruns +Copyright (c) 2012 Malte-Thorben Bruns Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/Makefile b/Makefile index f35f6ae..b9a5eaf 100644 --- a/Makefile +++ b/Makefile @@ -2,14 +2,37 @@ # node-caster Makefile # @author skenqbx@gmail.com (Malte-Thorben Bruns) # -REPORTER ?= spec +REPORTER ?= list all: jshint test + @ jshint: - @node_modules/.bin/jshint lib/ index.js + @node_modules/.bin/jshint ./ test: - @node_modules/.bin/mocha --reporter $(REPORTER) test/*.js + @node_modules/.bin/mocha -R ${REPORTER} -.PHONY: jshint test +test-cov: lib-cov + @CASTER_COV=1 $(MAKE) test REPORTER=html-cov > coverage.html + +lib-cov: + @rm -rf lib-cov/ + @./node-jscoverage/jscoverage lib lib-cov + +install: node_modules node-jscoverage + @ + +node-jscoverage: + @git clone git://github.com/visionmedia/node-jscoverage.git + @cd node-jscoverage/ && ./configure && make + +node_modules: + @npm install + +clean: + @rm -rf node-jscoverage/ + @rm -rf node_modules/ + @rm -rf lib-cov/ + +.PHONY: jshint test lib-cov diff --git a/README.markdown b/README.markdown index abef5bf..49726c5 100644 --- a/README.markdown +++ b/README.markdown @@ -263,3 +263,37 @@ Emitted when a remote node _disappeared_. `function(remote)` `remote` is the object just removed from [node.nodes](#nodenodes). + +## tests +``` +make install +make jshint +make test +make test-cov +``` + +## license +``` +(The MIT License) + +Copyright (c) 2012 Malte-Thorben Bruns + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +``` diff --git a/index.js b/index.js index b00800a..dc370ab 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -// Copyright (c) 2012 Malte-Thorben Bruns +// Copyright (c) 2012 Malte-Thorben Bruns // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -18,8 +18,8 @@ // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* enable ECMA-262 strict mode */ 'use strict'; -module.exports = require('./lib'); +module.exports = process.env.CASTER_COV ? + require('./lib-cov') : + require('./lib'); diff --git a/lib/caster.js b/lib/caster.js index 515943f..7e1224a 100644 --- a/lib/caster.js +++ b/lib/caster.js @@ -1,4 +1,4 @@ -// Copyright (c) 2012 Malte-Thorben Bruns +// Copyright (c) 2012 Malte-Thorben Bruns // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -18,8 +18,6 @@ // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* enable ECMA-262 strict mode */ 'use strict'; /* load node modules */ diff --git a/lib/index.js b/lib/index.js index 6028076..97ea504 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,4 +1,4 @@ -// Copyright (c) 2012 Malte-Thorben Bruns +// Copyright (c) 2012 Malte-Thorben Bruns // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -18,8 +18,6 @@ // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* enable ECMA-262 strict mode */ 'use strict'; /* load modules */ diff --git a/lib/middleware/crypto.js b/lib/middleware/crypto.js index 0fad3e2..e58b1d9 100644 --- a/lib/middleware/crypto.js +++ b/lib/middleware/crypto.js @@ -1,4 +1,4 @@ -// Copyright (c) 2012 Malte-Thorben Bruns +// Copyright (c) 2012 Malte-Thorben Bruns // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -18,8 +18,6 @@ // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* enable ECMA-262 strict mode */ 'use strict'; /* load node modules */ @@ -35,9 +33,10 @@ function cryptoMiddleware(opt_options) { var algorithm = opt_options.algorithm || 'aes256'; function tx(message, next) { + var msg; try { var cipher = crypto.createCipher(algorithm, key); - var msg = cipher.update(message.toString('binary'), 'binary', 'binary'); + msg = cipher.update(message.toString('binary'), 'binary', 'binary'); msg += cipher.final('binary'); } catch (err) { return next(err, null); @@ -46,9 +45,10 @@ function cryptoMiddleware(opt_options) { } function rx(message, remote, next) { + var msg; try { var decipher = crypto.createDecipher(algorithm, key); - var msg = decipher.update(message.toString('binary'), 'binary', 'binary'); + msg = decipher.update(message.toString('binary'), 'binary', 'binary'); msg += decipher.final('binary'); } catch (err) { return next(err, null); diff --git a/lib/middleware/hash.js b/lib/middleware/hash.js index 77a4c3c..af836aa 100644 --- a/lib/middleware/hash.js +++ b/lib/middleware/hash.js @@ -1,4 +1,4 @@ -// Copyright (c) 2012 Malte-Thorben Bruns +// Copyright (c) 2012 Malte-Thorben Bruns // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -18,8 +18,6 @@ // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* enable ECMA-262 strict mode */ 'use strict'; /* load node modules */ diff --git a/lib/middleware/index.js b/lib/middleware/index.js index 040b3ae..428325c 100644 --- a/lib/middleware/index.js +++ b/lib/middleware/index.js @@ -1,4 +1,4 @@ -// Copyright (c) 2012 Malte-Thorben Bruns +// Copyright (c) 2012 Malte-Thorben Bruns // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -18,8 +18,6 @@ // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* enable ECMA-262 strict mode */ 'use strict'; /* export modules */ diff --git a/lib/middleware/json.js b/lib/middleware/json.js index 52c54fe..3bf9f67 100644 --- a/lib/middleware/json.js +++ b/lib/middleware/json.js @@ -1,4 +1,4 @@ -// Copyright (c) 2012 Malte-Thorben Bruns +// Copyright (c) 2012 Malte-Thorben Bruns // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -18,8 +18,6 @@ // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* enable ECMA-262 strict mode */ 'use strict'; diff --git a/lib/node.js b/lib/node.js index ee97d3e..9a8ccae 100644 --- a/lib/node.js +++ b/lib/node.js @@ -1,4 +1,4 @@ -// Copyright (c) 2012 Malte-Thorben Bruns +// Copyright (c) 2012 Malte-Thorben Bruns // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -18,8 +18,6 @@ // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* enable ECMA-262 strict mode */ 'use strict'; /* load node modules */ diff --git a/test/mocha.opts b/test/mocha.opts index b8cd73a..9207fe1 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,3 +1,2 @@ --ui bdd --timeout 2000 ---verbose diff --git a/test/test-caster.js b/test/test-caster.js index a7df972..2a5d351 100644 --- a/test/test-caster.js +++ b/test/test-caster.js @@ -1,4 +1,4 @@ -// Copyright (c) 2012 Malte-Thorben Bruns +// Copyright (c) 2012 Malte-Thorben Bruns // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -18,12 +18,14 @@ // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +'use strict'; +/*global describe it afterEach after*/ describe('Caster', function() { - var caster = require('../lib'); + var caster = require('../'); var options = { - port: 43214 + port: 43215 }; var socketA = caster.create(options); diff --git a/test/test-node.js b/test/test-node.js index a1a8b0a..e007fae 100644 --- a/test/test-node.js +++ b/test/test-node.js @@ -1,4 +1,4 @@ -// Copyright (c) 2012 Malte-Thorben Bruns +// Copyright (c) 2012 Malte-Thorben Bruns // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -18,9 +18,11 @@ // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +'use strict'; +/*global describe it afterEach after*/ describe('Node', function() { - var caster = require('../lib'); + var caster = require('../'); var options = { port: 43214