我用纽约+摩卡有点麻烦。我的测试正在通过,但没有得到任何报告,尽管在我的包json中添加了一个nyc配置对象:
//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"
}
}当我运行测试时,我会得到以下错误:
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配置中遗漏了什么?
蒂娅!
发布于 2022-11-01 11:28:51
我相信问题在于你的声明:
"include": [ "test/**/*.*.[tj]s?(x)" ]这应该与您希望接收覆盖率的src文件相对应,而不是测试文件本身。您可能希望将测试文件排除在覆盖率报告之外。
我在许多地方使用的nyc配置是:
"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。
https://stackoverflow.com/questions/74245148
复制相似问题