[setupNodeEvents] on("before:spec", ()=>...) doesn't await the promise returned by the event handler
See original GitHub issueCurrent behavior
The promise returned by the event handler of before:spec
is not awaited but is run concurrently, alongside the spec.
Desired behavior
As specified in the docs here: https://docs.cypress.io/api/plugins/before-spec-api#Syntax, before:spec
is supposed to await the completion of the promise returned by it before running the spec.
Test code to reproduce
See https://github.com/ioannisNoukakis/cypress_before_spec_promise, contact me if any questions
Cypress Version
10.11.0
Node version
v16.17.0
Operating System
Manjaro 22.0.0 Sikaris - x86_64 Linux 5.15.74-3-MANJARO
Debug Logs
No response
Other
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Node.js Promise within event handler is not executing
As written in aws docs: If your code performs an asynchronous task, return a promise to make sure that it finishes running.
Read more >Before Run API - Cypress Documentation
You can return a promise from the before:run event handler and it will be awaited before Cypress proceeds running your specs.
Read more >Testing-library: avoid these mistakes in async tests
In our test, when we are calling render with await , JavaScript implicitly wraps the result into a promise and waits for it...
Read more >Use Promise.all to Stop Async/Await from Blocking Execution ...
Promises are extremely powerful for handling asynchronous operations in JavaScript. Async ... function getData() { // the Fetch API returns a Promise ......
Read more >javascript - await does not wait for Promise to finish
This is standard for asynchronous events in JavaScript. async functions always return a Promise which is not guaranteed to be resolved before ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ioannisNoukakis, thanks for logging this issue and providing the reproduction! I was able to reproduce the issue.
I am going to route this issue to the appropriate team.
Related to: https://github.com/cypress-io/cypress/issues/23627, https://github.com/cypress-io/cypress/issues/22360
@ioannisNoukakis We would love your contribution!