1.推荐项目
优点:1万个star,蓝色品质,值得信赖。零配置TS项目,自动测试编译。
缺点: debug支持的不怎么好,尤其是在test里面。
2.手动优化DEBUG
1.添加jest配置文件
vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Jest",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"stopOnEntry": false,
"args": ["${fileBasename}", "--runInBand", "--detectOpenHandles"],
"cwd": "${workspaceFolder}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": ["--nolazy"],
"env": {
"NODE_ENV": "development"
},
"console": "integratedTerminal",
"sourceMaps": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
}
}
]
}
此时debug测试文件是不行的,因为还需要添加TS和Babel编译器。
2. jest添加编译器
文件:jest.config.js
module.exports = process.env.BABEL_ENV === "test" ? {}:{
transform: {
'.(ts|tsx)$': require.resolve('ts-jest/dist'),
'.(js|jsx)$': require.resolve('babel-jest'),
},
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'],
}
执行jest的时候,会自动读取该配置文件。这里的ts-jest和babel-jest两个包是被tsdx依赖的,所以已经安装了。
添加process.env.BABEL_ENV === "test"这个判断是防止tsdx合并该配置,导致报错。
3.debug测试文件
- 1.打开测试文件
- 2.运行jest进行debug
3.自动优化版本
项目j-spring-eco;
- 1.安装项目脚手架
pnpm install j-spring-cli -g
- 2.创建项目
运行:j-spring-cli 选择1 TS-template
- 3.安装依赖
进入项目,pnpm install,就一切OK了