From 79a4e3bf44b2902e49dd1a60a31b85b26743a6b3 Mon Sep 17 00:00:00 2001 From: Jesse Buchanan Date: Tue, 12 Apr 2016 20:23:37 -0400 Subject: [PATCH] Add test coverage with istanbul ... * Add npm script `cover`, which calls istanbul: * Do not execute `istanbul` via `babel-node`, this is deprecated, instead use `babel-register` as an argument to `mocha` (credit: https://github.com/gotwarlost/istanbul/issues/594#issuecomment-208693131) * Use `--root src/` to fix issue where istanbul also attempts to cover `mocha` (credit: https://github.com/douglasduteil/isparta/issues/68#issuecomment-191752598) * Use `--include-all-sources` to make the coverage percentages actually meaningful by including sources that didn't get executed * In `src/higher_order_components/errors_normalizer.js`, make minor change to return statement. This form: `if (foo) return { a: 'b' }` seems to have confused Istanbul's coverage highlighter. There are other cases like this, that are bugs in Istanbul (e.g. https://github.com/gotwarlost/istanbul/issues/557). Probably worth making a repro case for this and reporting to them. --- .gitignore | 2 ++ package.json | 5 ++++- src/higher_order_components/errors_normalizer.js | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index e0ebdad..81f72ff 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ bower_components npm-debug.log .DS_Store + +coverage diff --git a/package.json b/package.json index 0ed42a1..fd377f2 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "test:watch": "npm run test -- --watch --watch-extensions js", "lint": "eslint src/ test/ || true", "lint:failfast": "eslint src/ test/", + "cover": "istanbul cover --root src/ --include-all-sources --report lcov --report json --report text --report html _mocha -- -r babel-register -r test/test_helper.js 'test/**/*.test.js'", "preversion": "./scripts/preversion.sh", "version": "./scripts/version.sh", "postversion": "./scripts/publish_docs.sh && git push && git push --tags" @@ -28,6 +29,7 @@ "babel-preset-es2015": "6.6.0", "babel-preset-react": "6.5.0", "babel-preset-stage-1": "6.5.0", + "babel-register": "^6.7.2", "chai": "3.5.0", "chai-enzyme": "^0.4.1", "dirty-chai": "^1.2.2", @@ -37,13 +39,14 @@ "eslint-plugin-react": "4.2.3", "extract-text-webpack-plugin": "1.0.1", "fs-extra": "0.26.7", + "istanbul": "^1.0.0-alpha.2", "jsdom": "8.2.0", "jsx-loader": "0.13.2", "mkpath": "1.0.0", "mocha": "2.4.5", "react": ">=0.14.3", - "react-dom": ">=0.14.3", "react-addons-test-utils": "^0.14.8", + "react-dom": ">=0.14.3", "webpack": "1.12.14", "webpack-dev-server": "1.14.1" }, diff --git a/src/higher_order_components/errors_normalizer.js b/src/higher_order_components/errors_normalizer.js index 174fd06..cedd20a 100644 --- a/src/higher_order_components/errors_normalizer.js +++ b/src/higher_order_components/errors_normalizer.js @@ -18,7 +18,9 @@ export default class ErrorNormalizer extends React.Component { // If errors is an array then convert it into an object. 'base' is // used to store all top-level errors that are not specific to an // input. - if (isArray) return { base: errors } + if (isArray) { + return { base: errors } + } return errors }