Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

115
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda