Skip to content

Commit

Permalink
fix(test): Support dynamic imports in tests (seek-oss#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish authored Apr 1, 2019
1 parent 5b3c89e commit 84b8541
Show file tree
Hide file tree
Showing 23 changed files with 175 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ node_modules
report/
dist-start/
dist-build/
dist-storybook/
coverage/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ dist-build/

# managed by sku
.prettierrc
coverage/
dist-storybook/
dist/
report/
tsconfig.json
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ dist-build/
dist-start/

# managed by sku
coverage/
dist-storybook/
dist/
report/
# end managed by sku
5 changes: 5 additions & 0 deletions config/babel/babelConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const nodeEnvOptions = {

module.exports = ({ target, lang = 'js' }) => {
const isBrowser = target === 'browser';
const isJest = target === 'jest';

const envPresetOptions = isBrowser ? browserEnvOptions : nodeEnvOptions;
const plugins = [
Expand All @@ -37,6 +38,10 @@ module.exports = ({ target, lang = 'js' }) => {
plugins.push(require.resolve('babel-plugin-seek-style-guide'));
}

if (isJest) {
plugins.push(require.resolve('babel-plugin-dynamic-import-node'));
}

if (process.env.NODE_ENV === 'production') {
plugins.push(
require.resolve('@babel/plugin-transform-react-inline-elements'),
Expand Down
2 changes: 1 addition & 1 deletion config/jest/jsBabelTransform.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const babelJest = require('babel-jest');
const babelConfig = require('../babel/babelConfig');

module.exports = babelJest.createTransformer(babelConfig({ target: 'node' }));
module.exports = babelJest.createTransformer(babelConfig({ target: 'jest' }));
2 changes: 1 addition & 1 deletion config/jest/tsBabelTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ const babelJest = require('babel-jest');
const babelConfig = require('../babel/babelConfig');

module.exports = babelJest.createTransformer(
babelConfig({ target: 'node', lang: 'ts' }),
babelConfig({ target: 'jest', lang: 'ts' }),
);
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"babel-jest": "^24.0.0",
"babel-loader": "^8.0.4",
"babel-plugin-add-react-displayname": "^0.0.5",
"babel-plugin-dynamic-import-node": "^2.2.0",
"babel-plugin-flow-react-proptypes": "^25.0.0",
"babel-plugin-macros": "^2.4.2",
"babel-plugin-module-resolver": "^3.1.1",
Expand Down Expand Up @@ -190,6 +191,7 @@
"react-dom": "^16.8.1",
"react-helmet": "^5.2.0",
"react-router-dom": "^4.3.1",
"react-testing-library": "^6.0.3",
"renovate-config-seek": "^0.4.0",
"seek-asia-style-guide": "^7.0.0",
"seek-style-guide": "^38.9.2",
Expand Down
Loading

0 comments on commit 84b8541

Please sign in to comment.