赛普拉斯测试覆盖率未检测

问题描述 投票:0回答:0

我一直在努力获得使用 Next.JS 应用程序的 e2e 测试的测试覆盖率。

我已经创建了基础应用程序

yarn create next-app --typescript --eslint --experimental-app

然后我跟着instrumentation documentation。这是我的设置:

  • package.json(仅限必备)
{
    "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"
    }
}
  • tsconfig.json
{
  "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"]
}
  • cypress.config.ts(限于必备)
import { defineConfig } from "cypress";

export default defineConfig({
    env: {

    },

    e2e: {
        setupNodeEvents(on, config) {
            require('@cypress/code-coverage/task')(on, config);
            return config;
        },
    },
});
  • .babelrc
{
    "presets": ["@babel/preset-env", "next/babel"],
    "plugins": ["istanbul"]
}
  • 柏树/支持/e2e.ts
import './commands'
import '@cypress/code-coverage/support'

当我运行测试时,它说代码未检测:

我也用

@bahmutov/cypress-code-coverage
包进行了测试,结果相似。

typescript next.js cypress code-coverage
© www.soinside.com 2019 - 2024. All rights reserved.