From 520f016951865d810d469b6232ac0c19edc1c328 Mon Sep 17 00:00:00 2001 From: domenic <domenic@domenicdenicola.com> Date: Tue, 15 May 2012 22:11:34 -0400 Subject: [PATCH] Adding code coverage for both specs and tests, in Node. Uses itay/node-cover. Run with: npm run-script test-cover npm run-script spec-cover Both will generate cover_html folders with an index.html containing the coverage report. There unfortunately doesn't seem to be a cross-platform way of automatically launching that index.html in your default browser [1]. This reveals a few missing spots, in addition to large swathes of untested-but-that's-OK code (like shims and long stack trace code). Ideally we would be able to run this in different browser environments (e.g. to make sure the shims are covered), but that would require a decent bit more work, I believe. NB some small additions were necessary to make the Jasmine specs run in Node. [1]: http://superuser.com/questions/38984/linux-equivalent-command-for-open-command-on-mac-windows --- .coverignore | 2 ++ .gitignore | 4 ++++ package.json | 8 ++++++-- spec/q-spec.js | 4 ++++ 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 .coverignore diff --git a/.coverignore b/.coverignore new file mode 100644 index 00000000..d3e54736 --- /dev/null +++ b/.coverignore @@ -0,0 +1,2 @@ +test/ +spec/ diff --git a/.gitignore b/.gitignore index 704bac73..e5254095 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ node_modules CHANGES.html README.html + +.coverage_data/ +.coverage_debug/ +cover_html/ diff --git a/package.json b/package.json index d3415487..52617352 100644 --- a/package.json +++ b/package.json @@ -41,10 +41,14 @@ "dependencies": {}, "devDependencies": { "test": ">=0.3.0", - "jshint": "*" + "jshint": "*", + "cover": "*", + "jasmine-node": "*" }, "scripts": { - "test": "node test/all.js" + "test": "node test/all.js", + "test-cover": "cover run test/all.js && cover report html", + "spec-cover": "cover run node_modules/jasmine-node/bin/jasmine-node spec && cover report html" }, "overlay": { "teleport": { diff --git a/spec/q-spec.js b/spec/q-spec.js index cb0cb670..bd3fcec0 100644 --- a/spec/q-spec.js +++ b/spec/q-spec.js @@ -1,3 +1,7 @@ +if (typeof Q === "undefined" && typeof require !== "undefined") { + // For Node compatability. + this.Q = require("../q"); +} describe("defer and when", function () {