From 04fbc9dea2f1aad9bcd345b1ef7ec2a6b9b8d45e Mon Sep 17 00:00:00 2001 From: joakin Date: Fri, 3 Mar 2017 13:34:33 +0100 Subject: [PATCH] Add code coverage reports npm script Generate code coverage reports based on the node-qunit tests with istanbul. Changes: * Update README with npm run coverage * Add .istanbul.yml to configure istanbul * Add npm script "coverage" that runs istanbul and generates the reports Example report: http://popups-coverage.surge.sh/lcov-report/index.html Change-Id: I9be8c04b858a3ce6f4e29af2685b79253e3b4dca --- .gitignore | 1 + .istanbul.yml | 8 ++++++++ README.md | 2 ++ package.json | 6 ++++-- 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .istanbul.yml diff --git a/.gitignore b/.gitignore index 18eac7846..5345eb0de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /docs/ +/coverage/ /node_modules/ /vendor/ /composer.lock diff --git a/.istanbul.yml b/.istanbul.yml new file mode 100644 index 000000000..22c9c5f3e --- /dev/null +++ b/.istanbul.yml @@ -0,0 +1,8 @@ +instrumentation: + include-all-sources: true + excludes: [ + "resources/dist/*", # Compiled assets + "*.js", # Gruntfile.js and webpack.config.js + "src/processLinks.js", # Covered by browser QUnit integration test + "src/index.js", # Application entry point + ] diff --git a/README.md b/README.md index 0fb732a1f..ee8dbdca3 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,5 @@ After an `npm install`: * `npm install -g nodemon` * Example running linting and node unit tests: * `nodemon -w src/ --exec "grunt lint:all && npm run test:node"` + * Get code coverage report with `npm run coverage` + * Reports printed in the `coverage/` folder diff --git a/package.json b/package.json index 0c9c3c9b8..b1ae2c444 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "test": "grunt lint && npm run check-built-assets && npm run test:node", "doc": "jsduck", "check-built-assets": "echo 'CHECKING BUILD SOURCES ARE COMMITED' && rm -rf test-build && mv resources/dist test-build && npm run build && diff -x '*.map' -r test-build resources/dist && rm -rf test-build", - "test:node": "mw-node-qunit tests/node-qunit/*.js tests/node-qunit/**/*.js | tap-dot" + "test:node": "mw-node-qunit tests/node-qunit/*.js tests/node-qunit/**/*.js | tap-dot", + "coverage": "istanbul cover node_modules/.bin/mw-node-qunit tests/node-qunit/*.js tests/node-qunit/**/*.js" }, "devDependencies": { "eslint-config-wikimedia": "0.3.0", @@ -18,8 +19,9 @@ "grunt-eslint": "19.0.0", "grunt-jsonlint": "1.1.0", "grunt-stylelint": "^0.6.0", - "mw-node-qunit": "^1.0.6", + "istanbul": "^0.4.5", "mock-require": "^2.0.1", + "mw-node-qunit": "^1.0.6", "redux": "3.6.0", "redux-thunk": "2.2.0", "stylelint-config-wikimedia": "0.3.0",