我在用摩卡和巴贝尔编译器运行伊斯坦布尔时遇到了一些问题.

我的所有测试都运行得很好,但在所有测试完成后,它向我显示了以下消息:

No coverage information was collected, exit without writing coverage information

它也没有制作任何报道报告.

我正在运行的命令是:

NODE_ENV=test istanbul cover _mocha -- --require babel-core/register --recursive

该项目位于GitHub上:

知道会是什么吗?

推荐答案

使用巴别塔6.x、 假设我们有test/pad.spec.js个文件:

import pad from '../src/assets/js/helpers/pad';
import assert from 'assert';

describe('pad', () => {
  it('should pad a string', () => {
    assert.equal(pad('foo', 4), '0foo');
  });
});

安装一堆垃圾:

$ npm install babel-istanbul babel-cli babel-preset-es2015 mocha

创建一个.babelrc:

{
  "presets": ["es2015"]
}

运行测试:

$ node_modules/.bin/babel-node node_modules/.bin/babel-istanbul cover \   
node_modules/.bin/_mocha -- test/pad.spec.js


  pad
    ✓ should pad a string


  1 passing (8ms)

=============================================================================
Writing coverage object [/Volumes/alien/projects/forked/react-flux-puzzle/coverage/coverage.json]
Writing coverage reports at [/Volumes/alien/projects/forked/react-flux-puzzle/coverage]
=============================================================================

=============================== Coverage summary ===============================
Statements   : 100% ( 4/4 )
Branches     : 66.67% ( 4/6 ), 1 ignored
Functions    : 100% ( 1/1 )
Lines        : 100% ( 3/3 )
================================================================================

UPDATE:我成功地使用了nyc(消耗istanbul),而不是istanbul/babel-istanbul.这就不那么复杂了.要try 它:

安装东西(可以删除babel-istanbulbabel-cli):

$ npm install babel-core babel-preset-es2015 mocha nyc

如上图所示创建.babelrc.

执行以下命令:

$ node_modules/.bin/nyc --require babel-core/register node_modules/.bin/mocha \ 
test/pad.spec.js

...这应该会给你类似的结果.默认情况下,它将覆盖率信息放入.nyc-output/,并在控制台中打印一个漂亮的文本摘要.

Note:将命令放入package.jsonscripts字段时,可以从这些命令中删除node_modules/.bin/.

Node.js相关问答推荐

使用ReadableStream.管道时NodeJS Crypto Hash不正确

JEST模拟由http服务器控制器导入的ES模块

使用NodeJS的DynamoDB中的BatchGetItem出现MultipleValidationError

当变量在另一个文件中初始化时,在初始化错误之前无法访问变量

React原生Nodejs兼容性问题

Redis Typescript 删除方法类型转换

在对象数组中的数组中嵌套 $lookup - Mongodb

在 getServerSideProps 中使用 EmailProvider 获取 NextAuth 会话会抛出 fs找不到模块

为什么当我使用waitForSelector时 Puppeteer 导致我的测试套件挂起 30 秒,即使我在页面和浏览器上调用关闭?

在 Node JS 中使用 url 链接而不是文件路径

mongoose.model() 方法返回未定义

如何在 node.js 环境中从 WebAssembly (Rust) 调用异步 JavaScript 导入函数?

什么是nestjs错误处理方式(业务逻辑错误vs.http错误)?

如何从 Redis 保存和检索会话

将 myproject/.npmrc 与注册表一起使用

ChildProcess 关闭、退出事件之间的区别

如何将子集合添加到 Firestore 中的文档?

为什么 Node 控制台不显示功能代码?

Javascript在try块内设置const变量

node.js 中的意外保留字导入