0

Here's my test in ./tests/homepage.test.js

context('Signup flow', () => {
    it('The happy path should work', () => {
        cy.visit('https://grazily.com/register');
        const random = Math.floor(Math.random() * 100000);
        cy.get('[data-testid=username]').type(`Tester${random}`);
        cy.get('[data-testid=email]').type(`user+${random}@realworld.io`);
        cy.get('[data-testid=password]').type('mysupersecretpassword');
        cy.get('[data-testid=signup-button]').click();
        cy.get('[data-testid=no-articles-here]', { timeout: 10000 }).should('be.visible');

Here's the file ./cypress/support/commands.js

import '@testing-library/cypress/add-commands';

tsconfig.json:

"compilerOptions": {
        "types": ["cypress", "@testing-library/cypress"],
...
}

I didn't make any other changes...and get this error when running npm t

I think t uses jest ./src so I'm not sure how to invoke cypress in ./tests/*test.js folder

Update:

Your pluginsFile is invalid: /home/ettinger/src/oblivion/Catalyze-frontend/cypress/plugins/index.js

Getting this error now with cypress run test

TesterDick
  • 3,830
  • 5
  • 18
chovy
  • 72,281
  • 52
  • 227
  • 295

2 Answers2

1

You're correct, npm t runs a predefined command specified in the "test" property of a package's "scripts" object.

//package.json
{
  ...
  "scripts": {
    "test": "jest"
  }
}

so you can either change "jest" to "cypress run" or add extra scripts, for example

//package.json
{
  ...
  "scripts": {
    "test": "jest",
    "e2e": "cypress run",
    "cy:open": "cypress open",
  }
}

or just run "npx cypress open" instead of "npm t".

BTW context(...) is valid in a Cypress test.

Fody
  • 23,754
  • 3
  • 20
  • 37
  • Do you know what I should put in `cypress.json`? It fails saying file doesn't exist. – chovy Apr 16 '22 at 02:47
  • `Your pluginsFile is invalid: /home/user/src/frontend/cypress/plugins/index.js` -- i don't have this file. – chovy Apr 16 '22 at 02:47
  • If you install Cypress and run it (`npx cypress open`), it set's up both (empty) `cypress.json` and all requisite folders and files under `/home/user/src/frontend/cypress`. – Fody Apr 16 '22 at 03:04
  • how to i tell it to look in `./tests/**/*.test.js` path? I got it working but it seems to be using TODO MVC code which is in ./cypress/ somewhere. – chovy Apr 16 '22 at 03:12
  • nevermind. i see it has a recommended folder layout. I'll just stick with that. – chovy Apr 16 '22 at 03:20
  • 1
    You're looking for [How to make Cypress use test files located outside of default integration folder?](https://stackoverflow.com/questions/71816653/how-to-make-cypress-use-test-files-located-outside-of-default-integration-folder) – Fody Apr 16 '22 at 03:27
0

Getting this error now with cypress run test

If you are trying to run a specific test, add --spec

npm run cypress run --spec my-test.spec.js
Visal
  • 537
  • 1
  • 6