Skip to content
This repository was archived by the owner on Apr 11, 2019. It is now read-only.

Commit 8c99fc0

Browse files
authored
Merge pull request #20 from RyanCCollins/fix_rc_fix_testing
Fix rc fix testing
2 parents 17bb5c2 + c525923 commit 8c99fc0

File tree

8 files changed

+124
-98
lines changed

8 files changed

+124
-98
lines changed

app/src/containers/FeatureFirstContainer/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { connect } from 'react-redux';
1111
import { bindActionCreators } from 'redux';
1212
import * as MyActions from './actions';
1313

14-
class FeatureFirstContainer extends Component {
14+
export class FeatureFirstContainer extends Component {
1515
constructor(props) {
1616
super(props);
1717
this.initiateLoading = this.initiateLoading.bind(this);
@@ -36,7 +36,7 @@ class FeatureFirstContainer extends Component {
3636
:
3737
<div>
3838
<LogoImage
39-
imageSource="https://github.com/RyanCCollins/cdn/raw/master/alumni-webapp/udacity-alumni-small.png?raw=true"
39+
imageSource="https://github.com/RyanCCollins/cdn/raw/master/alumni-webapp/udacity-alumni-small.png?raw=true"
4040
/>
4141
<div className={styles.headerText}>
4242
<Header
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { FeatureFirstContainer } from '../index';
2+
import expect from 'expect';
3+
import React from 'react';
4+
import { shallow } from 'enzyme';
5+
6+
function setup() {
7+
const props = {
8+
isLoading: true,
9+
};
10+
const wrapper = shallow(
11+
<FeatureFirstContainer isLoading={props.isLoading} />
12+
);
13+
return {
14+
props,
15+
wrapper,
16+
};
17+
}
18+
describe('<FeatureFirstContainer />', () => {
19+
it('should show a loading indicator while loading', () => {
20+
const {
21+
wrapper,
22+
} = setup();
23+
expect(
24+
wrapper.contains(
25+
<h1>LOADING...</h1>
26+
)
27+
).toBe(true);
28+
});
29+
});

config/testing/karma.conf.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
const webpackConfig = require('../../config/webpack/webpack.test.config');
1+
const webpackConfig = require('../webpack/webpack.test.babel');
22
const argv = require('minimist')(process.argv.slice(2));
33
const path = require('path');
44

5-
// From React Boilerplate
6-
// See here: https://github.com/mxstbr/react-boilerplate/blob/master/internals/webpack/webpack.test.babel.js
75
module.exports = (config) => {
86
config.set({
97
frameworks: ['mocha'],
108
reporters: ['coverage', 'mocha'],
11-
browsers: ['Chrome'],
9+
browsers: process.env.TRAVIS // eslint-disable-line no-nested-ternary
10+
? ['ChromeTravis']
11+
: process.env.APPVEYOR
12+
? ['IE'] : ['Chrome'],
1213

1314
autoWatch: false,
1415
singleRun: true,
@@ -21,15 +22,18 @@ module.exports = (config) => {
2122

2223
files: [
2324
{
24-
pattern: './test_helper.js',
25+
pattern: './test-bundler.js',
2526
watched: false,
2627
served: true,
2728
included: true,
2829
},
2930
],
3031

3132
preprocessors: {
32-
['./test_helper.js']: ['webpack', 'sourcemap'], // eslint-disable-line no-useless-computed-key
33+
['./test-bundler.js']: [
34+
'webpack',
35+
'sourcemap',
36+
],
3337
},
3438

3539
webpack: webpackConfig,
@@ -55,6 +59,6 @@ module.exports = (config) => {
5559
{ type: 'text-summary' },
5660
],
5761
},
58-
62+
failOnEmptyTestSuite: false,
5963
});
6064
};

config/testing/test-bundler.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// needed for regenerator-runtime
2+
// (ES7 generator support is required by redux-saga)
3+
import 'babel-polyfill';
4+
5+
// If we need to use Chai, we'll have already chaiEnzyme loaded
6+
import chai from 'chai';
7+
import chaiEnzyme from 'chai-enzyme';
8+
import chaiJsx from 'chai-jsx';
9+
10+
chai.use(chaiEnzyme());
11+
chai.use(chaiJsx);
12+
13+
// Include all .js files under `app`, except app.js, reducers.js, and routes.js.
14+
// This is for isparta code coverage
15+
const context = require.context(
16+
'../../app/src',
17+
true,
18+
/([^\a]+).test\.js$/
19+
);
20+
context.keys().forEach(context);

config/testing/test_helper.js

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

config/webpack/webpack.test.babel.js

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
2+
/**
3+
* TEST WEBPACK CONFIGURATION
4+
*/
5+
16
const path = require('path');
27
const webpack = require('webpack');
3-
const ROOT_PATH = path.resolve(__dirname);
4-
const HtmlwebpackPlugin = require('html-webpack-plugin');
5-
68
const modules = [
79
'app/src',
810
'node_modules',
911
];
1012

13+
const ROOT_PATH = path.resolve(__dirname);
14+
1115
module.exports = {
1216
devtool: 'inline-source-map',
1317
isparta: {
@@ -16,44 +20,82 @@ module.exports = {
1620
},
1721
},
1822
module: {
23+
// Some libraries don't like being run through babel.
24+
// If they gripe, put them here.
1925
noParse: [
20-
// If libraries complain about babel, put them here.
26+
/node_modules(\\|\/)sinon/,
27+
/node_modules(\\|\/)acorn/,
2128
],
2229
preLoaders: [
23-
{
24-
test: /\.js$/,
30+
{ test: /\.js$/,
2531
loader: 'isparta',
2632
include: path.resolve('app/src'),
2733
},
2834
],
2935
loaders: [
3036
{ test: /\.json$/, loader: 'json-loader' },
31-
{ test: /\.scss$/, loader: 'null-loader' },
32-
{ test: /\.js$/, loader: 'babel', exclude: [/node_modules/] },
33-
{ test: /\.jpe?g$|\.gif$|\.png$/i, loader: 'null-loader' },
37+
{ test: /\.css$/, loader: 'null-loader' },
38+
{
39+
test: /\.module\.scss$/,
40+
loader: 'null-loader',
41+
},
42+
{
43+
test: /\.scss$/,
44+
exclude: /\.module\.scss$/,
45+
loader: 'null-loader',
46+
},
47+
48+
// sinon.js--aliased for enzyme--expects/requires global vars.
49+
// imports-loader allows for global vars to be injected into the module.
50+
// See https://github.com/webpack/webpack/issues/304
51+
{ test: /sinon(\\|\/)pkg(\\|\/)sinon\.js/,
52+
loader: 'imports?define=>false,require=>false',
53+
},
54+
{ test: /\.js$/,
55+
loader: 'babel',
56+
exclude: [/node_modules/],
57+
},
58+
{ test: /\.jpe?g$|\.gif$|\.png$|\.svg$/i,
59+
loader: 'null-loader',
60+
},
3461
],
3562
},
63+
3664
plugins: [
37-
new HtmlwebpackPlugin({
38-
title: 'Scalable React Boilerplate',
39-
template: 'index.html',
40-
}),
65+
66+
// Always expose NODE_ENV to webpack, in order to use `process.env.NODE_ENV`
67+
// inside your code for any environment checks; UglifyJS will automatically
68+
// drop any unreachable code.
4169
new webpack.DefinePlugin({
4270
'process.env': {
4371
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
4472
},
45-
}),
46-
],
73+
})],
74+
75+
// Some node_modules pull in Node-specific dependencies.
76+
// Since we're running in a browser we have to stub them out. See:
77+
// https://webpack.github.io/docs/configuration.html#node
78+
// https://github.com/webpack/node-libs-browser/tree/master/mock
79+
// https://github.com/webpack/jade-loader/issues/8#issuecomment-55568520
80+
node: {
81+
fs: 'empty',
82+
child_process: 'empty',
83+
net: 'empty',
84+
tls: 'empty',
85+
},
86+
87+
// required for enzyme to work properly
4788
externals: {
4889
jsdom: 'window',
4990
'react/addons': true,
5091
'react/lib/ExecutionEnvironment': true,
5192
'react/lib/ReactContext': 'window',
5293
},
5394
resolve: {
54-
modulesDirectoris: modules,
95+
modulesDirectories: modules,
5596
modules,
5697
alias: {
98+
// required for enzyme to work properly
5799
sinon: 'sinon/pkg/sinon',
58100
components: path.resolve(ROOT_PATH, '../../app/src/components'),
59101
containers: path.resolve(ROOT_PATH, '../../app/src/containers'),

config/webpack/webpack.test.config.js

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

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
"deploy": "NODE_ENV=production `npm bin`/webpack -p",
2929
"start": "npm run dev",
3030
"clean": "rm -rf app/dist app/build",
31-
"setup": "npm install"
31+
"setup": "npm install",
32+
"devtest": "webpack-dev-server --config ./config/webpack/webpack.test.babel.js",
33+
"test2": "NODE_ENV=test mocha --compilers js:babel-core/register --require config/testing/test-bundler \"./app/src/**/*.test.js\""
3234
},
3335
"repository": {
3436
"type": "git",
@@ -121,6 +123,7 @@
121123
"react-css-modules": "^3.7.6",
122124
"react-hot-loader": "^1.3.0",
123125
"redux-devtools": "^3.0.1",
126+
"redux-mock-store": "^1.1.4",
124127
"webpack-dev-server": "^1.14.0",
125128
"webpack-visualizer-plugin": "^0.1.5"
126129
}

0 commit comments

Comments
 (0)