breaking: disallow setting viewportHeight/viewportWidth via Cypress.config() during test execution#34262
Open
jennifer-shehane wants to merge 7 commits into
Open
breaking: disallow setting viewportHeight/viewportWidth via Cypress.config() during test execution#34262jennifer-shehane wants to merge 7 commits into
jennifer-shehane wants to merge 7 commits into
Conversation
…s.config() during test execution `viewportWidth` and `viewportHeight` could be mutated at run-time via `Cypress.config()`. Doing so affected the *next* test rather than the current one and was not reflected in Test Replay, since these run-time config updates are not shared with the cloud. Introduce a new `suiteOrTest` override level that permits suite- and test-level config overrides (describe/it) but rejects run-time mutation via `Cypress.config()`, and apply it to `viewportWidth`/`viewportHeight`. Users should use `cy.viewport()` or set the viewport in a `describe`/`it` config override instead. Cross-origin config syncing applies its diff via `Cypress.config()` at run-time, so `suiteOrTest` values are now omitted from the sync (viewport is already propagated to spec bridges via state). Closes #31592
…ase-16-0-0-change-8396sx
cypress
|
||||||||||||||||||||||||||||
| Project |
cypress
|
| Branch Review |
claude/release-16-0-0-change-8396sx
|
| Run status |
|
| Run duration | 08m 04s |
| Commit |
|
| Committer | Jennifer Shehane |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
5
|
|
|
0
|
|
|
0
|
| View all changes introduced in this branch ↗︎ | |
Warning
No Report: Something went wrong and we could not generate a report for the Application Quality products.
…rtion viewportHeight/viewportWidth are now rejected at run-time by the override-level check before value validation runs, so asserting an invalid viewport value at run-time no longer reaches the value-type error. Use defaultCommandTimeout (overridable at any level) to keep exercising the value-validation path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RhjKrLZmvqXKhgKsDRtXAB
…y guidance Rework the `suite_or_test_only` message so the base text is config-key agnostic and option-specific advice is appended via an `additionalInfo` suffix, keyed by config option in the driver. viewportWidth/viewportHeight append the `cy.viewport()` recommendation; future suiteOrTest options can add their own guidance without changing the shared message. Also trims verbose inline comments per review feedback. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RhjKrLZmvqXKhgKsDRtXAB
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fc89400. Configure here.
…cution The suiteOrTest override check previously rejected viewportWidth/viewportHeight whenever the override context was not a suite/test config override, which also covered support/spec file load and test:before:run events — broader than the intended "during test execution" scope. Introduce a distinct `runtime` context (state.duringUserTestExecution) and only reject suiteOrTest options then, so spec-wide viewport defaults set via Cypress.config() at file load work again. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RhjKrLZmvqXKhgKsDRtXAB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

viewportHeightandviewportWidthviaCypress.configduring test execution #31592Additional details
viewportWidthandviewportHeightcould previously be mutated at run-time viaCypress.config(). This was confusing and error-prone:This change makes
viewportWidth/viewportHeightno longer settable viaCypress.config()during test execution. They remain settable via the supported alternatives:cy.viewport()describe/context/it(e.g.it('...', { viewportWidth: 800 }, () => { ... }))Implementation:
overrideLevelvalue,suiteOrTest, to@packages/config. It permits suite- and test-level config overrides but rejects run-time mutation viaCypress.config().viewportWidth/viewportHeightnow use this level (they were previouslyany).validateOverridableAtRunTimenow receives the current override context ('suite'/'test'/undefinedfor run-time) instead of a singleisSuiteLevelOverrideboolean, so it can distinguish anit-level override from a run-timeCypress.config()call.config.cypress_config_api.suite_or_test_only) that explains the reasoning and points users tocy.viewport()ordescribe/itoverrides.Cypress.config()at run-time, sosuiteOrTestvalues are now omitted from that sync. Viewport is already propagated to spec bridges via state (not config), so this is a no-op for behavior and avoids a false positive incy.origin().16.0.0changelog entry.Steps to test
Cypress.config('viewportWidth', 200)(orviewportHeight) inside the test body — Cypress should fail the test with an error explaining it cannot be overridden during test execution.cy.viewport(400, 300)resizes the viewport.it('...', { viewportWidth: 400, viewportHeight: 300 }, () => { ... })applies the viewport for that test.describe('...', { viewportWidth: 400 }, () => { ... })applies the viewport for the suite.Cypress.config('viewportWidth')still returns the current value.How has the user experience changed?
Calling
Cypress.config('viewportWidth', <n>)/Cypress.config('viewportHeight', <n>)during a test now throws:There is no visual change; the difference is the new error and the steering toward
cy.viewport()/ test config overrides.PR Tasks
viewportHeightandviewportWidthviaCypress.configduring test execution #31592 (opened by a maintainer, labeledtype: breaking change)@packages/configand driver e2e/validation specscypress-documentation?type definitions? —viewportWidth/viewportHeightremain valid inTestConfigOverrides(still allowed indescribe/it); the restriction is enforced at run-time validation, so no type-definition change is required.🤖 Generated with Claude Code
Generated by Claude Code
Note
Medium Risk
Breaking behavior for tests that resized the viewport via
Cypress.config()during execution; config override plumbing changed but scope is limited to viewport and validation context.Overview
Breaking change:
viewportWidthandviewportHeightcan no longer be set withCypress.config()while a test is running. Suite- and test-level overrides (describe/itconfig) andcy.viewport()are unchanged.Config validation gains a
suiteOrTestoverride level (allowed in Mocha overrides, rejected at run-time) and replaces the booleanisSuiteOverridewithCurrentOverrideLevel(suite|test|runtime|undefined) so run-timeCypress.config()calls are distinguished fromit-level overrides. Viewport options move fromanytosuiteOrTest.The driver surfaces a new
suite_or_test_onlyerror (with optionalcy.viewport()hints for viewport keys). Cross-origin config sync dropssuiteOrTestkeys from diffs applied viaCypress.config()at run-time socy.origin()does not hit false positives.Changelog documents the breaking behavior for 16.0.0; unit and e2e tests cover validation and failure messages.
Reviewed by Cursor Bugbot for commit 2ec276d. Bugbot is set up for automated code reviews on this repo. Configure here.