From c43d39f9237e14cae7aa9981f74003b1d5a4c83f Mon Sep 17 00:00:00 2001 From: Ben Kucera <14625260+Bkucera@users.noreply.github.com> Date: Fri, 17 Jul 2020 01:11:31 -0400 Subject: [PATCH] Fix testConfigOverrides not affecting viewport (#8006) --- .../e2e/testConfigOverrides.spec.js | 19 +++++++++++++++++++ packages/driver/src/cy/commands/window.js | 8 +++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/driver/cypress/integration/e2e/testConfigOverrides.spec.js b/packages/driver/cypress/integration/e2e/testConfigOverrides.spec.js index 2675d5b3018d..c82380fc468a 100644 --- a/packages/driver/cypress/integration/e2e/testConfigOverrides.spec.js +++ b/packages/driver/cypress/integration/e2e/testConfigOverrides.spec.js @@ -326,6 +326,25 @@ describe('per-test config', () => { }) }) +describe('viewport', () => { + // https://github.com/cypress-io/cypress/issues/7631 + it('can set viewport in testConfigOverrides', { viewportWidth: 200, viewportHeight: 100 }, () => { + cy.visit('/fixtures/generic.html') + cy.window().then((win) => { + expect(win.innerWidth).eq(200) + expect(win.innerHeight).eq(100) + }) + }) + + it('viewport does not leak between tests', () => { + cy.visit('/fixtures/generic.html') + cy.window().then((win) => { + expect(win.innerWidth).eq(1000) + expect(win.innerHeight).eq(660) + }) + }) +}) + describe('testConfigOverrides baseUrl @slow', () => { it('visit 1', { baseUrl: 'http://localhost:3501' }, () => { cy.visit('/fixtures/generic.html') diff --git a/packages/driver/src/cy/commands/window.js b/packages/driver/src/cy/commands/window.js index 1405fd51d5f3..cce0416702df 100644 --- a/packages/driver/src/cy/commands/window.js +++ b/packages/driver/src/cy/commands/window.js @@ -29,8 +29,8 @@ const validOrientations = ['landscape', 'portrait'] // refresh would cause viewport to hang let currentViewport = null -module.exports = (Commands, Cypress, cy, state, config) => { - const defaultViewport = _.pick(config(), 'viewportWidth', 'viewportHeight') +module.exports = (Commands, Cypress, cy, state) => { + const defaultViewport = _.pick(Cypress.config(), 'viewportWidth', 'viewportHeight') // currentViewport could already be set due to previous runs currentViewport = currentViewport || defaultViewport @@ -41,7 +41,9 @@ module.exports = (Commands, Cypress, cy, state, config) => { // need to restore prior to running the next test // after which we simply null and wait for the // next viewport change - setViewportAndSynchronize(defaultViewport.viewportWidth, defaultViewport.viewportHeight) + const configDefaultViewport = _.pick(Cypress.config(), 'viewportWidth', 'viewportHeight') + + setViewportAndSynchronize(configDefaultViewport.viewportWidth, configDefaultViewport.viewportHeight) }) const setViewportAndSynchronize = (width, height) => {