Nanciee / cypress-autorecord

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

Abnormal response when using fixtureId #59

Open MasterATM opened 3 years ago

MasterATM commented 3 years ago

Hello, (I repost it in a new issue rather than the old one #54)

When autorecord stubs requests with responses of big size, it returns the path of the fixture in the response to the client (see #54) instead of the real content itself.

I am using autorecord 3.1.2 + Cypress 8.3.1. 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.

kkhaidukov commented 2 years ago

@MasterATM would you mind to create a PR out of this? I'm experiencing the same issue, and your suggestion does indeed solve it for me locally.