运行测试
不带路径的 kscript test 会运行当前项目中的每个测试文件:即最近的 kscript.json 所在文件夹,如果没有则为当前文件夹。名称以 . 开头的文件夹,以及 node_modules、bin 和 obj,都会被跳过。你也可以指定文件夹和文件,或按名称挑选测试:
| 命令 | 作用 |
|---|---|
kscript test | 项目中可能受改动影响的测试。 |
kscript test --all | 项目中的每个测试。 |
kscript test --failed | 仅上次失败的测试。 |
kscript test --changed | 你未提交的更改可能影响到的测试。 |
kscript test --changed master | 本分支的更改可能影响到的测试。 |
kscript test --watch | 每次保存时运行受影响的测试。 |
kscript test tests/cart tests/api.test.kscript | 一个文件夹和一个文件。 |
kscript test --filter "cart › adds" | 仅运行全名包含该文本的测试(不区分大小写) |
kscript test --timeout 30 | 每个测试的秒数(0:不限制) |
kscript test --junit test-results.xml | 同时写入 JUnit XML 报告。 |
kscript tests/cart.test.kscript 也可运行单个文件。
当输出为终端时使用颜色;设置 NO_COLOR 可关闭颜色,设置 FORCE_COLOR 可保留颜色。按 Ctrl+C 可在当前测试结束后停止运行。
--junit 以 JUnit XML 格式写入结果,GitHub Actions 报告工具、GitLab、Jenkins 和 Azure Pipelines 均可显示。失败的检查记为 <failure>,其他错误记为 <error>,无法运行的文件记为名为 (load) 的测试,并附带 <error>。