运行“节点测试"作为Visual Studio Team Services构建任务的一部分,其中包含“测试"结果标签 [英] Run "node test" as part of Visual Studio Team Services build task with results in "tests" tab

查看:95
本文介绍了运行“节点测试"作为Visual Studio Team Services构建任务的一部分,其中包含“测试"结果标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,其中包含我从命令行通过Mocha运行的测试.我已经在packages.json中设置了一个测试脚本,该脚本如下所示:

I have a project that contains tests that I am running with Mocha from the command line. I have set up a test script in my packages.json, which looks as follows:

"test": "mocha ./**/*.spec.js --reporter dot --require jsdom-global/register"

我目前在Visual Studio Team Services中设置了一个简单的任务,该任务只运行npm test命令,这将在控制台中运行Mocha并根据测试是否通过来继续/失败构建.

I have currently got a simple task set up in Visual Studio Team Services, which just runs the npm test command, this runs Mocha within a console and continues/fails the build depending on whether the tests pass.

我想做的就是在运行定义后,将测试结果填充到构建定义中的测试"选项卡中.如果我在C#代码上运行测试,则以与填充此选项卡相同的方式.

What I'd like to be able to do is have the results of my tests populate the "tests" tab in the build definition after it's run. In the same way that I can get this tab populated if I'm running tests on C# code.

我已经尝试过使用Chutzpah,但是它过于复杂,似乎要求我经历各种麻烦,这意味着要更改测试并编写长的配置文件.我已经写了很多测试,所以真的不想这么做.当它最终发现我的任何测试时,它抱怨require以及与Node模块有关的其他事情.

I've tried using Chutzpah for this, but it's overly complicated and seems to require that I jump through all sorts of hoops that mean changing my tests and writing long config files. I already have loads of tests written, so really don't want to have to do that. When it did finally discover any of my tests, it complained about require and other things related to Node modules.

我所要求的实际上可行吗?是否有一种简单的方法可以与在Node中运行测试兼容?

Is what I'm asking for actually possible? Is there a simple way of achieving this that's compatible with running my tests in Node?

推荐答案

我找到了一种不需要第三方适配器(例如Chutzpah)的好方法.它涉及使Mocha以XML格式输出其报告,并设置Visual Studio Team Services以在构建定义的额外步骤中发布结果.

I've found a good way of doing it that requires no third-party adapter (eg. Chutzpah). It involves getting Mocha to output its report in an XML format, and setting up Visual Studio Team Services to publish the results in an extra step of the build definition.

我安装了mocha-junit-reporter( https://www.npmjs.com/package/mocha-junit-reporter ),并将我的测试脚本更改为以下内容:

I installed mocha-junit-reporter (https://www.npmjs.com/package/mocha-junit-reporter) and altered my test script to the following:

"test": "mocha ./temp/**/*.spec.js --reporter mocha-junit-reporter --require jsdom-global/register"

然后,我使用发布测试结果"任务在构建定义中创建了一个新步骤.我将结果格式设置为"JUnit",并为报告程序创建的输出test-results.xml文件添加了正确的路径.

I then created a new step in my build definition using the "Publish Test Results" task. I set the result format to "JUnit" and added the correct path for the outputted test-results.xml file created by the reporter.

值得注意的是,尽管Mocha随附了"XUnit"报告程序,但该格式似乎已作为VSTS的一部分而不能正确使用.

It is worth noting that although Mocha comes with an "XUnit" reporter, this format appears to not work correctly with VSTS even though it's listed as an option.

npm test的结果现在显示在测试"选项卡中,同时显示MSTest等进行的其他任何测试.

The results of npm test now show up in the "tests" tab alongside any other tests from MSTest etc.

这篇关于运行“节点测试"作为Visual Studio Team Services构建任务的一部分,其中包含“测试"结果标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆