Skip to content

Commit

Permalink
setup working karma jasmine enzyme test toolchain for our react app
Browse files Browse the repository at this point in the history
  • Loading branch information
nma committed Sep 1, 2017
1 parent 4d4db4d commit 8d443c0
Show file tree
Hide file tree
Showing 12 changed files with 968 additions and 938 deletions.
2 changes: 1 addition & 1 deletion client/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": ["es2015", "stage-2", "react"],
"presets": ["flow", "es2015", "stage-2", "react"],
"env": {
"test": {
"plugins": ["transform-es2015-modules-commonjs"]
Expand Down
9 changes: 9 additions & 0 deletions client/.flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[ignore]

[include]

[libs]

[lints]

[options]
13 changes: 2 additions & 11 deletions client/app/bundles/HelloWorld/components/Chart.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import React from 'react';
import { AreaChart } from 'react-chartkick';
import "chartjs";
import 'chartjs';

// const request = require('superagent');

Expand All @@ -24,18 +24,9 @@ export default class Chart extends React.Component {
}

componentDidMount() {
console.log('COMPONENT DID MOUNT');
// request
// .get('/moments/analytics')
// .end(function(err, res){
// if (err === null && res) {
// console.log('it works!')
// this.setState({ data: res })
// }
// });

}


updateName = (name) => {
this.setState({ name });
};
Expand Down
46 changes: 0 additions & 46 deletions client/app/bundles/HelloWorld/components/HelloWorld.jsx

This file was deleted.

52 changes: 0 additions & 52 deletions client/app/bundles/HelloWorld/components/__test__/Chart.test.jsx

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 11 additions & 0 deletions client/app/bundles/HelloWorld/components/__tests__/Chart.spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import Chart from '../Chart';
import { render } from 'enzyme';

describe('Chart', () => {
it("renders a Chart", () => {
expect(() => {
render(<Chart />);
}).not.toThrow();
});
});
4 changes: 1 addition & 3 deletions client/app/bundles/HelloWorld/startup/registration.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import ReactOnRails from 'react-on-rails';

import HelloWorld from '../components/HelloWorld';
import Chart from '../components/Chart';

// This is how react_on_rails can see the HelloWorld in the browser.
ReactOnRails.register({
HelloWorld,
Chart
Chart,
});
38 changes: 38 additions & 0 deletions client/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// karma.conf.js
var webpackConfig = require('./webpack.config');
const webpack = require('webpack');

webpackConfig.plugins = [
new webpack.EnvironmentPlugin({
NODE_ENV: 'development', // use 'development' unless process.env.NODE_ENV is defined
DEBUG: false,
}),
];
webpackConfig.devtool = 'eval-source-map';

// https://github.com/airbnb/enzyme/blob/master/docs/guides/webpack.md#react-15-compatibility
webpackConfig.externals = {
'react/addons': true,
'react/lib/ExecutionEnvironment': true,
'react/lib/ReactContext': true,
'react-addons-test-utils': 'react-dom',
};

module.exports = function (config) {
config.set({
browsers: ['PhantomJS'],
singleRun: true,
frameworks: ['jasmine'],
files: [
{ pattern: 'app/**/*.spec.jsx', watched: true },
],
preprocessors: {
'app/**/*.jsx': ['webpack', 'sourcemap']
},
reporters: ['dots'],
webpack: webpackConfig,
webpackServer: {
noInfo: true
}
});
};
15 changes: 13 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "ifme",
"private": true,
"scripts": {
"test": "jest",
"test": "karma start",
"test:watch": "karma start --no-single-run",
"build:test": "NODE_ENV=test webpack --config webpack.config.js",
"build:production": "NODE_ENV=production webpack --config webpack.config.js",
"build:development": "NODE_ENV=development webpack -w --config webpack.config.js"
Expand Down Expand Up @@ -31,13 +32,23 @@
"react-chartkick": "^0.1.3",
"react-dom": "^15.5.4",
"react-on-rails": "8.0.0",
"redux": "^3.7.2",
"superagent": "^3.5.2",
"webpack": "^2.3.3",
"webpack-manifest-plugin": "^1.1.0"
},
"devDependencies": {
"babel-preset-flow": "^6.23.0",
"enzyme": "^2.9.1",
"jest": "^20.0.4",
"flow-bin": "^0.52.0",
"jasmine": "^2.7.0",
"jasmine-enzyme": "^3.7.0",
"karma": "^1.7.0",
"karma-jasmine": "^1.1.0",
"karma-phantomjs-launcher": "^1.0.4",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.4",
"react-addons-test-utils": "^15.6.0",
"react-test-render": "^1.0.3",
"react-test-renderer": "^15.6.1",
"superagent-mock": "^3.5.0"
Expand Down
Loading

0 comments on commit 8d443c0

Please sign in to comment.