From dec1cc5517a1ca01096efb4c016c3cc205994441 Mon Sep 17 00:00:00 2001 From: Christoph Neuroth Date: Tue, 17 Jan 2017 19:36:49 +0200 Subject: [PATCH 1/4] Generate coverage reports for node tests --- .eslintignore | 1 + .gitignore | 1 + Makefile | 53 ++++++++++++++++++++++++++++++++------------------- package.json | 2 ++ 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/.eslintignore b/.eslintignore index 3e4b026a81..d5134e407e 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ +coverage/ lib/to-iso-string/**/*.js mocha.js diff --git a/.gitignore b/.gitignore index 05fd3db57e..05cc01726e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ npm-debug.log* .karma/ *.orig .nyc_output/ +coverage/ diff --git a/Makefile b/Makefile index 40a098e318..7dc2687fb9 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,13 @@ BROWSERIFY := "node_modules/.bin/browserify" ESLINT := "node_modules/.bin/eslint" KARMA := "node_modules/.bin/karma" MOCHA := "bin/mocha" +NYC := "node_modules/.bin/nyc" +ISTANBUL_COMBINE := "node_modules/.bin/istanbul-combine" +COVERAGE_DIR := "coverage/" + +define test_node + $(NYC) --report-dir coverage/$(1) --reporter json --exclude browser $(MOCHA) +endef TM_BUNDLE = JavaScript\ mocha.tmbundle SRC = $(shell find lib -name "*.js" -type f | sort) @@ -26,11 +33,17 @@ lint: @printf "==> [Test :: Lint]\n" $(ESLINT) . bin/* +COVERAGE_TMP_DIR:=$(shell mktemp -d) +generate-coverage-report: + $(ISTANBUL_COMBINE) -d $(COVERAGE_TMP_DIR) -r lcov -r html $(COVERAGE_DIR)/*/*.json + rm -rf $(COVERAGE_DIR) + mv $(COVERAGE_TMP_DIR) $(COVERAGE_DIR) + test-node: test-bdd test-tdd test-qunit test-exports test-unit test-integration test-jsapi test-compilers test-glob test-requires test-reporters test-only test-global-only test-browser: clean mocha.js test-browser-unit test-browser-bdd test-browser-qunit test-browser-tdd test-browser-exports -test: lint test-node test-browser +test: lint test-node test-browser generate-coverage-report test-browser-unit: @printf "==> [Test :: Browser]\n" @@ -54,24 +67,24 @@ test-jsapi: test-unit: @printf "==> [Test :: Unit]\n" - $(MOCHA) test/acceptance/*.js \ + $(call test_node,unit) test/acceptance/*.js \ --growl \ test/*.js test-integration: @printf "==> [Test :: Integrations]\n" - $(MOCHA) --timeout 5000 \ + $(call test_node,integration) --timeout 5000 \ test/integration/*.js test-compilers: @printf "==> [Test :: Compilers]\n" - $(MOCHA) --compilers coffee:coffee-script/register,foo:./test/compiler/foo \ + $(call test_node,compilers) --compilers coffee:coffee-script/register,foo:./test/compiler/foo \ test/acceptance/test.coffee \ test/acceptance/test.foo test-requires: @printf "==> [Test :: Requires]\n" - $(MOCHA) --compilers coffee:coffee-script/register \ + $(call test_node,requires) --compilers coffee:coffee-script/register \ --require test/acceptance/require/a.js \ --require test/acceptance/require/b.coffee \ --require test/acceptance/require/c.js \ @@ -80,22 +93,22 @@ test-requires: test-bdd: @printf "==> [Test :: BDD]\n" - $(MOCHA) --ui bdd \ + $(call test_node,bdd) --ui bdd \ test/acceptance/interfaces/bdd.spec test-tdd: @printf "==> [Test :: TDD]\n" - $(MOCHA) --ui tdd \ + $(call test_node,tdd) --ui tdd \ test/acceptance/interfaces/tdd.spec test-qunit: @printf "==> [Test :: QUnit]\n" - $(MOCHA) --ui qunit \ + $(call test_node,qunit) --ui qunit \ test/acceptance/interfaces/qunit.spec test-exports: @printf "==> [Test :: Exports]\n" - $(MOCHA) --ui exports \ + $(call test_node,exports) --ui exports \ test/acceptance/interfaces/exports.spec test-glob: @@ -104,49 +117,49 @@ test-glob: test-reporters: @printf "==> [Test :: Reporters]\n" - $(MOCHA) test/reporters/*.js + $(call test_node,reporters) test/reporters/*.js test-only: @printf "==> [Test :: Only]\n" - $(MOCHA) --ui tdd \ + $(call test_node,only-tdd) --ui tdd \ test/acceptance/misc/only/tdd.spec - $(MOCHA) --ui bdd \ + $(call test_node,only-bdd) --ui bdd \ test/acceptance/misc/only/bdd.spec - $(MOCHA) --ui qunit \ + $(call test_node,only-bdd-require) --ui qunit \ test/acceptance/misc/only/bdd-require.spec test-global-only: @printf "==> [Test :: Global Only]\n" - $(MOCHA) --ui tdd \ + $(call test_node,global-only-tdd) --ui tdd \ test/acceptance/misc/only/global/tdd.spec - $(MOCHA) --ui bdd \ + $(call test_node,global-only-bdd) --ui bdd \ test/acceptance/misc/only/global/bdd.spec - $(MOCHA) --ui qunit \ + $(call test_node,global-only-qunit) --ui qunit \ test/acceptance/misc/only/global/qunit.spec test-mocha: @printf "==> [Test :: Mocha]\n" - $(MOCHA) test/mocha + $(call test_node,mocha) test/mocha non-tty: @printf "==> [Test :: Non-TTY]\n" - $(MOCHA) --reporter dot \ + $(call test_node,non-tty-dot) --reporter dot \ test/acceptance/interfaces/bdd.spec 2>&1 > /tmp/dot.out @echo dot: @cat /tmp/dot.out - $(MOCHA) --reporter list \ + $(call test_node,non-tty-list) --reporter list \ test/acceptance/interfaces/bdd.spec 2>&1 > /tmp/list.out @echo list: @cat /tmp/list.out - $(MOCHA) --reporter spec \ + $(call test_node,non-tty-spec) --reporter spec \ test/acceptance/interfaces/bdd.spec 2>&1 > /tmp/spec.out @echo spec: diff --git a/package.json b/package.json index 764c159381..38ebf7b990 100644 --- a/package.json +++ b/package.json @@ -324,6 +324,7 @@ "eslint-plugin-promise": "^3.4.0", "eslint-plugin-standard": "2.0.1", "expect.js": "^0.3.1", + "istanbul-combine": "^0.3.0", "karma": "^1.1.0", "karma-browserify": "^5.0.5", "karma-chrome-launcher": "^2.0.0", @@ -332,6 +333,7 @@ "karma-phantomjs-launcher": "^1.0.2", "karma-sauce-launcher": "^1.0.0", "karma-spec-reporter": "0.0.26", + "nyc": "^10.0.0", "os-name": "^2.0.1", "phantomjs": "1.9.8", "rimraf": "^2.5.2", From 532c0b86ff9b6b84d1915de3b2935c2e0205716c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20M=C3=BCller?= Date: Tue, 17 Jan 2017 21:59:38 +0100 Subject: [PATCH 2/4] Move coverage report aggregation out into npm scripts --- Makefile | 16 ++++++---------- package.json | 5 ++++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 7dc2687fb9..8a9662d98c 100644 --- a/Makefile +++ b/Makefile @@ -3,12 +3,14 @@ ESLINT := "node_modules/.bin/eslint" KARMA := "node_modules/.bin/karma" MOCHA := "bin/mocha" NYC := "node_modules/.bin/nyc" -ISTANBUL_COMBINE := "node_modules/.bin/istanbul-combine" -COVERAGE_DIR := "coverage/" +ifdef COVERAGE define test_node - $(NYC) --report-dir coverage/$(1) --reporter json --exclude browser $(MOCHA) + $(NYC) --report-dir coverage/reports/$(1) --reporter json --exclude browser $(MOCHA) endef +else + test_node := $(MOCHA) +endif TM_BUNDLE = JavaScript\ mocha.tmbundle SRC = $(shell find lib -name "*.js" -type f | sort) @@ -33,17 +35,11 @@ lint: @printf "==> [Test :: Lint]\n" $(ESLINT) . bin/* -COVERAGE_TMP_DIR:=$(shell mktemp -d) -generate-coverage-report: - $(ISTANBUL_COMBINE) -d $(COVERAGE_TMP_DIR) -r lcov -r html $(COVERAGE_DIR)/*/*.json - rm -rf $(COVERAGE_DIR) - mv $(COVERAGE_TMP_DIR) $(COVERAGE_DIR) - test-node: test-bdd test-tdd test-qunit test-exports test-unit test-integration test-jsapi test-compilers test-glob test-requires test-reporters test-only test-global-only test-browser: clean mocha.js test-browser-unit test-browser-bdd test-browser-qunit test-browser-tdd test-browser-exports -test: lint test-node test-browser generate-coverage-report +test: lint test-node test-browser test-browser-unit: @printf "==> [Test :: Browser]\n" diff --git a/package.json b/package.json index 38ebf7b990..85e6a45583 100644 --- a/package.json +++ b/package.json @@ -299,7 +299,10 @@ "npm": ">= 1.4.x" }, "scripts": { - "test": "make test" + "test": "make test", + "precoverage": "rm -rf coverage", + "coverage": "COVERAGE=true npm run test", + "postcoverage": "istanbul-combine -d coverage -r lcov -r html coverage/reports/*/*.json" }, "dependencies": { "browser-stdout": "1.3.0", From 8750c3f5fb507018ac780ea4992a6191c494e2e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20M=C3=BCller?= Date: Tue, 17 Jan 2017 22:18:59 +0100 Subject: [PATCH 3/4] Move nyc configuration to .nycrc. Exclude tests from getting annotated for coverage --- .nycrc | 10 ++++++++++ Makefile | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .nycrc diff --git a/.nycrc b/.nycrc new file mode 100644 index 0000000000..8848fa90fd --- /dev/null +++ b/.nycrc @@ -0,0 +1,10 @@ +{ + "reporter": [ + "json", + "text-summary" + ], + "exclude": [ + "lib/browser", + "test/**/*" + ] +} diff --git a/Makefile b/Makefile index 8a9662d98c..c7d9e8a342 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ NYC := "node_modules/.bin/nyc" ifdef COVERAGE define test_node - $(NYC) --report-dir coverage/reports/$(1) --reporter json --exclude browser $(MOCHA) + $(NYC) --report-dir coverage/reports/$(1) $(MOCHA) endef else test_node := $(MOCHA) From 820d61639a95e808d58ea73f0860f7e139b2b7da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20M=C3=BCller?= Date: Tue, 17 Jan 2017 22:43:47 +0100 Subject: [PATCH 4/4] Set up travis to run coverage for Node 7 and post report to coveralls --- .travis.yml | 4 +++- package.json | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a80e4983a6..553966a6fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ matrix: fast_finish: true include: - node_js: '7' - env: TARGET=test-node + env: TARGET=test-node COVERAGE=true - node_js: '6' env: TARGET=test-node - node_js: '5' @@ -42,6 +42,8 @@ before_script: scripts/travis-before-script.sh script: make $TARGET +after_success: "npm run postcoverage &&