Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit 7de029f

Browse files
authored
Merge pull request mochajs#2672 from Munter/coverage-report
Coverage for node tests
2 parents 5027552 + ad2e32f commit 7de029f

File tree

6 files changed

+50
-21
lines changed

6 files changed

+50
-21
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
coverage/
12
lib/to-iso-string/**/*.js
23
mocha.js

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ npm-debug.log*
1111
.karma/
1212
*.orig
1313
.nyc_output/
14+
coverage/

.nycrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"reporter": [
3+
"json",
4+
"text-summary"
5+
],
6+
"exclude": [
7+
"lib/browser",
8+
"test/**/*"
9+
]
10+
}

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ matrix:
1616
fast_finish: true
1717
include:
1818
- node_js: '7'
19-
env: TARGET=test-node
19+
env: TARGET=test-node COVERAGE=true
2020
- node_js: '6'
2121
env: TARGET=test-node
2222
- node_js: '5'
@@ -42,6 +42,8 @@ before_script: scripts/travis-before-script.sh
4242

4343
script: make $TARGET
4444

45+
after_success: "npm run postcoverage && <coverage/lcov.info ./node_modules/coveralls/bin/coveralls.js"
46+
4547
notifications:
4648
urls:
4749
# for gitter

Makefile

+28-19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ 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+
7+
ifdef COVERAGE
8+
define test_node
9+
$(NYC) --report-dir coverage/reports/$(1) $(MOCHA)
10+
endef
11+
else
12+
test_node := $(MOCHA)
13+
endif
514

615
TM_BUNDLE = JavaScript\ mocha.tmbundle
716
SRC = $(shell find lib -name "*.js" -type f | sort)
@@ -54,24 +63,24 @@ test-jsapi:
5463

5564
test-unit:
5665
@printf "==> [Test :: Unit]\n"
57-
$(MOCHA) test/acceptance/*.js \
66+
$(call test_node,unit) test/acceptance/*.js \
5867
--growl \
5968
test/*.js
6069

6170
test-integration:
6271
@printf "==> [Test :: Integrations]\n"
63-
$(MOCHA) --timeout 5000 \
72+
$(call test_node,integration) --timeout 5000 \
6473
test/integration/*.js
6574

6675
test-compilers:
6776
@printf "==> [Test :: Compilers]\n"
68-
$(MOCHA) --compilers coffee:coffee-script/register,foo:./test/compiler/foo \
77+
$(call test_node,compilers) --compilers coffee:coffee-script/register,foo:./test/compiler/foo \
6978
test/acceptance/test.coffee \
7079
test/acceptance/test.foo
7180

7281
test-requires:
7382
@printf "==> [Test :: Requires]\n"
74-
$(MOCHA) --compilers coffee:coffee-script/register \
83+
$(call test_node,requires) --compilers coffee:coffee-script/register \
7584
--require test/acceptance/require/a.js \
7685
--require test/acceptance/require/b.coffee \
7786
--require test/acceptance/require/c.js \
@@ -80,22 +89,22 @@ test-requires:
8089

8190
test-bdd:
8291
@printf "==> [Test :: BDD]\n"
83-
$(MOCHA) --ui bdd \
92+
$(call test_node,bdd) --ui bdd \
8493
test/acceptance/interfaces/bdd.spec
8594

8695
test-tdd:
8796
@printf "==> [Test :: TDD]\n"
88-
$(MOCHA) --ui tdd \
97+
$(call test_node,tdd) --ui tdd \
8998
test/acceptance/interfaces/tdd.spec
9099

91100
test-qunit:
92101
@printf "==> [Test :: QUnit]\n"
93-
$(MOCHA) --ui qunit \
102+
$(call test_node,qunit) --ui qunit \
94103
test/acceptance/interfaces/qunit.spec
95104

96105
test-exports:
97106
@printf "==> [Test :: Exports]\n"
98-
$(MOCHA) --ui exports \
107+
$(call test_node,exports) --ui exports \
99108
test/acceptance/interfaces/exports.spec
100109

101110
test-glob:
@@ -104,49 +113,49 @@ test-glob:
104113

105114
test-reporters:
106115
@printf "==> [Test :: Reporters]\n"
107-
$(MOCHA) test/reporters/*.js
116+
$(call test_node,reporters) test/reporters/*.js
108117

109118
test-only:
110119
@printf "==> [Test :: Only]\n"
111-
$(MOCHA) --ui tdd \
120+
$(call test_node,only-tdd) --ui tdd \
112121
test/acceptance/misc/only/tdd.spec
113122

114-
$(MOCHA) --ui bdd \
123+
$(call test_node,only-bdd) --ui bdd \
115124
test/acceptance/misc/only/bdd.spec
116125

117-
$(MOCHA) --ui qunit \
126+
$(call test_node,only-bdd-require) --ui qunit \
118127
test/acceptance/misc/only/bdd-require.spec
119128

120129
test-global-only:
121130
@printf "==> [Test :: Global Only]\n"
122-
$(MOCHA) --ui tdd \
131+
$(call test_node,global-only-tdd) --ui tdd \
123132
test/acceptance/misc/only/global/tdd.spec
124133

125-
$(MOCHA) --ui bdd \
134+
$(call test_node,global-only-bdd) --ui bdd \
126135
test/acceptance/misc/only/global/bdd.spec
127136

128-
$(MOCHA) --ui qunit \
137+
$(call test_node,global-only-qunit) --ui qunit \
129138
test/acceptance/misc/only/global/qunit.spec
130139

131140
test-mocha:
132141
@printf "==> [Test :: Mocha]\n"
133-
$(MOCHA) test/mocha
142+
$(call test_node,mocha) test/mocha
134143

135144
non-tty:
136145
@printf "==> [Test :: Non-TTY]\n"
137-
$(MOCHA) --reporter dot \
146+
$(call test_node,non-tty-dot) --reporter dot \
138147
test/acceptance/interfaces/bdd.spec 2>&1 > /tmp/dot.out
139148

140149
@echo dot:
141150
@cat /tmp/dot.out
142151

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

146155
@echo list:
147156
@cat /tmp/list.out
148157

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

152161
@echo spec:

package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,10 @@
299299
"npm": ">= 1.4.x"
300300
},
301301
"scripts": {
302-
"test": "make test"
302+
"test": "make test",
303+
"precoverage": "rm -rf coverage",
304+
"coverage": "COVERAGE=true npm run test",
305+
"postcoverage": "istanbul-combine -d coverage -r lcov -r html coverage/reports/*/*.json"
303306
},
304307
"dependencies": {
305308
"browser-stdout": "1.3.0",
@@ -318,12 +321,14 @@
318321
"assert": "^1.4.1",
319322
"browserify": "^13.0.0",
320323
"coffee-script": "^1.10.0",
324+
"coveralls": "^2.11.15",
321325
"eslint": "^3.11.1",
322326
"eslint-config-semistandard": "^7.0.0",
323327
"eslint-config-standard": "^6.2.1",
324328
"eslint-plugin-promise": "^3.4.0",
325329
"eslint-plugin-standard": "2.0.1",
326330
"expect.js": "^0.3.1",
331+
"istanbul-combine": "^0.3.0",
327332
"karma": "^1.1.0",
328333
"karma-browserify": "^5.0.5",
329334
"karma-chrome-launcher": "^2.0.0",
@@ -332,6 +337,7 @@
332337
"karma-phantomjs-launcher": "^1.0.2",
333338
"karma-sauce-launcher": "^1.0.0",
334339
"karma-spec-reporter": "0.0.26",
340+
"nyc": "^10.0.0",
335341
"os-name": "^2.0.1",
336342
"phantomjs": "1.9.8",
337343
"rimraf": "^2.5.2",

0 commit comments

Comments
 (0)