[英]Kick off mocha tests in Visual Studio Team Services Build
I can't for the life of me find documentation or a tutorial for kicking off mocha unit tests in Visual Studio Online builds. 我一生都找不到在Visual Studio Online版本中启动Mocha单元测试的文档或教程。
I have node.js app that is building in VSO and being deployed to Azure. 我有在VSO中构建并部署到Azure的node.js应用程序。 That all works wonderfully.
一切都很棒。 I can't seem to figure out how to kick off the spec files through the build process.
我似乎无法弄清楚如何在构建过程中启动规范文件。
How is this done? 怎么做? Is there documentation available somewhere that I'm missing.
我缺少的地方是否有可用的文档。
Assume you have setup Mocha tests with your package.json
, ie you run tests with npm test
. 假设您使用
package.json
设置了Mocha测试,即使用npm test
。 For more information, refer to https://docs.npmjs.com/cli/test . 有关更多信息,请参阅https://docs.npmjs.com/cli/test 。
In your Visual Studio Online build/release: 在您的Visual Studio Online构建/发行版中:
install mocha-junit-reporter
install mocha-junit-reporter
test -- --reporter mocha-junit-reporter
test -- --reporter mocha-junit-reporter
--timeout 30000
because the build agent maybe running slower than your dev box --timeout 30000
来增加超时,因为构建代理的运行速度可能比开发人员盒慢 Queue a build, you should see Mocha test results in your VSO build. 排队构建时,您应该在VSO构建中看到Mocha测试结果。
BONUS!
奖金! You can also add code coverage to your Mocha run with nyc (formerly known as Istanbul )
您还可以使用nyc (以前称为Istanbul )向Mocha运行中添加代码覆盖率
On top of the steps above: 在上述步骤之上:
package.json
package.json
npm install nyc--save-dev
npm install nyc--save-dev
package.json
package.json
的脚本
{ "scripts": { "test": "nyc --repoter=cobertura mocha" } }
{ "scripts": { "test": "nyc --repoter=cobertura mocha" } }
test -- --reporter mocha-junit-reporter
test -- --reporter mocha-junit-reporter
$(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml
$(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml
$(System.DefaultWorkingDirectory)/coverage/
$(System.DefaultWorkingDirectory)/coverage/
NPM_CONFIG_COVERAGE
and set it to true
NPM_CONFIG_COVERAGE
并将其设置为true
Now you got both unit tests and code coverage results in your build report. 现在,您在构建报告中同时获得了单元测试和代码覆盖率结果。
If you've configured you package.json to be able to run tests, adding a npm step that executes npm run test
should do it. 如果已将package.json配置为能够运行测试,则添加执行
npm run test
的npm步骤即可。 If you want to publish the test results you need to make sure that Mocha is writing its results to a format understood by Visual Studio Team Services. 如果要发布测试结果,则需要确保Mocha将其结果写入Visual Studio Team Services可以理解的格式。 JUnit format would be a safe bet.
JUnit格式将是一个安全的选择。 Then follow up with a Publish test Results step that uploads the test results.
然后执行“发布测试结果”步骤,以上传测试结果。
You can also use the Visual Studio Test Runner, combined with Chutzpah to run your tests, but I suppose that's going to be a lot of additional work to setup and isn't going to add much. 您还可以结合使用Visual Studio Test Runner和Chutzpah来运行测试,但是我想这将需要大量的设置工作,并且不会增加太多的工作。
After quite a bit of fiddling around i got it to work by adding a "Command line task" to my build definition, i used the following parameters: 经过一番摆弄之后,我通过在构建定义中添加“命令行任务”使其工作,我使用了以下参数:
node
node
$(Build.SourcesDirectory)\\node_modules\\jasmine-node\\bin\\jasmine-node --verbose test\\
$(Build.SourcesDirectory)\\node_modules\\jasmine-node\\bin\\jasmine-node --verbose test\\
My tests are under a "test" folder, also make sure you have jasmine-node as a dev dependency 我的测试位于“测试”文件夹下,还请确保您具有jasmine-node作为开发依赖项
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.