Skip to content

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

@CamilleDrapier

Description

@CamilleDrapier

Versions

  • What is this plugin's version? If this is NOT the latest released version can you try the latest version, please? 3.10.7

  • What is Cypress version? 12.15.0, the problem doesn't seem to happen with 12.14.0

  • What is your operating system? Linux Manjaro

  • What is the shell? zsh

  • What is the Node version? v18.16.0

  • What is the NPM version? 9.6.6

  • How do you instrument your application? istanbul

  • When running tests, if you open the web application in regular browser, and open DevTools, do you see window.__coverage__ object? Can you paste a screenshot?

    Screenshot_20230621_104538

  • Is there .nyc_output folder? Is there .nyc_output/out.json file. Is it empty? Can you paste at least part of it so we can see the keys and file paths?
    All entries seem to looks the same with the form:

     "/home/camille/xdev/xxx/src/components/somefolder/SomeComponent.vue": {
       "path": "/home/camille/xdev/xxx/src/components/somefolder/SomeComponent.vue",
       "statementMap": {},
       "fnMap": {},
       "branchMap": {},
       "s": {},
       "f": {},
       "b": {}
     },
    
  • Do you have any custom NYC settings in package.json (nyc object) or in other NYC config files

     {
       "extends": "@istanbuljs/nyc-config-typescript",
       "all": true,
       "include": [
         "src/**/*.js",
         "src/**/*.ts",
         "src/**/*.vue"
       ],
       "exclude": [
         "**/types/*.ts",
         "**/types.ts",
         "**/*.d.ts",
         "**/*.spec.js",
         "**/*.spec.ts",
         "**/fixtures/*",
         "src/boot/*"
       ],
       "sourceMap": false,
       "instrument": false,
       "extension": [".js", ".ts", ".vue"],
       "report-dir": "test/cypress/coverage",
       "temp-dir": "test/cypress/coverage-cypress-output",
       "reporter": ["json", "text-summary", "lcov", "cobertura"]
     }
    
  • Do you run Cypress tests in a Docker container? no

Describe the bug
When running any test on my computer, even if the test seems to conclude properly, I get a failure and the following log:

CypressError
cy.task() must only be invoked from the spec file or support file.

Because this error occurred during a after each hook we are skipping all of the remaining tests.
node_modules/@cypress/code-coverage/support.js:20:1
  18 | 
  19 |   // stringify coverage object for speed
> 20 |   cy.task('combineCoverage', JSON.stringify(totalCoverage), {
     | ^
  21 |     log: false
  22 |   })
  23 | }

This works fine with cypress version 12.14; is there some specific thing to change, I have not seen anything specific related to this in the cypress changelog

This seems to fail both with chrome and chrome headless mode.

Link to the repo
I'm not sure this is entirely necessary, but if it is let me know and I will try to provide something.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions