在Visual Studio Team Services Build中启动摩卡testing
我不能为我的生活find文档或教程开始在Visual Studio在线构build摩卡咖啡unit testing。
我有在VSO中构build并正在部署到Azure的node.js应用程序。 这一切都奇妙的作品。 我似乎无法弄清楚如何通过构build过程启动spec文件。
这是怎么做的? 是否有文档可用,我失踪了。
假设你已经用你的package.json
设置了Mochatesting,也就是说用npm test
。 有关更多信息,请参阅https://docs.npmjs.com/cli/test 。
在您的Visual Studio Online构build/版本中:
- 添加一个“npm”任务来安装JUnit记者
- 运行自定义命令
install mocha-junit-reporter
- 运行自定义命令
- 添加一个“npm”任务
- 运行自定义命令
test -- --reporter mocha-junit-reporter
- 小贴士:你可能想通过增加
--timeout 30000
来增加超时时间,因为--timeout 30000
代理的运行速度可能比你的开发箱慢
- 运行自定义命令
- 然后,添加“发布testing结果”任务
- 将“testing结果格式”设置为“JUnit”
- 选中“继续出错”
- 在“控制选项”>“运行此任务”下,将其设置为“即使之前的任务失败,除非构build被取消”
排队构build,你应该在VSO构build中看到Mochatesting结果。
奖金! 您还可以将代码覆盖范围添加到您在伊斯坦布尔运行的Mocha。
在上面的步骤之上:
- 在本地安装Istanbul到你的
package.json
- 运行
npm install istanbul --save-dev
- 运行
- 修改
package.json
的脚本- 更新
{ "scripts": { "test": "istanbul test node_modules/mocha/bin/_mocha" } }
- 更新
- 修改“npmtesting”任务
- 运行自定义命令
test -- --report cobertura --report html -- --reporter mocha-junit-reporter
- 运行自定义命令
- 添加“发布代码覆盖率结果”任务
- 将“代码覆盖工具”设置为“Cobertura”
- 将“摘要文件”设置为
$(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml
- 将“报告目录”设置为
$(System.DefaultWorkingDirectory)/coverage/
- 选中“继续出错”
- 在“控制选项”>“运行此任务”下,将其设置为“即使之前的任务失败,除非构build被取消”
- 添加一个新的生成variables
NPM_CONFIG_COVERAGE
并将其设置为true
现在,您在构build报告中获得了unit testing和代码覆盖率结果。
如果你已经configuration了package.json来运行testing,那么添加一个执行npm run test
的npm步骤就可以了。 如果您想发布testing结果,则需要确保Mocha将其结果写入Visual Studio Team Services所了解的格式。 JUnit格式将是一个安全的赌注。 然后进行上传testing结果的发布testing结果步骤。
你也可以使用Visual Studio Test Runner和Chutzpah来运行你的testing,但是我想这将是很多额外的工作,而且不会增加很多。
经过相当多的摆弄我得到它的工作,通过添加一个“命令行任务”我的构build定义,我使用了以下参数:
- 将工具设置为
node
- 将参数设置为
$(Build.SourcesDirectory)\node_modules\jasmine-node\bin\jasmine-node --verbose test\
我的testing是在“testing”文件夹下,也确保你有茉莉花节点作为开发依赖