Skip to content

Error: "cy.task() must only be invoked from the spec file or support file" when calling cy.task() #29192

Open
@distante

Description

@distante

Current behavior

When overwritten cy.log, cy.task can not be called because it fails with > cy.task() must only be invoked from the spec file or support file.

  Cypress.Commands.overwrite('log', (subject, message) =>
    cy.task('cyLog', message)
  );

Desired behavior

That code can be used as it was before.

Test code to reproduce

on commands.ts:

  Cypress.Commands.overwrite('log', (subject, message) =>
    cy.task('cyLog', message)
  );

on index-ts

  on(`task`, {
    cyLog(message) {
      // eslint-disable-next-line no-console
      console.log(ansi.magenta('cy.log:'), ansi.magenta(message));

      return null;
    },
  });

Cypress Version

13.6.4

Node version

v20.11.0

Operating System

macOS 14.4

Debug Logs

No response

Other

This issue should be similar to the closed #28336.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions