-1

My tests store fixtures in cypress/fixtures but Cypress in unable to find them. Here is the project structure. I am using version 12.14.0 of cypress

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


     
         // 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;
              },
             }
          }); 

Here is how I try to access the fixture


            //In commands.ts

            Cypress.Commands.add('findAccounts',() => {
              cy.fixture('accounts.json').then((users) =>{
              const accounts = users.map((user: { accountId: any; })  => user.accountId)
              return cy.request("POST", 
               Cypress.env("baseUrl")+'user/accounts', {
                accounts: accounts
               }).then( (response) =>{
                  expect(response.status).to.eq(200)
               })
            })    
          })

I get an error that accounts.json could not be found in the following locations ``` > cypress/fixtures/accounts.json

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

 ```

How can it look in cypress/fixtures and not find the file? It's there I've check again and again. When I referenced it in one place in my test mySpec as ../../fixtures/accounts.json, it worked which tells me that Cypress is just not finding through its resolution algorithm. it's very frustrating when the document tells you that's where the fixtures are found and their examples also place them there. What's worse if I put a page index.html in the folder and access it with cy.visit('index.html') it can find it. It's absolutely ridiculous it can't find it otherwise. Is this a bug?

Please help me resolve this insanity. I'm very frustrated with using Cypress so far and I'm on the verge of recommending some other product to my team like Playwright which seems a lot better in terms of its easier adoption.

BreenDeen
  • 623
  • 1
  • 13
  • 42

1 Answers1

3

Move your fixtrues folder to the conventional place, underneath the cypress folder

       __tests__
           cypress
              e2e
                mySpec.ts
             fixtures
                accounts.json
           support
              command.ts
              types.d.ts 
           tsconfig.ts
           cypress.config.ts
  • If you read my explanation my fixtures folder is in the cypress folder. I will fix the indentation to properly reflect that – BreenDeen Jun 26 '23 at 04:00
  • Just as an FYI, your proposal doesn't work because my fixtures folder is aready in the Cypress folder – BreenDeen Jun 27 '23 at 12:21