diff --git a/bootstrap-test.js b/bootstrap-test.js index 57933689bae03..76c25f0d125ab 100644 --- a/bootstrap-test.js +++ b/bootstrap-test.js @@ -13,8 +13,3 @@ global.document = require( 'jsdom' ).jsdom( '', { } ); global.window = document.defaultView; global.navigator = window.navigator; -global.wp = { - element: { - Component: function() {} - } -}; diff --git a/package.json b/package.json index 1ed09b08fc354..747e81b666536 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "eslint-config-wordpress": "^1.1.0", "eslint-plugin-jsx-a11y": "^4.0.0", "eslint-plugin-react": "^6.10.3", + "expose-loader": "^0.7.3", "extract-text-webpack-plugin": "^2.1.0", "glob": "^7.1.1", "jsdom": "^9.12.0", @@ -42,6 +43,8 @@ "pegjs-loader": "^0.5.1", "postcss-loader": "^1.3.3", "raw-loader": "^0.5.1", + "react": "^15.4.2", + "react-dom": "^15.4.2", "sass-loader": "^6.0.3", "sinon": "^2.1.0", "sinon-chai": "^2.9.0", diff --git a/webpack.config.js b/webpack.config.js index 481729d2554d6..3f35ff8bcd836 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -74,7 +74,19 @@ switch ( process.env.NODE_ENV ) { case 'test': config.target = 'node'; - config.entry = glob.sync( `./{${ Object.keys( config.entry ).join() }}/test/*.js` ); + config.module.rules = [ + ...config.module.rules, + ...[ 'element', 'blocks', 'editor' ].map( ( entry ) => ( { + test: require.resolve( './' + entry + '/index.js' ), + use: 'expose-loader?wp.' + entry + } ) ) + ]; + config.entry = [ + './element/index.js', + './blocks/index.js', + './editor/index.js', + ...glob.sync( `./{${ Object.keys( config.entry ).join() }}/test/*.js` ) + ]; config.externals = [ require( 'webpack-node-externals' )() ]; config.output = { filename: 'build/test.js',