esbuild-jest
esbuild-jest copied to clipboard
Don't working with jsx: preserve
tsconfig.json
{
"compilerOptions": {
"target": "ESNext",
"lib": [
"DOM",
"DOM.Iterable",
"ESNext"
],
"allowJs": false,
"skipLibCheck": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"declaration": true,
"sourceMap": true
}
}
Button.tsx
import type { FC } from 'react'
export interface IButtonProps {}
export const Button: FC<IButtonProps> = function ({children}) {
return <button>{ children }</button>
}
Error
ReferenceError: React is not defined
Inject maybe can help
https://esbuild.github.io/api/#inject
@polRk can i know whats your jest config? you try to include jsx in the config, thanks
module.exports = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
transform: {
'^.+\\.tsx?$': [
'esbuild-jest',
{
sourcemap: true,
loaders: {
'.spec.tsx': 'tsx',
},
},
],
},
}
@polRk can i know whats your jest config? you try to include jsx in the config, thanks
It's the same error that I've reported about coverage failing, in your tests fails about semicolon but in large projects fails about React is not defined. I'm sure that @polRk if you clone my changes https://github.com/aelbore/esbuild-jest/pull/34 and try with your codebase everything should work fine
I thin right now you can not use the inject
configuration property in esbuild-jest
until some PR like #29 is merged. I hope it will soon.
Any update on this?
Doesn't work with react-jsx
as well. Would be great to replace ts-jest
, but it is not possible because of this issue.
What's the status of it?
Maybe this repo can solve problem
https://github.com/hannoeru/jest-esbuild
Maybe this repo can solve problem
https://github.com/hannoeru/jest-esbuild
I've had better luck with this one so far