首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尽管向package.json提供了nyc配置,但nyc却什么也没有生成。

尽管向package.json提供了nyc配置,但nyc却什么也没有生成。
EN

Stack Overflow用户
提问于 2022-10-29 12:10:52
回答 1查看 27关注 0票数 0

我用纽约+摩卡有点麻烦。我的测试正在通过,但没有得到任何报告,尽管在我的包json中添加了一个nyc配置对象:

代码语言:javascript
复制
//package.json
{
  "name": "open-concepts",
  "version": "1.0.0",
  "description": "Simply matching idea makers and doers",
  "main": "app.js",
  "scripts": {
    "start": "nodemon --watch './**/*.ts' --exec 'ts-node-esm' app.ts",
    "test": "NODE_ENV='test' nyc mocha -r ts-node/register 'test/**/*.*.*.ts' --exit",
   },
"nyc": {
    "extends": "@istanbuljs/nyc-config-typescript",
    "check-coverage": true,
    "all": true,
    "include": [
      "test/**/*.*.[tj]s?(x)"
    ],
    "reporter": [
      "html",
      "lcov",
      "text",
      "text-summary",
      "cobertura"
    ],
    "report-dir": "coverage"
  }
}

当我运行测试时,我会得到以下错误:

代码语言:javascript
复制
 91 passing (4s)

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |                   
----------|---------|----------|---------|---------|-------------------

=============================== Coverage summary ===============================
Statements   : Unknown% ( 0/0 )
Branches     : Unknown% ( 0/0 )
Functions    : Unknown% ( 0/0 )
Lines        : Unknown% ( 0/0 )
================================================================================
runner.once is not a function <-- I don't know where this comes from...

我是不是在nyc配置中遗漏了什么?

蒂娅!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-01 11:28:51

我相信问题在于你的声明:

代码语言:javascript
复制
    "include": [ "test/**/*.*.[tj]s?(x)" ]

这应该与您希望接收覆盖率的src文件相对应,而不是测试文件本身。您可能希望将测试文件排除在覆盖率报告之外。

我在许多地方使用的nyc配置是:

代码语言:javascript
复制
"nyc": {
    "all": true,
    "extension": [
      ".ts",
      ".tsx"
    ],
    "exclude": [
      "**/*.d.ts",
      "**/*.js",
      "**/*.spec.ts"
    ],
    "reporter": [
      "text",
      "html",
      "cobertura"
    ],
    "require": ["ts-node/register"]
  }

所有.ts或.tsx文件都通过扩展名param包含,然后排除筛选我们的测试文件、一些生成的ts文件以及任何JS。

如果您只是在寻找JS文件覆盖率,则相应地切换扩展名param。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74245148

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档