Testing with Cypress

Hi, I am just trying to get Cypress up and running but it seems to get stuck in a loop talking to Meteor. I followed the guide here

As you can see, it has been spinning away for over 10 minutes.

Here’s the spec:

describe('sign-up', _ => {
  before(_ => {

  it('should create and login a new user', _ => {
    // submit signup form
    // should redirect to home page
    cy.url().should('eq', 'http://localhost:3000/');

    // user exists and is now logged in
    cy.window().then(win => {
      // this allows accessing the window object within the browser
      const user = win.Meteor.user();

Do I need to do something special in the before hook to get Cypress and Meteor to work together? I’m running the latest Meteor version.

Thank you for any help!

That looks fine to me. Have you tried restarting it ?

I don’t think it’s related but check out using baseUrl and prefer regular function() to ()=> . See this for more details.

We have been using cypress for a while without issues. Does it error out at some point? Usually there is a timeout that prevents waiting for 10 minutes.

Switching to regular functions fixed it, thanks!

Here’s the weird part:

_ => { ... }       // doesn't work
function() { ... } // works
() => { ... }      // works!?

If I would have just copy pasted the code from the article I linked it would have worked, but my _ messed it up. Cypress must use lodash or something that’s my only idea.

I’m also curious what people do for test DB data. Should I be running Cypress in Meteor test mode or just code up the db resets in pre/post hooks?

Like for my signup example, would I destroy the user after the test runs so I can run it again?

Yeah, that’s odd, but glad you fixed it.

I have a file with all the fixtures in it and I just import it before each group of tests.

Cypress.Commands.add("resetDb", () => {
    const mongoport = 3001;
        `mongorestore --host localhost:${mongoport}  --drop --gzip --archive=./tests/testFixtures.agz`

And I don’t recommend running in test mode as that requires specifying the test driver etc. We just run it in development mode but use our own environment settings to see it’s in testing mode.

By importing the db you’ll have effectively destroyed that user, so no need to explicitly destroy it.

1 Like

The last sentence of the article:

With this tutorial, you can now set up top-notch e2e testing with cypress without the hassle of setting up anything else than meteor on your CI server

Is this not quite right? I don’t seem to have mongodb or mongodb-tools installed, which seems weird because I would assume meteor installs mongo.

So I would need to install mongo on my dev machine and on a staging server if I wanted CI? Am I missing a way of just using the mongo installation that comes with meteor?

Just to clarify my issue:

/bin/bash: mongo: command not found

Thank you again for the help!

Meteor ships with mongod so you don’t need to install that. I’m not sure where you’re trying to run mongo - but the command wouldn’t be on your path by default - it’s in .meteor/local/dev_bundle/mongodb/bin

But if you want to use my approach to resetting the DB you would need to have mongo-tools availabe as well - which contains mongorestore and dump.