Skip to content

Commit

Permalink
Merge pull request mochajs#2672 from Munter/coverage-report
Browse files Browse the repository at this point in the history
Coverage for node tests
  • Loading branch information
Munter authored Jan 17, 2017
2 parents eac6f3c + 820d616 commit 24df20a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 21 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
coverage/
lib/to-iso-string/**/*.js
mocha.js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ npm-debug.log*
.karma/
*.orig
.nyc_output/
coverage/
10 changes: 10 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"reporter": [
"json",
"text-summary"
],
"exclude": [
"lib/browser",
"test/**/*"
]
}
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -42,6 +42,8 @@ before_script: scripts/travis-before-script.sh

script: make $TARGET

after_success: "npm run postcoverage && <coverage/lcov.info ./node_modules/coveralls/bin/coveralls.js"

notifications:
urls:
# for gitter
Expand Down
47 changes: 28 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ BROWSERIFY := "node_modules/.bin/browserify"
ESLINT := "node_modules/.bin/eslint"
KARMA := "node_modules/.bin/karma"
MOCHA := "bin/mocha"
NYC := "node_modules/.bin/nyc"

ifdef COVERAGE
define test_node
$(NYC) --report-dir coverage/reports/$(1) $(MOCHA)
endef
else
test_node := $(MOCHA)
endif

TM_BUNDLE = JavaScript\ mocha.tmbundle
SRC = $(shell find lib -name "*.js" -type f | sort)
Expand Down Expand Up @@ -54,24 +63,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 \
Expand All @@ -80,22 +89,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:
Expand All @@ -104,49 +113,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:
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -318,12 +321,14 @@
"assert": "^1.4.1",
"browserify": "^13.0.0",
"coffee-script": "^1.10.0",
"coveralls": "^2.11.15",
"eslint": "^3.11.1",
"eslint-config-semistandard": "^7.0.0",
"eslint-config-standard": "^6.2.1",
"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",
Expand All @@ -332,6 +337,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",
Expand Down

0 comments on commit 24df20a

Please sign in to comment.