Skip to content

Commit

Permalink
karma tests on all versions of react
Browse files Browse the repository at this point in the history
- rewrote src/version.js in ES5 to be able to use it in karma.conf.js
- conditionally add webpack.IgnorePlugin based on React version installed, mirrorring react-compat.js
  • Loading branch information
Nuno Campos committed Jun 10, 2016
1 parent de2ee64 commit 69532d0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ before_install:
- 'if [ "${TRAVIS_NODE_VERSION}" != "0.6" ] && [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then npm install -g npm; fi'
before_script:
- "sh install-relevant-react.sh"
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- if [ $KARMA == 1 ]; then export CHROME_BIN=chromium-browser; fi
- if [ $KARMA == 1 ]; then export DISPLAY=:99.0; fi
- if [ $KARMA == 1 ]; then sh -e /etc/init.d/xvfb start; fi
script:
- 'if [ -z "$REACT" ] && [ "${TRAVIS_NODE_VERSION}" = "4" ]; then npm run test:env -- "${EXAMPLE}" ; elif [ -z "$REACT" ]; then echo "Test Skipped" ; elif [ $KARMA == 1 ]; then npm run test:karma -- --single-run; elif [ "${TRAVIS_NODE_VERSION}" = "4" ]; then npm run lint && npm run travis ; elif [ "${TRAVIS_NODE_VERSION}" = "0.12" ]; then npm run travis ; else npm test ; fi'
after_script:
Expand Down
22 changes: 18 additions & 4 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
var webpack = require('webpack'); // eslint-disable-line no-var
/* eslint-disable no-var,prefer-arrow-callback */

var IgnorePlugin = require('webpack').IgnorePlugin;
var REACT013 = require('./src/version').REACT013;


module.exports = function karma(config) {
config.set({
Expand All @@ -21,6 +25,8 @@ module.exports = function karma(config) {

frameworks: ['mocha'],

reporters: ['dots'],

files: [
'test/*.js',
],
Expand Down Expand Up @@ -65,9 +71,17 @@ module.exports = function karma(config) {
],
},
plugins: [
new webpack.IgnorePlugin(/react\/lib\/ReactContext/),
new webpack.IgnorePlugin(/react\/lib\/ExecutionEnvironment/),
],
/*
this list of conditional IgnorePlugins mirrors the conditional
requires in src/react-compat.js and exists to avoid error
output from the webpack compilation
*/
!REACT013 && new IgnorePlugin(/react\/lib\/ExecutionEnvironment/),
!REACT013 && new IgnorePlugin(/react\/lib\/ReactContext/),
!REACT013 && new IgnorePlugin(/react\/addons/),
REACT013 && new IgnorePlugin(/react-dom/),
REACT013 && new IgnorePlugin(/react-addons-test-utils/),
].filter(function filterPlugins(plugin) { return plugin !== false; }),
},

webpackServer: {
Expand Down
17 changes: 12 additions & 5 deletions src/version.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import React from 'react';
export const VERSION = React.version;
export const REACT013 = VERSION.slice(0, 4) === '0.13';
export const REACT014 = VERSION.slice(0, 4) === '0.14';
export const REACT15 = VERSION.slice(0, 3) === '15.';
/* eslint-disable no-var,object-shorthand */

var React = require('react');

var VERSION = React.version;

module.exports = {
VERSION: VERSION,
REACT013: VERSION.slice(0, 4) === '0.13',
REACT014: VERSION.slice(0, 4) === '0.14',
REACT15: VERSION.slice(0, 3) === '15.',
};

0 comments on commit 69532d0

Please sign in to comment.