jest icon indicating copy to clipboard operation
jest copied to clipboard

.swcrc file not read

Open iiroj opened this issue 3 years ago • 3 comments

It seems @swc/jest doesn't read the .swcrc configuration file, because Jest always passes it at least an empty options object (swcOptions = {}), and so this conditional never applies:

https://github.com/swc-project/jest/blob/82a6a95f2880d01e0b7e0b020a4e24bf88cb8487/index.ts#L58-L61

Something like this might help:

--- if (!swcOptions) { 
+++ if (!swcOptions || Object.keys(swcOptions).length === 0) { 
      const swcrc = path.join(process.cwd(), '.swcrc') 
      swcOptions = fs.existsSync(swcrc) ? JSON.parse(fs.readFileSync(swcrc, 'utf-8')) as Options : {} 
    } 

I was able to test this by cloning this repo, and moving the config in examples/react/package.json into examples/react/.swcrc instead.

iiroj avatar Dec 06 '21 13:12 iiroj

Change your jest config

transform: {
  '^.+\\.(t|j)sx?$': '@swc/jest',
},

to

transform: {
  '^.+\\.(t|j)sx?$': ['@swc/jest'],
},

it should work.

Kaciras avatar Dec 07 '21 15:12 Kaciras

Thanks @Kaciras. Maybe the README could be updated for this.

iiroj avatar Dec 07 '21 16:12 iiroj

I'm also having this problem, @Kaciras solution doesn't seem right to me. It gives me a type error in the IDE

image

And then when run I get the same type error on the console

spence-novata avatar Dec 24 '21 19:12 spence-novata