我试图在此教程之后向柏树添加代码覆盖率
我将@cypress/code-coverage和babel-plugin-istanbul添加到下面的package.json文件中
{
"name": "quiz",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"cypress": "cypress open"
},
"dependencies": {
"next": "12.0.10",
"react": "17.0.2",
"react-dom": "17.0.2",
"sass": "^1.49.7"
},
"devDependencies": {
"@cypress/code-coverage": "^3.9.12",
"@types/node": "17.0.15",
"@types/react": "17.0.39",
"babel-plugin-istanbul": "^6.1.1",
"cypress": "^9.4.1",
"eslint": "8.8.0",
"eslint-config-next": "12.0.10",
"typescript": "4.5.5"
}
}我配置了我的cypress/support/index.js
// Import commands.js using ES2015 syntax:
import './commands'
// Alternatively you can use CommonJS syntax:
// require('./commands')
import '@cypress/code-coverage/support'我配置了我的cypress/plugins/index.js
/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
require('@cypress/code-coverage/task')(on, config)
on('file:preprocessor', require('@cypress/code-coverage/use-babelrc'))
return config
}我的.babelrc
{
"presets": [
"next/babel"
],
"plugins": [
"istanbul"
]
}运行测试后,我得到以下消息
Only found unit test code coverage. [@cypress/code-coverage]

运行quiz.spec.js测试之后,我将运行
npx nyc report --reporter=text-summary 并得到一个空的覆盖摘要

我做错了什么?
我的github
发布于 2022-02-17 04:17:58
我认为这只是一个node_modules问题,因为您的回购工作后,下载和初始化。我认为,如果巴贝尔的依赖关系出现故障,它可能会默默地失败。
我删除了package.lock (因为我使用yarn来管理事物),然后删除yarn来加入依赖关系。
https://stackoverflow.com/questions/71152128
复制相似问题