Skip to content

breaking: disallow setting viewportHeight/viewportWidth via Cypress.config() during test execution#34262

Open
jennifer-shehane wants to merge 7 commits into
release/16.0.0from
claude/release-16-0-0-change-8396sx
Open

breaking: disallow setting viewportHeight/viewportWidth via Cypress.config() during test execution#34262
jennifer-shehane wants to merge 7 commits into
release/16.0.0from
claude/release-16-0-0-change-8396sx

Conversation

@jennifer-shehane

@jennifer-shehane jennifer-shehane commented Jul 9, 2026

Copy link
Copy Markdown
Member

Additional details

viewportWidth and viewportHeight could previously be mutated at run-time via Cypress.config(). This was confusing and error-prone:

  • The change applied to the next test rather than the current one (config overrides set at run-time leak into the following test).
  • The update was not shared with Cypress Cloud, so it was not reflected in Test Replay.

This change makes viewportWidth/viewportHeight no longer settable via Cypress.config() during test execution. They remain settable via the supported alternatives:

  • cy.viewport()
  • suite-/test-level config overrides — describe/context/it (e.g. it('...', { viewportWidth: 800 }, () => { ... }))

Implementation:

  • Added a new overrideLevel value, suiteOrTest, to @packages/config. It permits suite- and test-level config overrides but rejects run-time mutation via Cypress.config(). viewportWidth/viewportHeight now use this level (they were previously any).
  • validateOverridableAtRunTime now receives the current override context ('suite' / 'test' / undefined for run-time) instead of a single isSuiteLevelOverride boolean, so it can distinguish an it-level override from a run-time Cypress.config() call.
  • Added a dedicated, actionable error message (config.cypress_config_api.suite_or_test_only) that explains the reasoning and points users to cy.viewport() or describe/it overrides.
  • Cross-origin config syncing applies its diff via Cypress.config() at run-time, so suiteOrTest values 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 in cy.origin().
  • Added a 16.0.0 changelog entry.

Steps to test

  1. In a test, call Cypress.config('viewportWidth', 200) (or viewportHeight) inside the test body — Cypress should fail the test with an error explaining it cannot be overridden during test execution.
  2. Confirm the supported alternatives still work:
    • 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.
  3. Confirm reading config is unaffected: 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:

Cypress.config() cannot override viewportWidth during test execution because it would affect the next test rather than the current one and is not reflected in Test Replay. Set viewportWidth in the test configuration of a describe/context or it block, or use cy.viewport() instead.

There is no visual change; the difference is the new error and the steering toward cy.viewport() / test config overrides.

PR Tasks

  • Is there an associated issue with maintainer approval for PR submission? — Don't allow setting viewportHeight and viewportWidth via Cypress.config during test execution #31592 (opened by a maintainer, labeled type: breaking change)
  • Have tests been added/updated? — unit tests in @packages/config and driver e2e/validation specs
  • [na] Has a PR for user-facing changes been opened in cypress-documentation?
  • [na] Have API changes been updated in the type definitions? — viewportWidth/viewportHeight remain valid in TestConfigOverrides (still allowed in describe/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: viewportWidth and viewportHeight can no longer be set with Cypress.config() while a test is running. Suite- and test-level overrides (describe/it config) and cy.viewport() are unchanged.

Config validation gains a suiteOrTest override level (allowed in Mocha overrides, rejected at run-time) and replaces the boolean isSuiteOverride with CurrentOverrideLevel (suite | test | runtime | undefined) so run-time Cypress.config() calls are distinguished from it-level overrides. Viewport options move from any to suiteOrTest.

The driver surfaces a new suite_or_test_only error (with optional cy.viewport() hints for viewport keys). Cross-origin config sync drops suiteOrTest keys from diffs applied via Cypress.config() at run-time so cy.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.

claude added 2 commits June 10, 2026 01:16
…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
Comment thread packages/driver/cypress/e2e/util/config.cy.js
@jennifer-shehane jennifer-shehane self-assigned this Jul 9, 2026
@jennifer-shehane jennifer-shehane marked this pull request as draft July 9, 2026 19:03
@cypress

cypress Bot commented Jul 9, 2026

Copy link
Copy Markdown

cypress    Run #72298

Run Properties:  status check passed Passed #72298  •  git commit 2ec276dbba: Merge branch 'release/16.0.0' into claude/release-16-0-0-change-8396sx
Project cypress
Branch Review claude/release-16-0-0-change-8396sx
Run status status check passed Passed #72298
Run duration 08m 04s
Commit git commit 2ec276dbba: Merge branch 'release/16.0.0' into claude/release-16-0-0-change-8396sx
Committer Jennifer Shehane
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 5
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 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
@jennifer-shehane jennifer-shehane marked this pull request as ready for review July 9, 2026 20:24
claude and others added 2 commits July 9, 2026 20:28
…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

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread packages/config/src/browser.ts Outdated
claude and others added 2 commits July 10, 2026 14:43
…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
@jennifer-shehane jennifer-shehane requested a review from a team July 10, 2026 18:45
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.

2 participants