简体   繁体   English

摩卡咖啡与Blanket,Babel和LCOV记者

[英]Mocha with Blanket, Babel and LCOV reporter

Hiho, 嗨,

I've got a problem with my Mocha configuration. 我的Mocha配置有问题。 I've got ES6 code which should be compiled by Babel and then I want to get coverage (in LCOV format) of this ES6 code. 我有应该由Babel编译的ES6代码,然后我想覆盖此ES6代码(LCOV格式)。

My approach to this problem was to use mocha , mocha-lcov-reporter , babel and blanket packages. 我解决此问题的方法是使用mochamocha-lcov-reporterbabelblanket包装。 Code structure is: 代码结构为:

-- src
----- ...
-- test
----- spec
-------- something.spec.js
-------- ...
----- blanket.js

Where specs are in test/spec directory (matches also *.spec.js pattern) and blanket.js is: 规格位于test/spec目录中(也匹配*.spec.js模式),而blanket.js是:

require('blanket')({
    pattern: require('path').join(__dirname, '..', 'src')
});

Command which I prepared is: 我准备的命令是:

./node_modules/.bin/mocha $(find test -name '*.spec.js') --recursive --compilers js:babel/register -r test/blanket -R mocha-lcov-reporter

So, it should run Mocha tests for all *.spec.js files, compiling them by Babel and starting test/blanket.js file before. 因此,它应该对所有*.spec.js文件运行Mocha测试,并通过Babel对其进行编译,然后再启动test/blanket.js文件。

After starting this command I get Error: Line 1: Unexpected reserved word error from esprima.js . 启动此命令后,我收到Error: Line 1: Unexpected reserved word esprima.js Error: Line 1: Unexpected reserved word错误。 When I run it without requiring test/blanket file it run without problems, but ofc I haven't coverage. 当我运行它而无需测试/空白文件时,它可以正常运行,但是我没有覆盖。

Has anyone tried to do so? 有没有人尝试这样做? Do you have any ideas how to do it? 您有任何想法如何做吗?

Okey, problem already resolved, but without Babel (native ES6 instead); Okey,问题已经解决,但没有Babel(改为ES6原生); I've done it another way. 我已经用另一种方式做到了。 I've used istanbul-harmony and mocha packages. 我使用过istanbul-harmonymocha包。 Then the command is: 然后命令是:

./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- $(find test -name '*.spec.js') -R spec -u exports

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM