Added support for coverage reporting (as requested in https://github.com/newtriks/generator-react-webpack/issues/158)

This commit is contained in:
Chris
2015-10-27 08:08:26 +01:00
parent ed4e8a17f3
commit 89f6f1701b
5 changed files with 51 additions and 9 deletions
+28 -3
View File
@@ -1,6 +1,6 @@
# Welcome to react-webpack-template
> This repository holds a base template for the new version of generator-react-webpack.
It can be understood as the prototype for newly generated projects.
> This repository holds the base template for the current version of [generator-react-webpack](https://github.com/newtriks/generator-react-webpack).
It can also be used as the prototype for newly generated projects.
[![Build Status](https://travis-ci.org/weblogixx/react-webpack-template.svg)](https://travis-ci.org/weblogixx/react-webpack-template) ![Amount of Downloads per month](https://img.shields.io/npm/dm/react-webpack-template.svg "Amount of Downloads") ![Dependency Tracker](https://img.shields.io/david/weblogixx/react-webpack-template.svg "Dependency Tracker") ![Dependency Tracker](https://img.shields.io/david/dev/weblogixx/react-webpack-template.svg "Dependency Tracker")
@@ -10,9 +10,10 @@ The following features are currently included:
- [x] Webpack and Webpack-Dev-Server, including hot-loader
- [x] Babel and JSX
- [x] Mocha Unit tests (*optional*)
- [x] EsLint Support
- [x] esLint Support
- [x] No dependency on grunt, gulp or the next hot taskrunner!
- [x] Support for environment-specific configuration files
- [x] Support for code coverage via [isparta-loader](https://github.com/deepsweet/isparta-loader)
## Todo
- [ ] Better performance for webpack builds
@@ -64,6 +65,30 @@ webpack-dev-server --env=dev
webpack --env=dist
webpack-dev-server --env=dist
```
## A note on unit testing
When running tests, coverage information (provided via Istanbul) will also be written into the ```coverage/``` directory. If you do not need this, just comment out or remove the section in ```karma.conf``` like this:
```javascript
/* do not use coverage reporting!
coverageReporter: {
type: 'html',
dir: 'coverage/'
}*/
```
Also, you should adjust your webpack test configuration (located in ```cfg/test.js```) to reflect this:
```javascript
/* Uncomment this to prevent loading via isparta
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
include: [
path.join(__dirname, '/../src')
],
loader: 'isparta'
}*/
```
## License
react-webpack-template is available under MIT-License and can therefore be used in any project free of charge.
+9 -1
View File
@@ -16,11 +16,19 @@ module.exports = {
path.join(__dirname, '/../src'),
path.join(__dirname, '/../test')
]
},
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
include: [
path.join(__dirname, '/../src')
],
loader: 'isparta'
}
]
},
resolve: {
extensions: ['', '.js', '.jsx'],
extensions: [ '', '.js', '.jsx' ],
alias: {
actions: srcPath + 'actions/',
helpers: path.join(__dirname, '/../test/helpers'),
+8 -4
View File
@@ -3,24 +3,28 @@ var webpackCfg = require('./webpack.config');
module.exports = function(config) {
config.set({
basePath: '',
browsers: ['PhantomJS'],
browsers: [ 'PhantomJS' ],
files: [
'test/loadtests.js'
],
port: 8080,
captureTimeout: 60000,
frameworks: ['phantomjs-shim', 'mocha', 'chai'],
frameworks: [ 'phantomjs-shim', 'mocha', 'chai' ],
client: {
mocha: {}
},
singleRun: true,
reporters: ['mocha'],
reporters: [ 'mocha', 'coverage' ],
preprocessors: {
'test/loadtests.js': ['webpack', 'sourcemap']
'test/loadtests.js': [ 'webpack', 'sourcemap' ]
},
webpack: webpackCfg,
webpackServer: {
noInfo: true
},
coverageReporter: {
type: 'html',
dir: 'coverage/'
}
});
};
+2
View File
@@ -46,8 +46,10 @@
"eslint-plugin-react": "^3.3.0",
"file-loader": "^0.8.4",
"glob": "^5.0.15",
"isparta-loader": "^1.0.0",
"karma": "^0.13.9",
"karma-chai": "^0.1.0",
"karma-coverage": "^0.5.3",
"karma-mocha": "^0.2.0",
"karma-mocha-reporter": "^1.1.1",
"karma-phantomjs-launcher": "^0.2.1",
+4 -1
View File
@@ -1,2 +1,5 @@
var testsContext = require.context('.', true, /(Test\.js$)|(Helper\.js$)/);
'use strict';
// Add support for all files in the test directory
const testsContext = require.context('.', true, /(Test\.js$)|(Helper\.js$)/);
testsContext.keys().forEach(testsContext);