建楼之旅
使用自建变压器
使用此变压器可以使用并转换( ts, js, tsx和 jsx) 文件
安装
npm install --save-dev esbuild-jest esbuild
设置 Jest 配置文件
在您的 Jest 配置文件中应该使用 esbuild- jest 变压器 :
{
"transform": {
"^.+\\.tsx?$": "esbuild-jest"
}
}
设置带有变换选项的 Jest 配置文件
export interface Options {
jsxFactory?: string
jsxFragment?: string
sourcemap?: boolean | 'inline' | 'external'
loaders?: {
[ext: string]: Loader
},
target?: string
format?: string
}
{
"transform": {
"^.+\\.tsx?$": [
"esbuild-jest",
{
sourcemap: true,
loaders: {
'.spec.ts': 'tsx'
}
}
]
}
}
注意:如果您使用 tsconfig.json 和 jsconfig.json 的"路径",请查看
alias-hq文档 https://github.com/davestewart/alias-hq/blob/master/docs/ institutions.md