Skip to content

Commit

Permalink
Add babel-plugin-dynamic-import-node for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthachatterjee committed Jul 12, 2019
1 parent a823463 commit 5851a08
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion jest-transformer.js
@@ -1,2 +1,5 @@
const babelPreset = require(`babel-preset-gatsby-package`)()
module.exports = require(`babel-jest`).createTransformer(babelPreset)
module.exports = require(`babel-jest`).createTransformer({
...babelPreset,
plugins: [...babelPreset.plugins, `babel-plugin-dynamic-import-node`],
})
1 change: 1 addition & 0 deletions packages/babel-preset-gatsby/package.json
Expand Up @@ -29,6 +29,7 @@
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"babel-plugin-dynamic-import-node": "^1.2.0",
"babel-preset-gatsby-package": "^0.2.1",
"cross-env": "^5.1.4"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/babel-preset-gatsby/src/__tests__/index.js
Expand Up @@ -50,6 +50,7 @@ it(`Specifies proper presets and plugins for test stage`, () => {
useESModules: false,
},
],
expect.stringContaining(`babel-plugin-dynamic-import-node`),
])
})

Expand Down Expand Up @@ -111,6 +112,7 @@ it(`Specifies proper presets and plugins for build-html stage`, () => {
useESModules: true,
},
],
expect.stringContaining(`babel-plugin-dynamic-import-node`),
])
})

Expand Down
7 changes: 5 additions & 2 deletions packages/babel-preset-gatsby/src/index.js
Expand Up @@ -2,9 +2,11 @@ const path = require(`path`)

const resolve = m => require.resolve(m)

const IS_TEST = process.env.NODE_ENV === `test`

const loadCachedConfig = () => {
let pluginBabelConfig = {}
if (process.env.NODE_ENV !== `test`) {
if (!IS_TEST) {
try {
pluginBabelConfig = require(path.join(
process.cwd(),
Expand Down Expand Up @@ -85,6 +87,7 @@ module.exports = function preset(_, options = {}) {
absoluteRuntimePath,
},
],
],
IS_TEST && resolve(`babel-plugin-dynamic-import-node`),
].filter(Boolean),
}
}

0 comments on commit 5851a08

Please sign in to comment.