Meteor method timing out in cypress


#1

We’re running our end-to-end tests with cypress and we added this little helper to run methods from our tests directly:

Cypress.Commands.add('getMeteor', () =>
  cy.window().then(({ Meteor }) => {
    if (!Meteor) {
      // We visit the app so that we get the Window instance of the app
      // from which we get the `Meteor` instance used in tests
      cy.visit('/');
      return cy.window().then(({ Meteor: MeteorSecondTry }) => MeteorSecondTry);
    }
    return Meteor;
  }));

Cypress.Commands.add('callMethod', (method, ...params) => {
  Cypress.log({
    name: 'Calling method',
    consoleProps: () => ({ name: method, params }),
  });

  cy.getMeteor().then(Meteor =>
    new Cypress.Promise((resolve, reject) => {
      Meteor.call(
        method,
        ...params,
        (err, result) => {
          if (err) {
            reject(err);
          }

          resolve(result);
        },
      );
    }));
});

// Use it like this for example
beforeEach(() => {
  cy.callMethod('resetDatabase');
  cy.callMethod('generateTestData');
})

The issue we have, is that sometimes this Meteor.call never returns, i.e. the callback is never fired, even though on the meteor server, the code has been executed and the method has reached the end without errors.

It only happens for one specific method. I moved it to be server-only which made it run fine a few times, then it didn’t work again. I tried to use Meteor.apply and play around with the options which helped for a few runs and then it started failing again.

I really have no idea what I can try, which package might be causing some kind of error to be swallowed, or whatever else might be happening.

When a meteor method finishes executing, what happens next? Who/what could be preventing the callback from being fired?