Do not use env key in Babel common preset (#48661)

The merging behavior of having both `plugins` and `env.test.plugins` in the Babel configuration is confusing and does not work how we would like (that is, disabling the idx Babel plugin in test environments.)

There had been some [discussion about deprecating the `env` key in Babel](https://github.com/babel/babel/issues/5276) because of this behavior and recommending using conditional logic. The behavior has been modified in later versions of Babel, but still does not work as intended in our case.

Change this to only add the idx plugin if we're in a non-test environment.
This commit is contained in:
Nathan L Smith 2019-10-21 16:23:59 -05:00 committed by GitHub
parent cc6aff7433
commit fa951abfdc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -28,17 +28,17 @@ const plugins = [
// See https://github.com/babel/proposals/issues/12 for progress
require.resolve('@babel/plugin-proposal-class-properties'),
];
const isTestEnv = process.env.BABEL_ENV === 'test' || process.env.NODE_ENV === 'test';
// Only load the idx plugin in non-test environments, since it conflicts with
// Jest's coverage mapping.
if (!isTestEnv) {
plugins.push(require.resolve('@kbn/elastic-idx/babel'));
}
module.exports = {
presets: [require.resolve('@babel/preset-typescript'), require.resolve('@babel/preset-react')],
plugins: plugins.concat(require.resolve('@kbn/elastic-idx/babel')),
// Do not use the idx plugin in the test environment because it causes
// causes conflicts with Jest's coverage mapping.
env: {
test: {
plugins,
},
},
plugins,
overrides: [
{
// Babel 7 don't support the namespace feature on typescript code.