Skip to content

Commit 1033e04

Browse files
authored
fix: viewport from CLI on CT (#20849)
* fix: viewport from CLI on CT * Add tests
1 parent 09ab40d commit 1033e04

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

packages/app/cypress/e2e/cypress-in-cypress-component.cy.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,15 @@ describe('Cypress In Cypress CT', { viewportWidth: 1500, defaultCommandTimeout:
145145
)
146146
})
147147
})
148+
149+
it('set the correct viewport values from CLI', () => {
150+
cy.openProject('cypress-in-cypress', ['--config', 'viewportWidth=333,viewportHeight=333'])
151+
cy.startAppServer('component')
152+
153+
cy.visitApp()
154+
cy.contains('TestComponent.spec').click()
155+
156+
cy.get('#unified-runner').should('have.css', 'width', '333px')
157+
cy.get('#unified-runner').should('have.css', 'height', '333px')
158+
})
148159
})

packages/app/cypress/e2e/cypress-in-cypress-e2e.cy.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,17 @@ describe('Cypress In Cypress E2E', { viewportWidth: 1500, defaultCommandTimeout:
154154
cy.get('[data-model-state="failed"]').should('contain', 'renders the blank page')
155155
cy.percySnapshot()
156156
})
157+
158+
it('set the correct viewport values from CLI', () => {
159+
cy.openProject('cypress-in-cypress', ['--config', 'viewportWidth=333,viewportHeight=333'])
160+
cy.startAppServer()
161+
162+
cy.visitApp()
163+
cy.contains('dom-content.spec').click()
164+
165+
cy.get('.toggle-specs-wrapper').click()
166+
167+
cy.get('#unified-runner').should('have.css', 'width', '333px')
168+
cy.get('#unified-runner').should('have.css', 'height', '333px')
169+
})
157170
})

packages/config/src/options.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,12 @@ const resolvedOptions: Array<ResolvedConfigOption> = [
384384
canUpdateDuringTestTime: false,
385385
}, {
386386
name: 'viewportHeight',
387-
defaultValue: 660,
387+
defaultValue: (options: Record<string, any> = {}) => options.testingType === 'component' ? 500 : 660,
388388
validation: validate.isNumber,
389389
canUpdateDuringTestTime: true,
390390
}, {
391391
name: 'viewportWidth',
392-
defaultValue: 1000,
392+
defaultValue: (options: Record<string, any> = {}) => options.testingType === 'component' ? 500 : 1000,
393393
validation: validate.isNumber,
394394
canUpdateDuringTestTime: true,
395395
}, {

packages/server/lib/project-base.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,9 @@ export class ProjectBase<TServer extends Server> extends EE {
134134
injectCtSpecificConfig (cfg) {
135135
cfg.resolved.testingType = { value: 'component' }
136136

137-
// This value is normally set up in the `packages/server/lib/plugins/index.js#110`
138-
// But if we don't return it in the plugins function, it never gets set
139-
// Since there is no chance that it will have any other value here, we set it to "component"
140-
// This allows users to not return config in the `cypress/plugins/index.js` file
141-
// https://github.com/cypress-io/cypress/issues/16860
142-
const rawJson = cfg.rawJson as Cfg
143-
144137
return {
145138
...cfg,
146139
componentTesting: true,
147-
viewportHeight: rawJson.viewportHeight ?? 500,
148-
viewportWidth: rawJson.viewportWidth ?? 500,
149140
}
150141
}
151142

0 commit comments

Comments
 (0)