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

When error within 'test:after:run', Cypress hangs instead of throwing the error. #2271

Closed
mjhea0 opened this issue Aug 3, 2018 · 11 comments · Fixed by #8709
Closed

When error within 'test:after:run', Cypress hangs instead of throwing the error. #2271

mjhea0 opened this issue Aug 3, 2018 · 11 comments · Fixed by #8709
Assignees

Comments

@mjhea0
Copy link

mjhea0 commented Aug 3, 2018

Current behavior:

test:after:run hangs

Steps to reproduce:

Sample test:

Cypress.on('test:after:run', () => {
  throw new Error('foo');
});

describe('Test 2', () => {
  it('will send out request', ()  => {
    expect(true).to.eq(true);
  });
});

Meanwhile, this works fine:

Cypress.on('test:before:run', () => {
  throw new Error('foo');
});

describe('Test 1', () => {
  it('will send out request', ()  => {
    expect(true).to.eq(true);
  });
});

What am I missing?

Versions

  • Operating System: Mac OS 10.12.6
  • Cypress Version: 3.0.3
  • Browser Version: Chrome 68.0.3440.75
@jennifer-shehane
Copy link
Member

What do you mean by 'hangs'? How are you currently running Cypress, through the Command Line, Module API, ? Do you have a screenshot or any error logs to post?

Also, if running through the command log, could you capture some debug logs? https://on.cypress.io/debugging#Debug-the-Command-Line

@mjhea0
Copy link
Author

mjhea0 commented Aug 3, 2018

The run starts but never finishes.

I'm running it via:

DEBUG=cypress:* ./node_modules/.bin/cypress run

From the logs, the test run continues to run and it looks like it crashes. This is the end of the logs:

 cypress:server:video capture stderr log { message: 'frame=  574 fps= 33 q=12.0 size=     256kB time=00:00:22.40 bitrate=  93.6kbits/s dup=360 drop=0 speed= 1.3x    ' } +599ms
  cypress:server:video capture stderr log { message: 'frame=  588 fps= 33 q=12.0 size=     256kB time=00:00:22.96 bitrate=  91.4kbits/s dup=368 drop=0 speed=1.29x    ' } +599ms
  cypress:server:video capture stderr log { message: 'frame=  603 fps= 33 q=12.0 size=     256kB time=00:00:23.56 bitrate=  89.0kbits/s dup=377 drop=0 speed=1.28x    ' } +600ms
  cypress:server:video capture stderr log { message: 'frame=  618 fps= 33 q=12.0 size=     256kB time=00:00:24.16 bitrate=  86.8kbits/s dup=386 drop=0 speed=1.27x    ' } +636ms
  cypress:server:video capture stderr log { message: 'frame=  631 fps= 32 q=12.0 size=     256kB time=00:00:24.68 bitrate=  85.0kbits/s dup=394 drop=0 speed=1.26x    ' } +463ms
  cypress:server:timers clearing timer id 21 from queue { '21': { args: [], ms: 85000, cb: [Function] } } +457ms
  cypress:server:timers queuing timer id 22 after 85000 ms +0ms
  cypress:server:timers child received timer id 22 +23s
  cypress:server:video capture stderr log { message: 'frame=  645 fps= 32 q=12.0 size=     256kB time=00:00:25.24 bitrate=  83.1kbits/s dup=402 drop=0 speed=1.26x    ' } +144ms
  cypress:server:video capture stderr log { message: 'frame=  661 fps= 32 q=12.0 size=     256kB time=00:00:25.88 bitrate=  81.0kbits/s dup=412 drop=0 speed=1.25x    ' } +601ms
  cypress:server:video capture stderr log { message: 'frame=  676 fps= 32 q=12.0 size=     256kB time=00:00:26.48 bitrate=  79.2kbits/s dup=421 drop=0 speed=1.24x    ' } +598ms
  cypress:server:video capture stderr log { message: 'frame=  691 fps= 32 q=12.0 size=     256kB time=00:00:27.08 bitrate=  77.5kbits/s dup=430 drop=0 speed=1.24x    ' } +598ms
  cypress:server:video capture stderr log { message: 'frame=  706 fps= 31 q=12.0 size=     256kB time=00:00:27.68 bitrate=  75.8kbits/s dup=439 drop=0 speed=1.23x    ' } +844ms
  cypress:server:timers child sending timer id 4 +4s
  cypress:server:video capture stderr log { message: 'frame=  748 fps= 31 q=12.0 size=     256kB time=00:00:29.36 bitrate=  71.4kbits/s dup=479 drop=0 speed=1.21x    ' } +3s
  cypress:server:video capture stderr log { message: 'frame=  778 fps= 31 q=12.0 size=     256kB time=00:00:30.56 bitrate=  68.6kbits/s dup=508 drop=0 speed= 1.2x    ' } +84ms
  cypress:server:video capture stderr log { message: 'frame= 1036 fps= 29 q=12.0 size=     256kB time=00:00:40.88 bitrate=  51.3kbits/s dup=762 drop=0 speed=1.14x    ' } +10s
  cypress:server:timers clearing timer id 22 from queue { '22': { args: [], ms: 85000, cb: [Function] } } +9s
  cypress:server:timers queuing timer id 23 after 85000 ms +0ms
  cypress:server:timers child received timer id 23 +21s
  cypress:server:video capture stderr log { message: 'frame= 1270 fps= 28 q=12.0 size=     512kB time=00:00:50.24 bitrate=  83.5kbits/s dup=994 drop=0 speed=1.11x    ' } +235ms
  cypress:server:video capture stderr log { message: 'Past duration 0.999992 too large' } +10s
  cypress:server:video capture stderr log { message: 'More than 1000 frames duplicated' } +3s
  cypress:server:video capture stderr log { message: 'frame= 1532 fps= 28 q=12.0 size=     512kB time=00:01:00.72 bitrate=  69.1kbits/s dup=1252 drop=0 speed=1.09x    ' } +212ms
  cypress:server:video capture stderr log { message: 'frame= 1604 fps= 27 q=12.0 size=     512kB time=00:01:03.60 bitrate=  66.0kbits/s dup=1323 drop=0 speed=1.08x    ' } +69ms
  cypress:server:timers clearing timer id 23 from queue { '23': { args: [], ms: 85000, cb: [Function] } } +11s
  cypress:server:timers queuing timer id 24 after 85000 ms +0ms
  cypress:server:timers child received timer id 24 +25s
  cypress:server:video capture stderr log { message: 'frame= 1866 fps= 27 q=12.0 size=     512kB time=00:01:14.08 bitrate=  56.6kbits/s dup=1583 drop=0 speed=1.07x    ' } +248ms
  cypress:server:video capture stderr log { message: 'frame= 1895 fps= 27 q=12.0 size=     512kB time=00:01:15.24 bitrate=  55.8kbits/s dup=1611 drop=0 speed=1.07x    ' } +41ms

@jennifer-shehane
Copy link
Member

Yeah, you can even run in the UI and see that the timer of the tests just continues to run forever.

forever-gif

Some of the problem here is that it is after the test has run and we don't have a test to associate anymore. What would you expect to do in the after:test:run when you throw?

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Aug 3, 2018
@mjhea0
Copy link
Author

mjhea0 commented Aug 5, 2018

I'm throwing an error to test out the after:test:run event. Right now I am just trying to get some sort of code to run. Do you have an example of this event that works?

@brian-mann
Copy link
Member

We don't expect anything to throw in this event because well... its after the test has run. Since all failures / unhandled exceptions need to be caught and associated to a test, it is tricky.

We could fail the last test ran, but that would change its status from passing -> fail and would likely confuse the mocha reporters, but at least we'd be able to account for it.

Alternatively we could await this before arriving at the final status of a test and therefore not set its status until this event goes through.

@mjhea0
Copy link
Author

mjhea0 commented Aug 6, 2018

The throw was just to see if things were working. It hangs when I run a basic function at this point as well:

Cypress.on('test:before:run', () => {
  alertMyManagerOfTheBrokenTests();
});

Perhaps a callback function; or, if absent, maybe only allow 2 seconds of execution?

@jennifer-shehane jennifer-shehane added stage: needs investigating Someone from Cypress needs to look at this and removed stage: needs information Not enough info to reproduce the issue labels Aug 10, 2018
@jennifer-shehane
Copy link
Member

This is still an issue in 4.9.0.

@saki2rules
Copy link

saki2rules commented Jul 22, 2020

Cypress.on('test:after:run', (test, runnable) => {
    if (test.state === 'failed') {
      let item = runnable
      const nameParts = [runnable.title]

      // Iterate through all parents and grab the titles
      while (item.parent) {
        nameParts.unshift(item.parent.title)
        item = item.parent
      }

      const fullTestName = nameParts
              .filter(Boolean)
              .join(' -- ')           // this is how cypress joins the test title fragments

      const imageUrl = `screenshots/${
        Cypress.spec.name
      }/${fullTestName} (failed).png`

      addContext({ test }, imageUrl)
    }
  })

The above code is used to put the failed test's screenshot in the mochawesome reports

It works as expected, but when there is a failure in the test, it gets stuck in the after hook

"after each" hook in "{root}"

I found this issue to be related. Any work around for the above problem ?

@jennifer-shehane - Is this bug under consideration for fix in the future versions ?

@jennifer-shehane jennifer-shehane changed the title test:after:run is hanging When error within 'test:after:run', Cypress hangs instead of throwing the error. Aug 21, 2020
@jennifer-shehane
Copy link
Member

This becomes more problematic when you write things like below, because you don't really realize you're referencing some variable that doesn't exist:

Cypress.on('test:after:run', (test) => {
  test.error // should throw as undefined
})

it('test', () => {
  expect(true).to.be.false
})

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 2, 2020

The code for this is done in cypress-io/cypress#8709, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 14, 2020

Released in 5.4.0.

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

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

Successfully merging a pull request may close this issue.

5 participants