Cypress - Why adding testfiles names in jsconfig.json file are not executing in order

Viewed 86

I have added spec file names in jsconfig.json so that they can execute in order. But they are not executing in this order.

enter image description here

{
  "include": ["./node_modules/cypress", "cypress/**/*.js"],
  "testFiles":
  [
    "login.cy.js",
    "create_course.cy.js",
    "open_course.cy.js",
    "create_training.cy.js",
    "edit_pitch.cy.js"
  ]

 }

enter image description here

2 Answers

With specPattern, you can add a String or Array of glob patterns of the test files to load. Unfortunately, you won't be able to add the spec files in an array-like you can do in cypress version < 10 with testFiles.

An alternate way would be to keep the spec pattern as ["cypress/e2e/**/*.cy.{js,jsx,ts,tsx}"] and then rename your spec files to include sequential numbers so that they are executed in that sequence.

01-login.cy.js
02-create_course.cy.js
03-open_course.cy.js
04-create_training.cy.js
05-edit_pitch.cy.js

A better way to execute specs in order is to import them into a parent spec.

This also means you can run them together in the Cypress test runner (a feature removed in Cypress v10)

all-spec.cy.js

// run this spec to run the following in sequence

import './login.cy.js'
import './create_course.cy.js'
import './open_course.cy.js'
import './create_training.cy.js'
import './edit_pitch.cy.js'
Related