Files
react/compiler/forget/scripts/jest/makeTransform.js
T
Jan Kassens e575e22925 Add hash of Babel plugin to Jest transform
Jest caches based on the hash of the babel config. This caused us to not break 
that cache when the we made changes to the plugin. 

Fixes #643
2022-10-06 16:59:12 -04:00

49 lines
1.2 KiB
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const ReactForgetBabelPlugin = require("../../dist").default;
const babelJest = require("babel-jest");
const { readFileSync } = require("fs");
module.exports = (useForget) => {
function createTransformer() {
return babelJest.createTransformer({
passPerPreset: true,
presets: [
"@babel/preset-typescript",
{
plugins: [
"@babel/plugin-syntax-jsx",
...(useForget
? [
[
ReactForgetBabelPlugin,
{
// Jest hashes the babel config as a cache breaker.
cacheBreaker: readFileSync("dist/HASH", "utf8"),
},
],
]
: []),
],
},
"@babel/preset-react",
{
plugins: ["@babel/plugin-transform-modules-commonjs"],
},
],
targets: {
esmodules: true,
},
});
}
return {
createTransformer,
};
};