即使在 cypress/fixtures 中定义,Cypress 也没有找到适合我的测试的装置

Bre*_*een -1 cypress cypress-custom-commands cypress-intercept

我的测试将灯具存储在 cypress/fixtures 中,但 Cypress 无法找到它们。这是项目结构。我使用的是 cypress 12.14.0 版本

       __tests__
           cypress
              e2e
                mySpec.ts
           fixtures
              accounts.json
           support
              command.ts
              types.d.ts 
           tsconfig.ts
           cypress.config.ts


Run Code Online (Sandbox Code Playgroud)
       __tests__
           cypress
              e2e
                mySpec.ts
           fixtures
              accounts.json
           support
              command.ts
              types.d.ts 
           tsconfig.ts
           cypress.config.ts


Run Code Online (Sandbox Code Playgroud)

这是我尝试访问夹具的方法

     
         // tsconfig.js
         {
            "compilerOptions": {
            "target": "es5",
            "lib": ["dom", "dom.iterable", "esnext"],
            "allowJs": true,
            "skipLibCheck": true,
            "esModuleInterop": true,
            "allowSyntheticDefaultImports": true,
            "strict": true,
            "module": "esnext",
            "moduleResolution": "node",
            "resolveJsonModule": true,
            "isolatedModules": true,
            "noEmit": true,
            "types": ["cypress","./support"]
            },
             "include": ["/**/*cy.ts", "**/**/*.ts"]
           }

        
          
           //cypress.config.ts
            import { defineConfig } from "cypress";

            export default defineConfig({
                projectId: "accounts-ui-tests",
                retries: {
                runMode: 2,
             },
             env: {
                accountDb: "accounts/db"
             },
             e2e: {
              baseUrl: "http://localhost:8083",
              defaultCommandTimeout: 5000,
              specPattern: "**/e2e/**/*.cy.{js,jsx,ts,tsx}",
              supportFile: "**/support/e2e.ts",
              fixturesFolder: "cypress/fixtures"
              viewportHeight: 1200,
              viewportWidth: 1280,

              setupNodeEvents(on, config) {
                return config;
              },
             }
          }); 

Run Code Online (Sandbox Code Playgroud)

我收到一个错误,在以下位置找不到accounts.json > cypress/fixtures/accounts.json

         > cypress/fixtures/users.json.[ext]

 ```
Run Code Online (Sandbox Code Playgroud)

它如何在 cypress/fixtures 中查找而找不到该文件?就在那里,我一次又一次地检查过。当我在测试 mySpec 的一处将其引用为 ../../fixtures/accounts.json 时,它起作用了,这告诉我 Cypress 只是没有通过其解析算法进行查找。当文档告诉您这是找到灯具的位置并且他们的示例也将它们放置在那里时,这是非常令人沮丧的。更糟糕的是,如果我将页面 index.html 放入文件夹中并使用 cy.visit('index.html') 访问它,它可以找到它。这绝对是荒谬的,否则就找不到它。这是一个错误吗?

请帮我解决这个疯狂的问题。到目前为止,我对 Cypress 的使用感到非常沮丧,我正准备向我的团队推荐其他产品,比如 Playwright,它在更容易采用方面似乎要好得多。

D.Z*_*gna 5

cypress将 fixtrues 文件夹移动到文件夹下方的常规位置

       __tests__
           cypress
              e2e
                mySpec.ts
             fixtures
                accounts.json
           support
              command.ts
              types.d.ts 
           tsconfig.ts
           cypress.config.ts
Run Code Online (Sandbox Code Playgroud)