diff --git a/README.md b/README.md index 0fb67e7..4952965 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/cfg/test.js b/cfg/test.js index f2e3e4e..1ec90fd 100644 --- a/cfg/test.js +++ b/cfg/test.js @@ -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'), diff --git a/karma.conf.js b/karma.conf.js index 65b452a..f9ba063 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -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/' } }); }; diff --git a/package.json b/package.json index f425ab1..aa73d23 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/loadtests.js b/test/loadtests.js index a3fbd63..68f8af6 100644 --- a/test/loadtests.js +++ b/test/loadtests.js @@ -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);