ค้นหาเว็บไซต์

typescript - การครอบคลุมการทดสอบ Cypress ไม่ได้รับการติดตั้งเครื่องมือ


ฉันกำลังประสบปัญหาในการทำให้การครอบคลุมการทดสอบบนการทดสอบ e2e ทำงานกับแอปพลิเคชัน Next.JS

ฉันได้สร้างแอปพลิเคชันพื้นฐานด้วย

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

จากนั้นฉันก็ทำตามเอกสารการติดตั้งเครื่องมือ นี่คือการตั้งค่าของฉัน:

  • 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 ด้วยเช่นกันและได้ผลลัพธ์ที่คล้ายกัน