-
-
Notifications
You must be signed in to change notification settings - Fork 498
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from spautz/issue/190
Support async configs for scripts (fix #190)
- Loading branch information
Showing
8 changed files
with
119 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/craco/lib/features/test/create-jest-babel-transform.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const babelJest = require("babel-jest"); | ||
|
||
const { isArray } = require("../../utils"); | ||
|
||
function createJestBabelTransform(cracoConfig) { | ||
const craBabelTransformer = { | ||
presets: ["babel-preset-react-app"], | ||
babelrc: false, | ||
configFile: false | ||
}; | ||
|
||
if (cracoConfig) { | ||
const { addPresets, addPlugins } = cracoConfig.jest.babel; | ||
|
||
if (cracoConfig.babel) { | ||
if (addPresets) { | ||
const { presets } = cracoConfig.babel; | ||
|
||
if (isArray(presets)) { | ||
craBabelTransformer.presets = craBabelTransformer.presets.concat(presets); | ||
} | ||
} | ||
|
||
if (addPlugins) { | ||
const { plugins } = cracoConfig.babel; | ||
|
||
if (isArray(plugins)) { | ||
craBabelTransformer.plugins = plugins; | ||
} | ||
} | ||
} | ||
} | ||
return babelJest.createTransformer(craBabelTransformer); | ||
} | ||
|
||
module.exports = { | ||
createJestBabelTransform | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,17 @@ | ||
const babelJest = require("babel-jest"); | ||
|
||
const { loadCracoConfig } = require("../../config"); | ||
const { isArray } = require("../../utils"); | ||
|
||
const craBabelTransformer = { | ||
presets: ["babel-preset-react-app"], | ||
babelrc: false, | ||
configFile: false | ||
}; | ||
|
||
const context = { | ||
env: process.env.NODE_ENV | ||
}; | ||
|
||
const cracoConfig = loadCracoConfig(context); | ||
|
||
const { addPresets, addPlugins } = cracoConfig.jest.babel; | ||
|
||
if (cracoConfig.babel) { | ||
if (addPresets) { | ||
const { presets } = cracoConfig.babel; | ||
|
||
if (isArray(presets)) { | ||
craBabelTransformer.presets = craBabelTransformer.presets.concat(presets); | ||
const { createJestBabelTransform } = require("./create-jest-babel-transform"); | ||
|
||
let jestBabelTransform; | ||
|
||
// cracoConfig is only available inside the transform, but the transform needs to include whatever options cracoConfig | ||
// specifies. So, the first time this transform is run, it generates a new transform -- using cracoConfig -- and | ||
// uses that to process files. | ||
module.exports = { | ||
...createJestBabelTransform(), | ||
process(src, filename, config, transformOptions) { | ||
if (!jestBabelTransform) { | ||
jestBabelTransform = createJestBabelTransform(config.globals._cracoConfig); | ||
} | ||
} | ||
|
||
if (addPlugins) { | ||
const { plugins } = cracoConfig.babel; | ||
|
||
if (isArray(plugins)) { | ||
craBabelTransformer.plugins = plugins; | ||
} | ||
return jestBabelTransform.process(src, filename, config, transformOptions); | ||
} | ||
} | ||
|
||
module.exports = babelJest.createTransformer(craBabelTransformer); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters