jest
jest copied to clipboard
.swcrc file not read
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.
Change your jest config
transform: {
'^.+\\.(t|j)sx?$': '@swc/jest',
},
to
transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest'],
},
it should work.
Thanks @Kaciras. Maybe the README
could be updated for this.
I'm also having this problem, @Kaciras solution doesn't seem right to me. It gives me a type error in the IDE

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