half-halt / svg-jest

A small utility for Jest for converting SVG files into react components for testing.
MIT License
15 stars 5 forks source link

Fix for Jest 28+ #7

Open jameskraus opened 2 years ago

jameskraus commented 2 years ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch svg-jest@1.0.1 for the project I'm working on.

Jest has changed the function signature for transformers from (args) => string to (args) => { 'code': string }: https://jestjs.io/docs/28.x/upgrading-to-jest28#transformer

Here is the diff that solved my problem:

diff --git a/node_modules/svg-jest/index.js b/node_modules/svg-jest/index.js
index 20167b5..26adbb2 100644
--- a/node_modules/svg-jest/index.js
+++ b/node_modules/svg-jest/index.js
@@ -2,7 +2,7 @@ const path = require('path');

 function buildModule(functionName, pathname, filename)
 {
-   return `
+   return { code: `
 const React = require('react');

 const ${functionName} = (props) => 
@@ -17,7 +17,7 @@ const ${functionName} = (props) =>

 module.exports.default = ${functionName};
 module.exports.ReactComponent = ${functionName};
-`;
+`};
 }

 function createFunctionName(base)

This issue body was partially generated by patch-package.

jameskraus commented 2 years ago

Here's a PR which fixes the problem: https://github.com/half-halt/svg-jest/pull/8

jameskraus commented 2 years ago

Ah, seems like this is already fixed in https://github.com/half-halt/svg-jest/pull/5

Ronald-Cifuentes commented 1 year ago

@jameskraus this is fork with your suggested change