Skip to content

Commit

Permalink
Fix testConfigOverrides not affecting viewport (#8006)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuceb committed Jul 17, 2020
1 parent 8b3ba9c commit c43d39f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
8 changes: 5 additions & 3 deletions packages/driver/src/cy/commands/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) => {
Expand Down

0 comments on commit c43d39f

Please sign in to comment.