Function addTasks

  • Add cypress tasks defined as commands so that

    cy.task("doSomething", 1)
    // becomes
    cy.doSomething(1)

    with type support and go to definition IDE utils.

    // likely create object with `import * as tasks from ...`
    const tasks = { getUUID: () => 'a uuid' };
    addTasks(tasks);
    // type def, see above `addCommands` for further namespace extension details
    type Commands = typeof commands & Tasks<typeof tasks>;
    declare global { // ...

    Then also add tasks in cypress.config.ts

    import * as tasks from "./cypress/support/tasks";

    export default defineConfig({
    // ... other config
    setupNodeEvents: (on, config) => {
    on("task", tasks);
    },
    });

    afterwards, tasks will be available as commands that return well-typed promises

    cy.getUUID().then(uuid => ...)`
    

    Type Parameters

    • T extends {
          [event: string]: TaskFn;
      }

    Parameters

    • tasks: T

    Returns void