Cypress with MeteorJS: user does not stay logged in

I did it like so:

  1. Create a module that is loaded only when you are running integration tests
  2. In this module, create a client side function createTestUser that calls Meteor’s Account.createUser with credentials you wish to use, so a fresh user is created for each test
  3. Assign this function to window
  4. Create a Cypress command login, something like this:
function login(win) {
   win.createTestUser().then(() => win.appReady = true);
}

Cypress.Commands.add('login', () => {
  cy.visit('/'); // load the app
  cy.window().then(login); // create user
  cy.window().should('have.property', 'appReady', true); // wait for the user to get created
});
  1. Use this command in the beforeEach hooks of your Cypress tests