Unverified Commit c16ed9a4 authored by Vihang Mehta's avatar Vihang Mehta Committed by Copybara
Browse files

PC-937 - Add esm transformation for jest

Summary:
This is necessary because we are upgradeing to mui@5 which uses
esm modules. ESM in node modules are not transformed by default.
Unfortunately, changing the tranform rules is not enough since
some Babel config is preventing the transformation without the
extra level of indirection.

Test Plan: tested with current version and update mui.

Reviewers: michelle, vihang, nlanam

Reviewed By: vihang

JIRA Issues: PC-937

Differential Revision: https://phab.corp.pixielabs.ai/D8651

GitOrigin-RevId: a6d0a2b497b88e02222ccc771867008fed108c56
parent 4c5a379a
No related merge requests found
Showing with 46 additions and 3 deletions
+46 -3
{
"presets": ["@babel/react", "@babel/typescript", ["@babel/env", { "modules": false }]],
"presets": ["@babel/preset-env", "@babel/preset-react", "@babel/typescript"],
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-proposal-private-methods",
"react-hot-loader/babel" // Enables React code to work with HMR.
"react-hot-loader/babel"
]
}
......@@ -37,6 +37,7 @@
"devDependencies": [
"**/*test.ts",
"**/*test.tsx",
"jest-esm-transform.js",
"src/testing/**/*",
"packages/**/src/testing/*",
"packages/**/rollup.config.js",
......
......@@ -27,6 +27,7 @@ package(default_visibility = ["//src:__subpackages__"])
UI_DEP_PACKAGES = [
"yarn.lock",
"package.json",
".babelrc.json",
".yarnrc",
] + glob([
"offline_package_cache/**",
......
/*
* Copyright 2018- The Pixie Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
// This file calls Babel manually on js(x) files.
// This is necessary because we have esm node_modules
// and they are ignored by default. Unfortunately, changing
// the tranform views is not enough since some Babel config is
// preventing the transformation without this.
const babelJest = require('babel-jest').createTransformer(require('./.babelrc.json'));
module.exports = {
process: function(src, file, config, transformOptions) {
if (file.match(/.*jsx?$/)) {
return babelJest.process.bind(this)(src, file, config, transformOptions);
}
console.warn('Unknown extension for file (passing through):', file);
return src;
},
};
......@@ -16,6 +16,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
const esModules = ['@material-ui/core', '@babel/runtime/helpers/esm'].join('|');
module.exports = {
globals: {
window: true,
......@@ -49,8 +51,9 @@ module.exports = {
},
resolver: null,
transform: {
'^.+\\.jsx?$': 'babel-jest',
'^.+\\.tsx?$': 'ts-jest',
[`node_modules/(${esModules}).*\\.jsx?$`]: './jest-esm-transform',
'^.+\\.jsx?$': 'babel-jest',
'^.+\\.toml$': 'jest-raw-loader',
},
testRegex: '.*test\\.(ts|tsx|js|jsx)$',
......@@ -58,6 +61,9 @@ module.exports = {
'default',
'jest-junit',
],
// We need to specify the inverse of the esModules above, to make sure
// we don't use the default (ignore all node modules).
transformIgnorePatterns: [`/node_modules/(?!${esModules})`],
collectCoverageFrom: [
'src/**/*.ts',
'src/**/*.tsx',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment