istambul nyc在运行ava测试套件时无法检测到任何文件

问题描述

开始尝试将nyc / istambul集成到我的ava测试套件中:

./node_modules/.bin/nyc --include modules/todo.js --es-modules ./node_modules/.bin/ava
  1 tests passed
  ----------|---------|----------|---------|---------|-------------------
  File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
  ----------|---------|----------|---------|---------|-------------------
  All files |       0 |        0 |       0 |       0 |                   
  ----------|---------|----------|---------|---------|-------------------

输出无法列出任何文件!

如果我添加--all标志,即使测试涵盖了这两个功能,我也会得到以下结果:

ERROR: Coverage for lines (0%) does not meet global threshold (90%)
----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |                   
 todo.js  |       0 |        0 |       0 |       0 | 6-30              
----------|---------|----------|---------|---------|-------------------

因此,看起来ava测试工具未获得nyc测试工具的输出。

简单的设置如下:

/* todo.js (uses ES6 modules) */

'use strict'

let data = []

function clear() {
    data = []
}

function add(item,qty = 1) {
    qty = Number(qty)
    if(isNaN(qty)) throw new Error('qty must be a number')
    data.push({item: item,qty: qty})
  return true
}

export { add,clear }
/* todo.spec.js */
import { add,clear } from './modules/todo.js'
import test from 'ava'

test('add a single item',test => {
  clear()
  const ok = add('bread')
  test.truthy(ok)
})

我尝试创建.nycrc.json文件,但这没有帮助:

{
  "check-coverage": true,"include": [
    "modules/todo.js"
  ],"reporter": ["text","html"]
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)