From 96bc6173d9e46cefec5c1dbc20c799352019f53f Mon Sep 17 00:00:00 2001 From: Jaden Diefenbaugh <jaden.diefenbaugh@idiap.ch> Date: Fri, 20 Oct 2017 16:51:24 +0200 Subject: [PATCH] fixed testing! instrumentation only shows for files in src/ for some reason --- karma.conf.js | 4 ++-- src/main.jsx => main.jsx | 8 ++++---- {test => src}/Foo.jsx | 4 ++++ test/index.js | 4 ++++ test/test.spec.jsx | 7 ++----- webpack.config.js | 2 +- 6 files changed, 17 insertions(+), 12 deletions(-) rename src/main.jsx => main.jsx (76%) rename {test => src}/Foo.jsx (86%) diff --git a/karma.conf.js b/karma.conf.js index 89d0059d..22a1e599 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -20,11 +20,11 @@ module.exports = function (config) { frameworks: ['mocha'], // this is the entry file for all our tests. files: [ - './test/index.js' + './test/index.js', ], // we will pass the entry file to webpack for bundling. preprocessors: { - './test/index.js': [ 'webpack', 'sourcemap' ], + '**/*': [ 'webpack', 'sourcemap' ], }, reporters: [ 'mocha', diff --git a/src/main.jsx b/main.jsx similarity index 76% rename from src/main.jsx rename to main.jsx index 3c443607..bdea091b 100644 --- a/src/main.jsx +++ b/main.jsx @@ -6,8 +6,8 @@ import React from 'react'; import ReactDOM from 'react-dom'; import { Provider } from 'react-redux'; import { AppContainer } from 'react-hot-loader'; -import App from './components/App.jsx'; -import store from './store'; +import App from './src/components/App.jsx'; +import store from '@store'; ReactDOM.render( <AppContainer> @@ -20,8 +20,8 @@ ReactDOM.render( // Hot Module Replacement API if (module.hot) { - module.hot.accept('./components/App', () => { - const NextApp = require('./components/App').default; + module.hot.accept('./src/components/App', () => { + const NextApp = require('./src/components/App').default; ReactDOM.render( <AppContainer> <Provider store={ store }> diff --git a/test/Foo.jsx b/src/Foo.jsx similarity index 86% rename from test/Foo.jsx rename to src/Foo.jsx index 4670849e..27fcec35 100644 --- a/test/Foo.jsx +++ b/src/Foo.jsx @@ -21,6 +21,10 @@ class Foo extends React.Component<FooProps, FooState> { ); } + isntCovered = () => { + console.log(`mauahahahahah`); + } + componentDidMount(){} } diff --git a/test/index.js b/test/index.js index 28167f0c..d532d048 100644 --- a/test/index.js +++ b/test/index.js @@ -1,3 +1,7 @@ +import { configure } from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; +configure({ adapter: new Adapter() }); + // require all test files using special Webpack feature // https://webpack.js.org/guides/dependency-management/#require-context const testsContext = require.context('.', true, /\.spec.js(x)?$/); diff --git a/test/test.spec.jsx b/test/test.spec.jsx index 0e0d6afd..baf72eae 100644 --- a/test/test.spec.jsx +++ b/test/test.spec.jsx @@ -1,12 +1,9 @@ // @flow import React from 'react'; import { expect } from 'chai'; -import { configure, mount } from 'enzyme'; -import Adapter from 'enzyme-adapter-react-16'; +import { mount } from 'enzyme'; import sinon from 'sinon'; -import Foo from './Foo.jsx'; - -configure({ adapter: new Adapter() }); +import Foo from '../src/Foo.jsx'; describe('<Foo />', () => { it('calls componentDidMount', () => { diff --git a/webpack.config.js b/webpack.config.js index a8193fa2..cd4d61f5 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -14,7 +14,7 @@ module.exports = { main: [ 'react-hot-loader/patch', // all our code starts here - './src/main.jsx', + './main.jsx', ] }, -- GitLab