Cypress: run only one test

There are multiple ways of achieving this.

  1. You can add .onlyto it or describe see @bkucera answer
  2. You can do it from the terminal as explained in the doc here
     npx cypress run --record --spec "cypress/integration/my-spec.js"
    
     npm run cypress -- --record --spec "cypress/integration/my-spec.js"
    

You can run the test like this.

cypress run --spec **/file.js


You can mute not needed test suites and particular cases by prepending x to testrunner methods call (describe, it, etc.)

So it would look like:

// this whole testsuite will be muted
xdescribe('Visit google', () => { 
  it('should visit google', () => { cy.visit('https://google.com/'); });
});

// this testsuite will run
describe('Visit youtube', () => {
  it('should visit youtube', () => { cy.visit('https://youtube.com/'); });

  // this testcase will be muted
  xit('is not necessary', () => { ... });
});

to run only one file

cypress run --spec path/to/file.spec.js

or using glob patterns:

cypress run --spec 'path/to/files/*.spec.js'

Note: you need to wrap your glob patterns in single quotes to avoid shell expansion!

to run only one test in a file

You can use a .only as described in the Cypress docs

it.only('only run this one', () => {
  // similarly use it.skip(...) to skip a test
})

it('not this one', () => {
})

Also, you can do the same with describe and context blocks

edit:

there's also a nice VSCode extension to make adding/removing .only's easier with keyboard shortcuts. It's called Test Utils (install with ext install chrisbreiding.test-utils). It works with js, coffee, and typescript:

enter image description here