Skip to content

Commit

Permalink
Merge pull request #150 from react-component/fix-jest-28
Browse files Browse the repository at this point in the history
fix: jest 28 compatable
  • Loading branch information
zombieJ authored May 24, 2023
2 parents 6e9e6bf + c9a2a53 commit 2b8d872
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/transformers/fileTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import path from "path";

// Jest 28 has breaking change of this.
const jestPkg = require('jest/package.json');
const aboveJest28 = parseFloat(jestPkg.version) >= 28;

export default {
process(src: string, filename: string) {
const assetFilename = JSON.stringify(path.basename(filename));

if (filename.match(/\.svg$/)) {
return `module.exports = {
const code = `module.exports = {
__esModule: true,
default: ${assetFilename},
ReactComponent: ({ svgRef, ...props }) => ({
Expand All @@ -18,8 +22,11 @@ export default {
})
}),
};`;

return aboveJest28 ? { code } : code;
}

return `module.exports = ${assetFilename};`;
const rawCode = `module.exports = ${assetFilename};`;
return aboveJest28 ? { code: rawCode } : rawCode;
},
};

0 comments on commit 2b8d872

Please sign in to comment.