From e0582301504fd7aaa23e36227471541b7fda7731 Mon Sep 17 00:00:00 2001 From: Ben Kucera <14625260+Bkucera@users.noreply.github.com> Date: Thu, 16 Jul 2020 14:24:45 -0400 Subject: [PATCH 1/4] fix testConfigOverrides not setting viewport --- .../e2e/testConfigOverrides.spec.js | 18 ++++++++++++++++++ packages/driver/src/cy/commands/window.js | 6 ++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/driver/cypress/integration/e2e/testConfigOverrides.spec.js b/packages/driver/cypress/integration/e2e/testConfigOverrides.spec.js index 2675d5b3018d..762923383e33 100644 --- a/packages/driver/cypress/integration/e2e/testConfigOverrides.spec.js +++ b/packages/driver/cypress/integration/e2e/testConfigOverrides.spec.js @@ -326,6 +326,24 @@ describe('per-test config', () => { }) }) +describe('viewport', () => { + 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..be8299f8498a 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,6 +41,8 @@ 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 + const defaultViewport = _.pick(Cypress.config(), 'viewportWidth', 'viewportHeight') + setViewportAndSynchronize(defaultViewport.viewportWidth, defaultViewport.viewportHeight) }) From 3590771d423dcd13c6ec57dd827eb0e41696cf73 Mon Sep 17 00:00:00 2001 From: Ben Kucera <14625260+Bkucera@users.noreply.github.com> Date: Thu, 16 Jul 2020 14:26:05 -0400 Subject: [PATCH 2/4] add comment --- .../driver/cypress/integration/e2e/testConfigOverrides.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/driver/cypress/integration/e2e/testConfigOverrides.spec.js b/packages/driver/cypress/integration/e2e/testConfigOverrides.spec.js index 762923383e33..c82380fc468a 100644 --- a/packages/driver/cypress/integration/e2e/testConfigOverrides.spec.js +++ b/packages/driver/cypress/integration/e2e/testConfigOverrides.spec.js @@ -327,6 +327,7 @@ 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) => { From a723585629faac36d890cdb6ae8d439bb4012dc2 Mon Sep 17 00:00:00 2001 From: Ben Kucera <14625260+Bkucera@users.noreply.github.com> Date: Thu, 16 Jul 2020 14:31:08 -0400 Subject: [PATCH 3/4] cleanup --- packages/driver/src/cy/commands/window.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/driver/src/cy/commands/window.js b/packages/driver/src/cy/commands/window.js index be8299f8498a..8b838e9473f8 100644 --- a/packages/driver/src/cy/commands/window.js +++ b/packages/driver/src/cy/commands/window.js @@ -41,9 +41,9 @@ module.exports = (Commands, Cypress, cy, state) => { // need to restore prior to running the next test // after which we simply null and wait for the // next viewport change - const defaultViewport = _.pick(Cypress.config(), 'viewportWidth', 'viewportHeight') + const testDefaultViewport = _.pick(Cypress.config(), 'viewportWidth', 'viewportHeight') - setViewportAndSynchronize(defaultViewport.viewportWidth, defaultViewport.viewportHeight) + setViewportAndSynchronize(testDefaultViewport.viewportWidth, testDefaultViewport.viewportHeight) }) const setViewportAndSynchronize = (width, height) => { From c1dffbac658cd71513b64b61e666f5b4f44da4c9 Mon Sep 17 00:00:00 2001 From: Ben Kucera <14625260+Bkucera@users.noreply.github.com> Date: Thu, 16 Jul 2020 14:32:10 -0400 Subject: [PATCH 4/4] cleanup 2 --- packages/driver/src/cy/commands/window.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/driver/src/cy/commands/window.js b/packages/driver/src/cy/commands/window.js index 8b838e9473f8..cce0416702df 100644 --- a/packages/driver/src/cy/commands/window.js +++ b/packages/driver/src/cy/commands/window.js @@ -41,9 +41,9 @@ module.exports = (Commands, Cypress, cy, state) => { // need to restore prior to running the next test // after which we simply null and wait for the // next viewport change - const testDefaultViewport = _.pick(Cypress.config(), 'viewportWidth', 'viewportHeight') + const configDefaultViewport = _.pick(Cypress.config(), 'viewportWidth', 'viewportHeight') - setViewportAndSynchronize(testDefaultViewport.viewportWidth, testDefaultViewport.viewportHeight) + setViewportAndSynchronize(configDefaultViewport.viewportWidth, configDefaultViewport.viewportHeight) }) const setViewportAndSynchronize = (width, height) => {