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

fix: handle async before:spec event handler #26055

Merged
merged 24 commits into from
Mar 13, 2023

Conversation

emilyrohrbough
Copy link
Member

Correctly await async before:spec event handlers per the documentation specifications.

PR Tasks

@cypress
Copy link

cypress bot commented Mar 8, 2023

30 flaky tests on run #44687 ↗︎

0 26874 1281 0 Flakiness 30

Details:

missed test updates
Project: cypress Commit: ca2385826e
Status: Passed Duration: 18:53 💡
Started: Mar 10, 2023 2:40 PM Ended: Mar 10, 2023 2:58 PM
Flakiness  create-from-component.cy.ts • 1 flaky test • app-e2e

View Output Video

Test Artifacts
... > runs generated spec Output Screenshots Video
Flakiness  specs_list_latest_runs.cy.ts • 1 flaky test • app-e2e

View Output Video

Test Artifacts
App/Cloud Integration - Latest runs and Average duration > when no runs are recorded > shows placeholders for all visible specs Output Screenshots Video
Flakiness  cypress-origin-communicator.cy.ts • 1 flaky test • app-e2e

View Output Video

Test Artifacts
Cypress In Cypress Origin Communicator > cy.origin passivity with app interactions > passes upon test reload mid test execution Output Screenshots Video
Flakiness  global-mode.cy.ts • 1 flaky test • launchpad-e2e

View Output Video

Test Artifacts
... > can be opened Output Screenshots Video
Flakiness  commands/net_stubbing.cy.ts • 1 flaky test • 5x-driver-chrome

View Output Video

Test Artifacts
network stubbing > intercepting request > can delay and throttle a StaticResponse Output Video

The first 5 flaky specs are shown, see all 17 specs in Cypress Cloud.

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

packages/server/lib/socket-base.ts Show resolved Hide resolved
project: 'plugin-after-spec-deletes-video',
spec: '*',
project: 'plugin-run-events',
// project: 'plugin-after-spec-deletes-video',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove comment

onMounted(() => {
// watch active spec, and re-run if it changes!
startSpecWatcher()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why we needed to wait until the element was rendered to call this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is left over from attempts in trying to correct this behavior in open mode. changing back for now. but my original thought was there wasn't any. need to watch if a spec was changes from a user in the app if the content wasn't mounted & rendered yet.

@@ -361,19 +360,31 @@ export class EventManager {
}

setup (config) {
Cypress = this.Cypress = this.$CypressDriver.create(config)
this.ws.emit('watch:test:file', config.spec)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to watch the test file during run mode? This sounds like an open mode specific thing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eg should this be under the check on line 365-368?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It likely should but that is outside of the scope of this change and would require additionally testing. Going to leave as it for the PR.

this.ws.emit('watch:test:file', config.spec)
resolve(null)
})
}).then(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can (probably) just use async/await here (if you want, that is - I don't think this part is impacted by the whole "async doesn't work properly" since this is outside of the driver, but either way is fine by me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The async won't work properly concept is tied to writing Cypress tests, not the code so await should work fine.

@lmiller1990 lmiller1990 requested a review from a team March 9, 2023 04:37
@lmiller1990
Copy link
Contributor

I will assign @cypress-io/component-testing, since we are working in this area the most nowdays.

Copy link
Contributor

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, looks good to me.

@lmiller1990 lmiller1990 requested a review from a team March 10, 2023 00:17
@emilyrohrbough emilyrohrbough merged commit 1c5a67f into develop Mar 13, 2023
@emilyrohrbough emilyrohrbough deleted the emily/before-spec-promise branch March 13, 2023 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[setupNodeEvents] on("before:spec", ()=>...) doesn't await the promise returned by the event handler
4 participants