This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jest: Use babel-jest instead of a custom implementation (#1183)
We were previously just reimplementing parts of it, and not using the latest recommended Babel settings (such as still setting `retainLines: true` when sourcemaps are supported natively). There isn't currently a way to set the babel-jest `createTransformer()` options via Jest configuration/globals, so we instead have to resort to using an environment variable. This has the limitation of only supporting Babel options that are serializable (virtually all commonly used configuration options are), with any others being silently omitted. However this was already the case when using `globals` anyway. See: https://github.com/facebook/jest/blob/v23.6.0/packages/babel-jest/README.md https://github.com/facebook/jest/blob/v23.6.0/packages/babel-jest/src/index.js Fixes #851.
- Loading branch information
Showing
4 changed files
with
17 additions
and
59 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
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,13 +1,5 @@ | ||
const { transform } = require('@babel/core'); | ||
const { createTransformer } = require('babel-jest'); | ||
|
||
module.exports = { | ||
// This is inspired by: | ||
// https://github.com/facebook/jest/blob/v22.4.2/packages/babel-jest/src/index.js#L105-L147 | ||
// And is required due to: | ||
// https://github.com/facebook/jest/issues/1468 | ||
// TODO: See if it would be easier to wrap the higher-level babel-jest instead. | ||
process(src, filename, config) { | ||
// Babel 7 returns null if the file was ignored. | ||
return transform(src, { filename, ...config.globals.BABEL_OPTIONS }) || src; | ||
} | ||
}; | ||
const babelOptions = JSON.parse(process.env.JEST_BABEL_OPTIONS); | ||
|
||
module.exports = createTransformer(babelOptions); |
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