Nextjs Cypress 只发现单元测试代码覆盖率
Nextjs Cypress Only found unit test code coverage
我正尝试在这个 tutorial
之后为 cypress 添加代码覆盖率
我在下面的 package.json
文件中添加了 @cypress/code-coverage
和 babel-plugin-istanbul
{
"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
我认为这只是一个 node_modules 问题,因为您的存储库在下载和初始化后有效。我认为如果 babel 的依赖项出现问题,它可能会无提示地失败。
我删除了 package.lock
(因为我使用 yarn
来管理事物)然后 yarn
来初始化依赖项。
我正尝试在这个 tutorial
之后为 cypress 添加代码覆盖率我在下面的 package.json
文件中添加了 @cypress/code-coverage
和 babel-plugin-istanbul
{
"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
我认为这只是一个 node_modules 问题,因为您的存储库在下载和初始化后有效。我认为如果 babel 的依赖项出现问题,它可能会无提示地失败。
我删除了 package.lock
(因为我使用 yarn
来管理事物)然后 yarn
来初始化依赖项。