Skip to content

Commit dec1cc5

Browse files
committed
Generate coverage reports for node tests
1 parent eac6f3c commit dec1cc5

File tree

4 files changed

+37
-20
lines changed

4 files changed

+37
-20
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
coverage/
12
lib/to-iso-string/**/*.js
23
mocha.js

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ npm-debug.log*
1111
.karma/
1212
*.orig
1313
.nyc_output/
14+
coverage/

Makefile

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ BROWSERIFY := "node_modules/.bin/browserify"
22
ESLINT := "node_modules/.bin/eslint"
33
KARMA := "node_modules/.bin/karma"
44
MOCHA := "bin/mocha"
5+
NYC := "node_modules/.bin/nyc"
6+
ISTANBUL_COMBINE := "node_modules/.bin/istanbul-combine"
7+
COVERAGE_DIR := "coverage/"
8+
9+
define test_node
10+
$(NYC) --report-dir coverage/$(1) --reporter json --exclude browser $(MOCHA)
11+
endef
512

613
TM_BUNDLE = JavaScript\ mocha.tmbundle
714
SRC = $(shell find lib -name "*.js" -type f | sort)
@@ -26,11 +33,17 @@ lint:
2633
@printf "==> [Test :: Lint]\n"
2734
$(ESLINT) . bin/*
2835

36+
COVERAGE_TMP_DIR:=$(shell mktemp -d)
37+
generate-coverage-report:
38+
$(ISTANBUL_COMBINE) -d $(COVERAGE_TMP_DIR) -r lcov -r html $(COVERAGE_DIR)/*/*.json
39+
rm -rf $(COVERAGE_DIR)
40+
mv $(COVERAGE_TMP_DIR) $(COVERAGE_DIR)
41+
2942
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
3043

3144
test-browser: clean mocha.js test-browser-unit test-browser-bdd test-browser-qunit test-browser-tdd test-browser-exports
3245

33-
test: lint test-node test-browser
46+
test: lint test-node test-browser generate-coverage-report
3447

3548
test-browser-unit:
3649
@printf "==> [Test :: Browser]\n"
@@ -54,24 +67,24 @@ test-jsapi:
5467

5568
test-unit:
5669
@printf "==> [Test :: Unit]\n"
57-
$(MOCHA) test/acceptance/*.js \
70+
$(call test_node,unit) test/acceptance/*.js \
5871
--growl \
5972
test/*.js
6073

6174
test-integration:
6275
@printf "==> [Test :: Integrations]\n"
63-
$(MOCHA) --timeout 5000 \
76+
$(call test_node,integration) --timeout 5000 \
6477
test/integration/*.js
6578

6679
test-compilers:
6780
@printf "==> [Test :: Compilers]\n"
68-
$(MOCHA) --compilers coffee:coffee-script/register,foo:./test/compiler/foo \
81+
$(call test_node,compilers) --compilers coffee:coffee-script/register,foo:./test/compiler/foo \
6982
test/acceptance/test.coffee \
7083
test/acceptance/test.foo
7184

7285
test-requires:
7386
@printf "==> [Test :: Requires]\n"
74-
$(MOCHA) --compilers coffee:coffee-script/register \
87+
$(call test_node,requires) --compilers coffee:coffee-script/register \
7588
--require test/acceptance/require/a.js \
7689
--require test/acceptance/require/b.coffee \
7790
--require test/acceptance/require/c.js \
@@ -80,22 +93,22 @@ test-requires:
8093

8194
test-bdd:
8295
@printf "==> [Test :: BDD]\n"
83-
$(MOCHA) --ui bdd \
96+
$(call test_node,bdd) --ui bdd \
8497
test/acceptance/interfaces/bdd.spec
8598

8699
test-tdd:
87100
@printf "==> [Test :: TDD]\n"
88-
$(MOCHA) --ui tdd \
101+
$(call test_node,tdd) --ui tdd \
89102
test/acceptance/interfaces/tdd.spec
90103

91104
test-qunit:
92105
@printf "==> [Test :: QUnit]\n"
93-
$(MOCHA) --ui qunit \
106+
$(call test_node,qunit) --ui qunit \
94107
test/acceptance/interfaces/qunit.spec
95108

96109
test-exports:
97110
@printf "==> [Test :: Exports]\n"
98-
$(MOCHA) --ui exports \
111+
$(call test_node,exports) --ui exports \
99112
test/acceptance/interfaces/exports.spec
100113

101114
test-glob:
@@ -104,49 +117,49 @@ test-glob:
104117

105118
test-reporters:
106119
@printf "==> [Test :: Reporters]\n"
107-
$(MOCHA) test/reporters/*.js
120+
$(call test_node,reporters) test/reporters/*.js
108121

109122
test-only:
110123
@printf "==> [Test :: Only]\n"
111-
$(MOCHA) --ui tdd \
124+
$(call test_node,only-tdd) --ui tdd \
112125
test/acceptance/misc/only/tdd.spec
113126

114-
$(MOCHA) --ui bdd \
127+
$(call test_node,only-bdd) --ui bdd \
115128
test/acceptance/misc/only/bdd.spec
116129

117-
$(MOCHA) --ui qunit \
130+
$(call test_node,only-bdd-require) --ui qunit \
118131
test/acceptance/misc/only/bdd-require.spec
119132

120133
test-global-only:
121134
@printf "==> [Test :: Global Only]\n"
122-
$(MOCHA) --ui tdd \
135+
$(call test_node,global-only-tdd) --ui tdd \
123136
test/acceptance/misc/only/global/tdd.spec
124137

125-
$(MOCHA) --ui bdd \
138+
$(call test_node,global-only-bdd) --ui bdd \
126139
test/acceptance/misc/only/global/bdd.spec
127140

128-
$(MOCHA) --ui qunit \
141+
$(call test_node,global-only-qunit) --ui qunit \
129142
test/acceptance/misc/only/global/qunit.spec
130143

131144
test-mocha:
132145
@printf "==> [Test :: Mocha]\n"
133-
$(MOCHA) test/mocha
146+
$(call test_node,mocha) test/mocha
134147

135148
non-tty:
136149
@printf "==> [Test :: Non-TTY]\n"
137-
$(MOCHA) --reporter dot \
150+
$(call test_node,non-tty-dot) --reporter dot \
138151
test/acceptance/interfaces/bdd.spec 2>&1 > /tmp/dot.out
139152

140153
@echo dot:
141154
@cat /tmp/dot.out
142155

143-
$(MOCHA) --reporter list \
156+
$(call test_node,non-tty-list) --reporter list \
144157
test/acceptance/interfaces/bdd.spec 2>&1 > /tmp/list.out
145158

146159
@echo list:
147160
@cat /tmp/list.out
148161

149-
$(MOCHA) --reporter spec \
162+
$(call test_node,non-tty-spec) --reporter spec \
150163
test/acceptance/interfaces/bdd.spec 2>&1 > /tmp/spec.out
151164

152165
@echo spec:

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@
324324
"eslint-plugin-promise": "^3.4.0",
325325
"eslint-plugin-standard": "2.0.1",
326326
"expect.js": "^0.3.1",
327+
"istanbul-combine": "^0.3.0",
327328
"karma": "^1.1.0",
328329
"karma-browserify": "^5.0.5",
329330
"karma-chrome-launcher": "^2.0.0",
@@ -332,6 +333,7 @@
332333
"karma-phantomjs-launcher": "^1.0.2",
333334
"karma-sauce-launcher": "^1.0.0",
334335
"karma-spec-reporter": "0.0.26",
336+
"nyc": "^10.0.0",
335337
"os-name": "^2.0.1",
336338
"phantomjs": "1.9.8",
337339
"rimraf": "^2.5.2",

0 commit comments

Comments
 (0)