cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.59k stars 3.15k forks source link

Task error propagation broken #18641

Open EtienneBruines opened 2 years ago

EtienneBruines commented 2 years ago

Current behavior

The error message is not shown:

  1) the issue
       something specific
         "before each" hook for "works":
     CypressError: `cy.task('some-bad-task')` failed with the following error:

> Error

https://on.cypress.io/api/task

Because this error occurred during a `before each` hook we are skipping the remaining tests in the current suite: `the issue`
      at http://localhost:38953/__cypress/runner/cypress_runner.js:158945:78
      at tryCatcher (http://localhost:38953/__cypress/runner/cypress_runner.js:13212:23)
      at Promise._settlePromiseFromHandler (http://localhost:38953/__cypress/runner/cypress_runner.js:11147:31)
      at Promise._settlePromise (http://localhost:38953/__cypress/runner/cypress_runner.js:11204:18)
      at Promise._settlePromise0 (http://localhost:38953/__cypress/runner/cypress_runner.js:11249:10)
      at Promise._settlePromises (http://localhost:38953/__cypress/runner/cypress_runner.js:11325:18)
      at _drainQueueStep (http://localhost:38953/__cypress/runner/cypress_runner.js:7919:12)
      at _drainQueue (http://localhost:38953/__cypress/runner/cypress_runner.js:7912:9)
      at Async.../../node_modules/bluebird/js/release/async.js.Async._drainQueues (http://localhost:38953/__cypress/runner/cypress_runner.js:7928:5)
      at Async.drainQueues (http://localhost:38953/__cypress/runner/cypress_runner.js:7798:14)
  From Your Spec Code:
      at Context.eval (http://localhost:38953/__cypress/tests?p=cypress/integration/test_spec.js:101:8)

  From Node.js Internals:
    Error
        at EventEmitter.handler (/home/etiennebruines/.cache/Cypress/8.7.0/Cypress/resources/app/packages/server/lib/plugins/util.js:69:27)
        at EventEmitter.emit (events.js:376:20)
        at ChildProcess.<anonymous> (/home/etiennebruines/.cache/Cypress/8.7.0/Cypress/resources/app/packages/server/lib/plugins/util.js:19:22)
        at ChildProcess.emit (events.js:376:20)
        at emit (internal/child_process.js:910:12)
        at processTicksAndRejections (internal/process/task_queues.js:83:21)

Desired behavior

The error message shown, e.g. the string Hello rejected world being present.

Test code to reproduce

// Register the task in plugins/index.js
on('task', {
    'some-bad-task': () => {
        return new Promise((resolve, reject) => {
            reject("Hello rejected world");
        })
    }
})

// Then later in some tests
describe('the issue', () => {
    beforeEach(() => {
        cy.task('some-bad-task')
    })  

    it('works', () => {

    })
})

Cypress Version

8.7.0

Other

No response

EtienneBruines commented 2 years ago

If I were to throw the Error instead of rejecting the Promise, Cypress would stop executing with the correct error message, but would require manually killing the process. (Which is a no-go in CI pipelines. We need the process to exit on errors, and give us an error we can work with.)

cypress-app-bot commented 1 year ago

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

cypress-app-bot commented 1 year ago

This issue has been closed due to inactivity.

kris-luminar commented 1 month ago

I'm still seeing this issue in Cypress version 13.12.0