Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix testConfigOverrides not affecting viewport #8006

Merged
merged 4 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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