Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
Cypress choose what test file to launch based on a string

I am currently working in Cypress, I will try to semplify my question as much as possible:

I have several test files:

integration/testA.spec.js
integration/testB.spec.js
integration/testC.spec.js

I also have a config.js file in which I have an object containing the name of the test I want to run:

{
    test: 'testA.spec.js'
}

what I want to do - if possible - is a main.spec.js file that, depending on the testproperty, runs the relative spec file.

I have prepared almost everything

describe('Test', () => {
  before(() => {})

  beforeEach(() => {})

  after(() => {})

  describe('Test Booking', () => {
    // retrieves the `test`property and returns the string name
    let testName = retrieveTestName()
    console.log('testName', testName)

    /** I want to do something like this */
    if (testName === 'testA.spec.js') {
        // launch testA.spec.js file
    }
  }

})

but I ignore if I can do something like the code above; do you think is possible?

Or do I have to create a script file that

  • checks for the namefile
  • uses the --spec option and launches the test

?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

An option can be to create commands using the --spec file and add it under scripts in your package.json. Something like:

"scripts": {
  "testA": "npx cypress run --spec "cypress/integration/testA.spec.js",
  "testB": "npx cypress run --spec "cypress/integration/testB.spec.js",
  "testC": "npx cypress run --spec "cypress/integration/testC.spec.js"
}

You can run directly run the above command depending on the test you want to execute.

npm run testA
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!