Skip to content

Commit f9c5383

Browse files
committed
Added back karma for unit testing, adjusted webpack config accordingly
1 parent bff1648 commit f9c5383

File tree

20 files changed

+214
-124
lines changed

20 files changed

+214
-124
lines changed

.eslintrc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
"strict": 0,
1414
"no-unused-expressions": 0,
1515
"no-underscore-dangle": [ "error", { "allowAfterThis": true }],
16-
"import/no-unresolved": [ "error", "ignore": [ 'config' ] ]
16+
"import/no-unresolved": [ "error", "ignore": [
17+
'config',
18+
'components/',
19+
'stores/',
20+
'actions/',
21+
'sources/',
22+
'styles/',
23+
'images/'
24+
]]
1725
}
1826
}

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generator-React-Webpack 2.0 (alpha)
1+
# React Webpack Template 2.0 (alpha)
22
> A flexible, easy to use boilerplate to quickly get started with Webpack, Babel and React.
33
44
[![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")
@@ -9,11 +9,12 @@ You may use this template either directly (by cloning this git repository) or by
99
## Features
1010
The following features are currently included out of the box:
1111

12-
- [x] Webpack 2 setup to get you started (including support for LESS/SASS/SCSS/Stylus and PostCSS)
12+
- [x] Webpack 2 setup to get you started (including basic support for LESS/SASS/SCSS/Stylus and PostCSS)
13+
- [ ] CSS Modules support
1314
- [x] Babel 6 to transpile ES2015 and JSX
14-
- [x] React 15.0
15-
- [x] Mocha, Chai and Enzyme for easy unit testing (without karma)
16-
- [x] Istanbul and Isparta for collecting coverage information
15+
- [x] Latest stable React Version (v15.0)
16+
- [x] Karma, Mocha, Chai and Enzyme for easier unit testing
17+
- [x] Isparta to collect coverage information
1718
- [x] Preconfigured .editorconfig file
1819
- [x] Preconfigured eslint configuration, based on airbnb
1920

@@ -23,13 +24,13 @@ The following features are currently included out of the box:
2324
FOLLOWS
2425

2526
- I want to use less/sass/whatever, but get an error when requiring the file:
26-
We currently do not ship the needed modules. This is done on purpose, as we dont want you to install too much dependencies. If you do not use a css precompiler, chance is you wont even notice it. If you need one, just install the required webpack loader (e.g. for less via ```npm install --save-dev less-loader```).
27+
We currently do not ship the needed webpack modules. This is done on purpose, as we dont want you to install too much dependencies without using them. If you do not use a css precompiler, chance is you wont even notice it. If you need one, just install the required webpack loader (e.g. for less via ```npm install --save-dev less-loader```).
2728

2829
- I want to change/add/remove one of the given configs for webpack:
2930
The webpack configuration is located in ```conf/webpack```. All changes in Base.js will get delegated to all webpack configurations, so you will just have to update this file for adding loaders etc. You may add your own configurations at any time. Just make sure to extend ```WebpackBaseConfig``` to make it work. When ready, just update ```conf/webpack/index.js``` with your wanted options to make them work.
3031

31-
- Where do I find configuration options for *insert tool of choise here*:
32-
Every configuration options are located either directly in the project root (as for .babelrc, base webpack...) or as a folder in the conf directory.
32+
- Where do I find configuration options for *insert tool of choice here*:
33+
Configuration options are located either directly in the project root (as for .babelrc, webpack.config.js, karma.conf.js...) or as a folder in the conf/ directory.
3334

3435
## Using it
3536
The template uses webpack as build tool to serve files and run tests. The following commands are available:

conf/mocha/chai.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

conf/mocha/fakedom.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

conf/mocha/webpackexclude.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

conf/webpack/Base.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,31 @@ class WebpackBaseConfig {
4646
return path.resolve('./src');
4747
}
4848

49+
/**
50+
* Get the absolute path to tests directory
51+
* @return {String}
52+
*/
53+
get testPathAbsolute() {
54+
return path.resolve('./test');
55+
}
56+
4957
/**
5058
* Get the default settings
5159
* @return {Object}
5260
*/
5361
get defaultSettings() {
5462
return {
63+
cache: true,
5564
context: this.srcPathAbsolute,
5665
debug: false,
5766
devtool: 'eval',
5867
devServer: {
5968
contentBase: './src/',
6069
publicPath: '/assets/',
61-
historyApiFallback: true
70+
historyApiFallback: true,
71+
hot: true,
72+
inline: true,
73+
port: 8080
6274
},
6375
entry: './index.js',
6476
module: {
@@ -99,7 +111,7 @@ class WebpackBaseConfig {
99111
include: [
100112
this.srcPathAbsolute
101113
],
102-
loaders: ['babel']
114+
loaders: ['react-hot', 'babel']
103115
}
104116
]
105117
},

conf/webpack/Dev.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
'use strict';
55

6+
const webpack = require('webpack');
67
const WebpackBaseConfig = require('./Base');
78

89
class WebpackDevConfig extends WebpackBaseConfig {
@@ -11,6 +12,15 @@ class WebpackDevConfig extends WebpackBaseConfig {
1112
super();
1213
this.config = {
1314
devtool: 'cheap-module-source-map',
15+
entry: [
16+
'webpack-dev-server/client?http://0.0.0.0:8080/',
17+
'webpack/hot/only-dev-server',
18+
'./index.js'
19+
],
20+
plugins: [
21+
new webpack.HotModuleReplacementPlugin(),
22+
new webpack.NoErrorsPlugin()
23+
]
1424
};
1525
}
1626
}

conf/webpack/Dist.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class WebpackDistConfig extends WebpackBaseConfig {
1818
'process.env.NODE_ENV': '"production"'
1919
}),
2020
new webpack.optimize.DedupePlugin(),
21-
new webpack.optimize.AggressiveMergingPlugin()
21+
new webpack.optimize.AggressiveMergingPlugin(),
22+
new webpack.NoErrorsPlugin()
2223
]
2324
};
2425
}

conf/webpack/Test.js

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,45 @@ class WebpackTestConfig extends WebpackBaseConfig {
1010
constructor() {
1111
super();
1212
this.config = {
13+
devtool: 'inline-source-map',
1314
externals: {
1415
cheerio: 'window',
1516
'react/lib/ExecutionEnvironment': true,
17+
'react/addons': true,
1618
'react/lib/ReactContext': true,
1719
},
18-
module: [
19-
{
20-
test: /\.(css|less|sass|scss|png|jpg|gif|mp4|ogg|svg|woff|woff2)$/,
21-
loader: 'null'
22-
},
23-
{
24-
test: /\.(js|jsx)$/,
25-
exclude: /(node_modules|bower_components)/,
26-
loader: 'babel',
27-
query: {
28-
presets: ['react', 'es2015', 'stage-0'],
20+
module: {
21+
preLoaders: [
22+
{
23+
test: /\.(js|jsx)$/,
24+
loader: 'isparta-instrumenter-loader',
25+
include: [
26+
this.srcPathAbsolute
27+
]
2928
}
30-
}
31-
],
29+
],
30+
loaders: [
31+
{
32+
test: /\.(png|jpg|gif|woff|woff2|css|sass|scss|less|styl|mp4|ogg|svg)$/,
33+
loader: 'null-loader'
34+
},
35+
{
36+
test: /\.json$/,
37+
loader: 'json'
38+
},
39+
{
40+
test: /\.(js|jsx)$/,
41+
loader: 'babel-loader',
42+
query: {
43+
presets: ['airbnb']
44+
},
45+
include: [
46+
this.srcPathAbsolute,
47+
this.testPathAbsolute
48+
]
49+
}
50+
]
51+
},
3252
plugins: [
3353
new webpack.DefinePlugin({
3454
'process.env.NODE_ENV': '"test"'
@@ -37,6 +57,29 @@ class WebpackTestConfig extends WebpackBaseConfig {
3757
};
3858
}
3959

60+
/**
61+
* Set the config data.
62+
* Will remove the devServer config value as we do not need it in test environments
63+
* This function will always return a new config
64+
* @param {Object} data Keys to assign
65+
* @return {Object}
66+
*/
67+
set config(data) {
68+
69+
const baseSettings = this.defaultSettings;
70+
delete baseSettings.devServer;
71+
this._config = Object.assign({}, baseSettings, data);
72+
return this._config;
73+
}
74+
75+
/**
76+
* Get the global config
77+
* @param {Object} config Final webpack config
78+
*/
79+
get config() {
80+
return super.config;
81+
}
82+
4083
/**
4184
* Get the environment name
4285
* @return {String} The current environment

karma.conf.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'use strict';
2+
const webpackCfg = require('./webpack.config')('test');
3+
4+
module.exports = function karmaConfig(config) {
5+
6+
config.set({
7+
browsers: ['PhantomJS'],
8+
files: [
9+
'test/loadtests.js'
10+
],
11+
port: 8080,
12+
captureTimeout: 60000,
13+
frameworks: [
14+
'mocha',
15+
'chai',
16+
'sinon'
17+
],
18+
client: {
19+
mocha: {}
20+
},
21+
singleRun: true,
22+
reporters: ['mocha', 'coverage', 'junit'],
23+
mochaReporter: {
24+
output: 'autowatch'
25+
},
26+
preprocessors: {
27+
'test/loadtests.js': ['webpack', 'sourcemap']
28+
},
29+
webpack: webpackCfg,
30+
webpackServer: {
31+
noInfo: true
32+
},
33+
junitReporter: {
34+
outputDir: 'coverage',
35+
outputFile: 'junit-result.xml',
36+
useBrowserName: false
37+
},
38+
coverageReporter: {
39+
dir: 'coverage/',
40+
watermarks: {
41+
statements: [70, 80],
42+
functions: [70, 80],
43+
branches: [70, 80],
44+
lines: [70, 80]
45+
},
46+
reporters: [
47+
{ type: 'text' },
48+
{
49+
type: 'html',
50+
subdir: 'html'
51+
},
52+
{
53+
type: 'cobertura',
54+
subdir: 'cobertura'
55+
},
56+
{
57+
type: 'lcovonly',
58+
subdir: 'lcov'
59+
}
60+
]
61+
}
62+
});
63+
};

0 commit comments

Comments
 (0)