Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining tasks out of cypress config file #25970

Closed
palcarazm opened this issue Feb 28, 2023 · 5 comments
Closed

Defining tasks out of cypress config file #25970

palcarazm opened this issue Feb 28, 2023 · 5 comments

Comments

@palcarazm
Copy link

What would you like?

In cypress config file add a list of filepaths containing task definition.

Why is this needed?

When using cucumber preprocesor all steps that hace todo use no de platform are broken except if you use cy.task().

When the test projet grow a large number of tasks can be defined in a single file. This is quite dificult to maintain.

Spliting task definition in some files will solve the issue.

Other

No response

@nagash77 nagash77 added the type: feature New feature that does not currently exist label Feb 28, 2023
@emilyrohrbough
Copy link
Member

@palcarazm This can already be accomplished in Cypress. You would be responding for defining. One way to do this is:

// cypress/support/tasks.js
const addTasks = (on) => {
  on('task', {
    task1(message) {
      console.log('task1', message)

      return null
    },

    task2(message) {
      console.log('task2', message)

      return null
    },
  })
}

module.exports = addTasks
// cypress.config.js
const addTasks = require('./cypress/support/tasks')

module.exports = {
    setupNodeEvents(on, config) {
      addTasks(on)
    },
}

@emilyrohrbough emilyrohrbough removed the type: feature New feature that does not currently exist label Apr 12, 2023
@palcarazm
Copy link
Author

palcarazm commented Apr 12, 2023

Hi @emilyrohrbough

Even if task are defined in multiple files?

I didn't find it in the doc.

// cypress/support/tasksA.js
const addTasksA = (on) => {
  on('task', {
    task1(message) {
      console.log('task1', message)
      return null
    },
    task2(message) {
      console.log('task2', message)
      return null
    },
  })
}
module.exports = addTasksA
// cypress/support/tasksB.js
const addTasksB = (on) => {
  on('task', {
    task3(message) {
      console.log('task3', message)
      return null
    },
    task4(message) {
      console.log('task4', message)
      return null
    },
  })
}
module.exports = addTasksB

@emilyrohrbough
Copy link
Member

If you have tasks across files, I'd suggest something like:

const addTaskA = {
    task1(message) {
      console.log('task1', message)
      return null
    },
    task2(message) {
      console.log('task2', message)
      return null
    },
}
const addTaskB = {
    task3(message) {
      console.log('task3', message)
      return null
    },
    task4(message) {
      console.log('task4', message)
      return null
    },
}
```js

```js
// cypress.config.js
const addTasksA = require('./cypress/support/tasksA')
const addTasksB = require('./cypress/support/tasksB')

module.exports = {
    setupNodeEvents(on, config) {
      on('task', {
          ...addTasksA,
          ...addTasksB,
    },
}

@emilyrohrbough
Copy link
Member

You cannot define multiple on('task') hooks. See #22428

@palcarazm
Copy link
Author

Okay thanks 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants