我已经看到了Angular项目,其中在每次执行构建时以及在运行git push命令时都会运行单元测试。如果在任一命令中任何测试失败,则直到所有单元测试通过或除非您绕过,该过程才会执行。我想为我的项目设置这种最佳实践。请帮忙:)
答案 0 :(得分:1)
要在提交或推送之前运行构建,单元测试等,您可以使用Husky之类的工具。
答案 1 :(得分:1)
Git provides a methodology to hook it's events using .git/hooks
you can add a folder to your project called .git/hooks
and within that folder add a subfolder called pre-commit
and within that you may place scripts that are to be ran. This being whatever your test command is.
For example test.sh would contain: ng test
More documentation about hooking git events can be found here: https://git-scm.com/docs/githooks
Let me know if you have any questions, I would be happy to revise my answer!
答案 2 :(得分:1)
添加一个名为 husky 的程序包作为devDependencies。
npm i husky --save-dev
现在使用赫斯基捕获预提交的Webhook,在 package.json 中执行此操作,添加以下对象:
"husky": {
"hooks": {
"pre-commit": "ng test"
}
}
这将确保每次进行提交时, ng测试都会在实际提交发生之前运行。