当我在Windows命令行mocha --reporter spec > report.html
上运行以下命令时,我得到了一些我在浏览器中无法使用的内容。
[0m[0m
[0m Routes[0m
[32m √[0m[90m all GET routes should be bound to a function [0m
[32m √[0m[90m all POST routes should be bound to a function [0m
[32m √[0m[90m should have one for creating CU [0m
[0m Database[0m
[32m √[0m[90m should be online, connectable and the right one [0m[31m(156ms)[0m
[0m HTTPS API[0m
[0m authentication[0m
[32m √[0m[90m is mandatory [0m[31m(1109ms)[0m
[0m entity[0m
[32m √[0m[90m lookup should work [0m[31m(172ms)[0m
[36m - creation should work[0m
[0m Website[0m
[0m pages[0m
[32m √[0m[90m should contain quite a few of them [0m
[32m √[0m[90m all of them should have internal links to existing pages [0m
[92m [0m[32m 8 passing[0m[90m (2s)[0m
[36m [0m[36m 1 pending[0m
我想要一些输出,如本例http://visionmedia.github.io/mocha/example/tests.html所示,它实际上将文档与测试结果结合在一起。只是测试结果对我来说就足够了。
我所做的所有搜索都告诉我有关code coverage获取HTML的信息,但我现在不想这样做。我只需要一个我可以在浏览器中查看的Mocha(测试我的节点应用程序)的html报告。当然我可以自己做点什么,但这看起来微不足道,所以我希望有人创造了一个custom reporter。
答案 0 :(得分:1)
我在mocha-unfunk-reporter找到了答案。一个没有控制台时髦性和具有HTML报告功能的摩卡记者。
使用如下:
npm install mocha-unfunk-reporter
如果您在全球范围内安装了Mocha,则need to install mocha-unfunk-reporter globally (add -g) as well会导致mocha无效的报告错误。
在test.js中添加选项,使用css颜色或css类将样式设置为html
。对后者使用样式css
:process.env['mocha-unfunk-style'] = 'css';
运行mocha --reporter mocha-unfunk-reporter > unfunk.html
你会得到:
<span class="mw-plain"></span>
<span class="mw-accent">-></span> running <span class="mw-accent">4 suites</span>
<span class="mw-accent">Routes</span>
<span class="mw-plain">all GET routes should be bound to a function.. </span><span class="mw-success">ok</span>
<span class="mw-plain">all POST routes should be bound to a function.. </span><span class="mw-success">ok</span>
<span class="mw-plain">should have one for creating CU.. </span><span class="mw-success">ok</span>
<span class="mw-accent">Database</span>
<span class="mw-plain">should be online, connectable and the right one.. </span><span class="mw-success">slow</span><span class="mw-error"> (125ms)</span>
<span class="mw-accent">HTTPS API</span>
<span class="mw-accent">authentication</span>
<span class="mw-plain">is mandatory.. </span><span class="mw-success">medium</span><span class="mw-warning"> (47ms)</span>
<span class="mw-accent">entity</span>
<span class="mw-plain">lookup should work.. </span><span class="mw-success">ok</span>
<span class="mw-plain">creation should work.. </span><span class="mw-warning">pending</span>
<span class="mw-accent">Website</span>
<span class="mw-accent">pages</span>
<span class="mw-plain">should contain quite a few of them.. </span><span class="mw-success">ok</span>
<span class="mw-plain">all of them should have internal links to existing pages.. </span><span class="mw-success">ok</span>
<span class="mw-plain">-> </span><span class="mw-success">passed 12</span> of <span class="mw-accent">12 tests</span>, left <span class="mw-warning">1 pending</span> (282ms)
正是我需要的!
答案 1 :(得分:0)
您可以使用mochawesome。它非常高效,可以输出JSON和样式优雅的HTML报告。
由于我们大多数人都在全球范围内安装了摩卡咖啡,因此最好在全球范围内也安装摩卡咖啡。
npm install -g mochawesome
然后运行:
mocha --reporter mochawesome
从您的测试目录中。
答案 2 :(得分:-2)
另一种选择是使用mochawesome:https://github.com/adamgruber/mochawesome
使用以下脚本,您可以执行测试(在测试/文件夹中)并查看结果(在报告文件夹中):
throw new Error('Zone already loaded.');