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

cy.task() doesn't work with new Cypress version 12.15.0 #27099

Closed
Pavel-Lahutsin opened this issue Jun 21, 2023 · 7 comments · Fixed by #27122
Closed

cy.task() doesn't work with new Cypress version 12.15.0 #27099

Pavel-Lahutsin opened this issue Jun 21, 2023 · 7 comments · Fixed by #27122
Assignees

Comments

@Pavel-Lahutsin
Copy link

Pavel-Lahutsin commented Jun 21, 2023

Current behavior

With the latest Cypress version 12.15.0 cy.task() is broken. It says "cy.task() must only be invoked from the spec file or support file."

12 15 0
documentation

Desired behavior

It should work as in previous Cypress version

Test code to reproduce

cypress.config.js

const { defineConfig } = require('cypress')

module.exports = defineConfig({
  // setupNodeEvents can be defined in either
  // the e2e or component configuration
  e2e: {
    setupNodeEvents(on, config) {
      on('task', {
        log(message) {
          console.log(message)

          return null
        },
      })
    },
  },
})

spec.cy.js

describe("Test for bug ", () => {
    it(`should be working`, () => {
        cy.task('log', 'This will be output to the terminal')
    })
});

Cypress Version

12.15.0

Node version

16.15

Operating System

win10

Debug Logs

No response

Other

No response

@Phonesis
Copy link

Getting this too, seems like major issue

@Phonesis
Copy link

Further to this, it breaks stuff like the cypress code coverage lib because that uses cy.task() in an afterHook

@Pavel-Lahutsin Pavel-Lahutsin changed the title cy.task() doesn't work in new Cypress version 12.15.0 cy.task() doesn't work with new Cypress version 12.15.0 Jun 21, 2023
@elGatoMantocko
Copy link

elGatoMantocko commented Jun 21, 2023

It looks like this is also breaking cypress-localstorage-commands as well. We are seeing errors when invoking cy.saveLocalStorage() from that lib.

CypressError: `cy.task()` must only be invoked from the spec file or support file.
      at <unknown> (http://localhost:4200/__cypress/runner/cypress_runner.js:151183:80)
      at tryCatcher (http://localhost:4200/__cypress/runner/cypress_runner.js:18744:23)
      at Promise._settlePromiseFromHandler (http://localhost:4200/__cypress/runner/cypress_runner.js:16679:31)
      at Promise._settlePromise (http://localhost:4200/__cypress/runner/cypress_runner.js:16736:18)
      at Promise._settlePromise0 (http://localhost:4200/__cypress/runner/cypress_runner.js:16781:10)
      at Promise._settlePromises (http://localhost:4200/__cypress/runner/cypress_runner.js:16857:18)
      at _drainQueueStep (http://localhost:4200/__cypress/runner/cypress_runner.js:13451:12)
      at _drainQueue (http://localhost:4200/__cypress/runner/cypress_runner.js:13444:9)
      at ../../node_modules/bluebird/js/release/async.js.Async._drainQueues (http://localhost:4200/__cypress/runner/cypress_runner.js:13460:5)
      at Async.drainQueues (http://localhost:4200/__cypress/runner/cypress_runner.js:13330:14)
  From Your Spec Code:
      at LocalStorage._clearNodeSnapshot (webpack:///./node_modules/cypress-localstorage-commands/src/LocalStorage.js:92:0)
      at LocalStorage.clearLocalStorageSnapshot (webpack:///./node_modules/cypress-localstorage-commands/src/LocalStorage.js:104:0)
      at LocalStorage.saveLocalStorage (webpack:///./node_modules/cypress-localstorage-commands/src/LocalStorage.js:109:0)

Locking our cypress version to 12.14.0 allows our tests to run.

@mike-plummer
Copy link
Contributor

Hi everyone. We're aware of this issue and are looking into it now. Until a fix is identified, tested, and released you can temporarily downgrade to Cypress v12.14.0 which does not exhibit this issue.

@JomyGeo
Copy link

JomyGeo commented Jun 22, 2023

@mike-plummer I am getting the same issue for the 12.4.0 version

Issue 1 :
PayloadTooLargeError: request entity too large
at p (:2319:1358)
at s.exports (:2319:799)
at s.exports (:2338:1577)
at :2358:2007
at a.handle_request (:2640:1038)
at d (:2655:1285)

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

Issue 3 : CypressError: cy.writeFile() must only be invoked from the spec file or support file.

@arundavid1987
Copy link

arundavid1987 commented Jun 22, 2023

Issue in 12.5.0 and 12.4.0 as well for cy.readFile()

image

Works: Older version of node.js also does not work

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jun 26, 2023

Released in 12.16.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v12.16.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jun 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants