cypress-autorecord icon indicating copy to clipboard operation
cypress-autorecord copied to clipboard

The upstream server is always contacted, even if a stubbed request is provided

Open Sam152 opened this issue 2 years ago • 0 comments

Here is the code that sends the stubbed responses:

          (req) => {
            return req.reply((res) => {
              const newResponse = sortedRoutes[method][url][index];
              res.send(
                newResponse.status,
                newResponse.fixtureId

The docs of .reply() are:

    /**
     * Control the response to this request.
     * If a function is passed, the request will be sent outgoing, and the function will be called
     * with the response from the upstream server.
     * If a `StaticResponse` is passed, it will be used as the response, and no request will be made
     * to the upstream server.
     */
    reply(interceptor?: StaticResponse | HttpResponseInterceptor): void

Since a function is provided, the actual request is made and then it's merged with the fixture. This ends up failing tests where the origin is no longer accessible, like in CI environments.

Sam152 avatar May 12 '22 04:05 Sam152