我一直在努力获得使用 Next.JS 应用程序的 e2e 测试的测试覆盖率。
我已经创建了基础应用程序
yarn create next-app --typescript --eslint --experimental-app
然后我跟着instrumentation documentation。这是我的设置:
{
"scripts": {
"cypress:e2e": "cypress open --e2e"
},
"devDependencies": {
"@babel/core": "^7.21.3",
"@babel/preset-env": "^7.20.2",
"@cypress/code-coverage": "^3.10.0",
"@types/cypress": "^1.1.3",
"babel-loader": "^9.1.2",
"babel-plugin-istanbul": "^6.1.1",
"cypress": "^12.8.1"
}
}
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
import { defineConfig } from "cypress";
export default defineConfig({
env: {
},
e2e: {
setupNodeEvents(on, config) {
require('@cypress/code-coverage/task')(on, config);
return config;
},
},
});
{
"presets": ["@babel/preset-env", "next/babel"],
"plugins": ["istanbul"]
}
import './commands'
import '@cypress/code-coverage/support'
我也用
@bahmutov/cypress-code-coverage
包进行了测试,结果相似。