Skip to content

Cannot read property "fireChangeEvent" of undefined when stubbing with route2 in Chrome #9170

Closed
@LoaderB0T

Description

@LoaderB0T

Current behavior

I am stubbing many (all) server calls for testing our web-app without the real server. As the server is not reachable, I also have to stub OPTIONS-method http calls.

My code looks something like this:

const preflightHeaders = {
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Expose-Headers': '*',
    'access-control-allow-headers': '*',
    'Access-Control-Request-Headers': '*',
    'Access-Control-Request-Method': '*',
    'Access-Control-Allow-Methods': '*'
};


cy.route2({ url: this._urlMatch }, (req) => {

  if (req.method.toUpperCase() === 'OPTIONS') {
    req.reply(200, undefined, preflightHeaders);
    return;
  }

  // [...Actual stubs here]
}

In many cases this works without any problem. With one specific test, I get this error:
Cypress tells me that this error originates from my test code and not from cypress itself. If that is true, I am very sorry for opening this issue. But in this case, I think this might be a bug in the experimental full network stubbing feature, especially since this problem only occurs in Chromium!

TypeError: The following error originated from your test code, not from Cypress.

  > Cannot read property 'fireChangeEvent' of undefined

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
    at sendContinueFrame (http://localhost:4200/__cypress/runner/cypress_runner.js:164493:17)
    at onRequestReceived (http://localhost:4200/__cypress/runner/cypress_runner.js:164497:12)
    at http://localhost:4200/__cypress/runner/cypress_runner.js:164283:14
From previous event:
    at $Cypress.<anonymous> (http://localhost:4200/__cypress/runner/cypress_runner.js:164281:56)
    at $Cypress.../driver/node_modules/eventemitter2/lib/eventemitter2.js.EventEmitter.emit (http://localhost:4200/__cypress/runner/cypress_runner.js:85136:19)
    at $Cypress.parent.<computed> [as emit] (http://localhost:4200/__cypress/runner/cypress_runner.js:172903:33)
    at Socket.<anonymous> (http://localhost:4200/__cypress/runner/cypress_runner.js:199515:17)
    at Socket.../socket/node_modules/component-emitter/index.js.Emitter.emit (http://localhost:4200/__cypress/runner/cypress_runner.js:187266:20)
    at Socket.../socket/node_modules/socket.io-client/lib/socket.js.Socket.onevent (http://localhost:4200/__cypress/runner/cypress_runner.js:193994:10)
    at Socket.../socket/node_modules/socket.io-client/lib/socket.js.Socket.onpacket (http://localhost:4200/__cypress/runner/cypress_runner.js:193952:12)
    at Manager.<anonymous> (http://localhost:4200/__cypress/runner/cypress_runner.js:187124:15)
    at Manager.../socket/node_modules/component-emitter/index.js.Emitter.emit (http://localhost:4200/__cypress/runner/cypress_runner.js:187266:20)
    at Manager.../socket/node_modules/socket.io-client/lib/manager.js.Manager.ondecoded (http://localhost:4200/__cypress/runner/cypress_runner.js:193450:8)
    at Decoder.<anonymous> (http://localhost:4200/__cypress/runner/cypress_runner.js:187124:15)
    at Decoder.../socket/node_modules/component-emitter/index.js.Emitter.emit (http://localhost:4200/__cypress/runner/cypress_runner.js:187266:20)
    at Decoder.../socket/node_modules/socket.io-circular-parser/index.js.Decoder.add (http://localhost:4200/__cypress/runner/cypress_runner.js:192098:12)
    at Manager.../socket/node_modules/socket.io-client/lib/manager.js.Manager.ondata (http://localhost:4200/__cypress/runner/cypress_runner.js:193440:16)
    at Socket.<anonymous> (http://localhost:4200/__cypress/runner/cypress_runner.js:187124:15)
    at Socket.../socket/node_modules/engine.io-client/node_modules/component-emitter/index.js.Emitter.emit (http://localhost:4200/__cypress/runner/cypress_runner.js:189743:20)
    at Socket.../socket/node_modules/engine.io-client/lib/socket.js.Socket.onPacket (http://localhost:4200/__cypress/runner/cypress_runner.js:187810:14)
    at WS.<anonymous> (http://localhost:4200/__cypress/runner/cypress_runner.js:187627:10)
    at WS.../socket/node_modules/engine.io-client/node_modules/component-emitter/index.js.Emitter.emit (http://localhost:4200/__cypress/runner/cypress_runner.js:189743:20)
    at WS.../socket/node_modules/engine.io-client/lib/transport.js.Transport.onPacket (http://localhost:4200/__cypress/runner/cypress_runner.js:188253:8)
logError @ cypress_runner.js:199876
(anonymous) @ cypress_runner.js:199531
emit @ cypress_runner.js:51548
(anonymous) @ cypress_runner.js:184636
emit @ cypress_runner.js:51548
emit @ cypress_runner.js:184676
onPrint @ cypress_runner.js:183587
_onPrintClick @ cypress_runner.js:183592
(anonymous) @ cypress_runner.js:184847
executeAction @ cypress_runner.js:49413
n @ cypress_runner.js:49413
ca @ cypress_runner.js:59945
ja @ cypress_runner.js:59946
ka @ cypress_runner.js:59946
wa @ cypress_runner.js:59948
Aa @ cypress_runner.js:59949
ya @ cypress_runner.js:59949
Da @ cypress_runner.js:59952
Ad @ cypress_runner.js:60015
Gi @ cypress_runner.js:60181
Kb @ cypress_runner.js:59970
Dd @ cypress_runner.js:60017
(anonymous) @ cypress_runner.js:60182
../../node_modules/scheduler/cjs/scheduler.production.min.js.exports.unstable_runWithPriority @ cypress_runner.js:64056
Ii @ cypress_runner.js:60182
Cd @ cypress_runner.js:60016

The error is thrown in this code excerpt in the cypress_runner.js:

  const sendContinueFrame = () => {
    if (continueSent) {
      throw new Error('sendContinueFrame called twice in handler');
    }

    continueSent = true;

    if (request) {
      request.state = 'Intercepted';
    }

    if (continueFrame) {
      // copy changeable attributes of userReq to req in frame
      // @ts-ignore
      continueFrame.req = { ...lodash__WEBPACK_IMPORTED_MODULE_0___default.a.pick(userReq, _types__WEBPACK_IMPORTED_MODULE_1__[/* SERIALIZABLE_REQ_PROPS */ "a"])
      };

      lodash__WEBPACK_IMPORTED_MODULE_0___default.a.merge(request.request, continueFrame.req);

      emitNetEvent('http:request:continue', continueFrame);
    }

    request.log.fireChangeEvent(); // <--- Error here
  };

Any idea why "log" is missing in some cases?

Desired behavior

No exception when (an OPTIONS) http call is intercepted.

Test code to reproduce

Sadly, I cannot share the project that this error occurred in, I might be able to reproduce this in a fresh repo, if required I will add that later.

Versions

Found in:
Cypress 5.6.0
Chrome 86 & Edge Dev 88
Windows 10

Works in Firefox 80

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions