Skip to content

Commit

Permalink
Expose package globals in test build
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Mar 28, 2017
1 parent f80239f commit 97ba143
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
5 changes: 0 additions & 5 deletions bootstrap-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,3 @@ global.document = require( 'jsdom' ).jsdom( '', {
} );
global.window = document.defaultView;
global.navigator = window.navigator;
global.wp = {
element: {
Component: function() {}
}
};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
14 changes: 13 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 97ba143

Please sign in to comment.