Nanciee / cypress-autorecord

Simplify API mocking by auto-recording/stubbing HTTP interactions and automating the process of updating/deleting mocks.
223 stars 52 forks source link

FixtureId is not working with req.reply #54

Closed ErichSA closed 3 years ago

ErichSA commented 3 years ago

Cypress is not returning the fixture index.js line 169: req.reply(response.status, newResponse, response.headers); It's returning the fixture folder instead. image Changing it to:

let newResponse = response.response;
            if (response.fixtureId) {
              newResponse = {
                statusCode: response.status,
                fixture: `${fixturesFolderSubDirectory}/${response.fixtureId}.json`
              };
            }
req.reply(newResponse, response.headers);

Everything works.

ErichSA commented 3 years ago

Can I open a PR? This is the cypress documentation: image https://docs.cypress.io/api/commands/intercept#Request-Response-Modification-with-routeHandler

MasterATM commented 3 years ago

Hello, I got the same problem as initially described despite using the latest 3.1.2 version. The signature for res.send is different if we want to reply with either the direct response or a fixture.

If if modify the code to this, then it works:

            req.reply((res) => {
              const newResponse = sortedRoutes[method][url][index];
              if (newResponse.fixtureId) {
                res.send(
                  {
                        fixture: `${fixturesFolderSubDirectory}/${newResponse.fixtureId}.json`,
                        headers: newResponse.headers,
                        statusCode: newResponse.status
                  }
                );  
              } else {
                res.send(
                  newResponse.status,
                  newResponse.response,
                  newResponse.headers,
                );  
              }

Thanks.