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

feat: add resourceType support to cy.intercept() on req/routeMatcher #25075

Merged
merged 32 commits into from
Dec 14, 2022

Conversation

flotwig
Copy link
Contributor

@flotwig flotwig commented Dec 8, 2022

User facing changelog

  • Added the ability to match on resourceType with cy.intercept(), and to see the resource type of an intercepted request as req.resourceType.

Additional details

  • All browsers report this in pre-request information to enable proxy logging, so we can now safely add it in the public intercept API too.
  • In combination with cy.intercept(..., { log: false }, these two changes will unblock users on disabling/enabling logs by resource type: Is there an equivalent of cy.server({ignore: (xhr) => bool}) to disable logging, after moving to cy.intercept? #9358 (no PR yet for 9358)
  • Also renamed "resourceType" to "requestedWith" everywhere it's used in multi-domain. Multi-domain was previously using the term "resource type" to refer to "xhr" or "fetch" for the runner patches, but this usage of the term clobbers the meaning given by CDP and makes it confusing. Since it's referred to as "requestedWith" in some places in MD already, I went ahead and renamed MD's usage to "requestedWith" for the entirety of MD.

Steps to test

Use the new resourceType property on RouteMatcher and req to match only certain requests:

cy.intercept({ resourceType: 'stylesheet' }) // only CSS

cy.intercept('/my-api', (req) => {
  expect(req.resourceType).to.eq('xhr') // only XHRs should hit the API
})

Possible values:

type ResourceType = 'document' | 'fetch' | 'xhr' | 'websocket' | 'stylesheet' | 'script' | 'image' | 'font' | 'cspviolationreport' | 'ping' | 'manifest' | 'other'

How has the user experience changed?

PR Tasks

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Dec 8, 2022

Thanks for taking the time to open a PR!

@@ -38,7 +38,6 @@ export default defineConfig({
delete process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT
process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF = 'true'
process.env.CYPRESS_INTERNAL_VITE_OPEN_MODE_TESTING = 'true'
// process.env.DEBUG = '*'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unrelated change, just noticed this while wrestling with debug

@flotwig flotwig marked this pull request as ready for review December 9, 2022 18:31
Copy link
Contributor

@AtofStryker AtofStryker left a comment

Choose a reason for hiding this comment

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

Looks good on my end! Thank you for renaming resourceType to requestedWith. I gave this a run against some of the tests in cypress-origin-providers and all checks out

packages/driver/cypress/e2e/commands/net_stubbing.cy.ts Outdated Show resolved Hide resolved
flotwig and others added 15 commits December 12, 2022 19:54
Co-authored-by: Bill Glesias <bglesias@gmail.com>
* fix: Remove unneeded Firefox headless hack (run ci)

* Add test to cover new case

Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com>
* fix: cleanup files made by the tmp library in cypress.run()

* Apply suggestions from code review

* Update cli/lib/cypress.js

Co-authored-by: Matt Henkes <mjhenkes@gmail.com>
#25034)

Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com>
Closes undefined
* fix behavior when only using inverted tags

* fix: fix behavior when only using inverted tags

* yarn lint --fix ./npm/grep

Co-authored-by: Matt Schile <mschile@cypress.io>
Co-authored-by: Ryan Manuel <ryanm@cypress.io>
Co-authored-by: Blue F <blue@cypress.io>
@flotwig flotwig merged commit e02f6bf into develop Dec 14, 2022
@flotwig flotwig deleted the cy-intercept-resourceType branch December 14, 2022 17:40
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.

cy.intercept by request cause