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
Comments
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 |
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:
|
I'm throwing an error to test out the |
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. |
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? |
This is still an issue in 4.9.0. |
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
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 ? |
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
}) |
The code for this is done in cypress-io/cypress#8709, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior:
test:after:run
hangsSteps to reproduce:
Sample test:
Meanwhile, this works fine:
What am I missing?
Versions
The text was updated successfully, but these errors were encountered: