Skip to content

Commit

Permalink
migrate karma webpack usage.
Browse files Browse the repository at this point in the history
use webpack alias for enzyme adapter instead of template string
  • Loading branch information
Gilad Gray committed Jan 7, 2019
1 parent 2eab81a commit 5a067da
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
10 changes: 2 additions & 8 deletions packages/karma-build-scripts/createKarmaConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = function createKarmaConfig(
},
port: KARMA_SERVER_PORT,
preprocessors: {
[path.join(dirname, "test/**/*.ts")]: "sourcemap",
[path.join(dirname, "test/**/*.ts")]: ["sourcemap"],
[path.join(dirname, "test/index.ts")]: ["webpack", "sourcemap"],
},
// define where to save final remapped coverage reports
Expand All @@ -80,13 +80,7 @@ module.exports = function createKarmaConfig(
},
reporters: ["mocha"],
singleRun: true,
webpack: Object.assign({}, webpackBuildScripts.karmaConfig, {
entry: {
testIndex: [
path.resolve(dirname, "test/index.ts"),
],
},
}),
webpack: webpackBuildScripts.karmaConfig,
webpackMiddleware: {
noInfo: true,
stats: {
Expand Down
3 changes: 2 additions & 1 deletion packages/test-commons/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ require("./polyfill");

const Enzyme = require("enzyme");
// test against React 15 with REACT=15 env variable.
const Adapter = require(`enzyme-adapter-react-${process.env.REACT || 16}`);
// this module is swapped out using webpack aliases in webpack.config.karma.js
const Adapter = require("enzyme-adapter-react-16");

Enzyme.configure({ adapter: new Adapter() });

Expand Down
14 changes: 6 additions & 8 deletions packages/webpack-build-scripts/webpack.config.karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

const { CheckerPlugin } = require("awesome-typescript-loader");
const CircularDependencyPlugin = require("circular-dependency-plugin");
// const CircularDependencyPlugin = require("circular-dependency-plugin");
const path = require("path");
const webpack = require("webpack");

Expand All @@ -17,11 +17,14 @@ module.exports = {

devtool: "inline-source-map",

mode: "development",

resolve: {
// swap versions of React packages when this env variable is set
alias: REACT === "15" ? {
// swap enzyme adapter
"enzyme-adapter-react-16": "enzyme-adapter-react-15",
// use path.resolve for directory (require.resolve returns main file)
"prop-types": path.resolve(__dirname, "../test-react15/node_modules/prop-types"),
"react": path.resolve(__dirname, "../test-react15/node_modules/react"),
"react-dom": path.resolve(__dirname, "../test-react15/node_modules/react-dom"),
"react-test-renderer": path.resolve(__dirname, "../test-react15/node_modules/react-test-renderer"),
Expand Down Expand Up @@ -65,12 +68,7 @@ module.exports = {
},

plugins: [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("test"),
REACT: JSON.stringify(REACT),
},
}),
new CheckerPlugin(),

// TODO: enable this
// new CircularDependencyPlugin({
Expand Down

0 comments on commit 5a067da

Please sign in to comment.