Skip to content

Commit c8e737a

Browse files
authored
Merge branch '10.0-release' into zachw/component-index-html-lift
2 parents 96696e1 + 771f765 commit c8e737a

File tree

13 files changed

+460
-19
lines changed

13 files changed

+460
-19
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
@@ -387,12 +387,12 @@ const resolvedOptions: Array<ResolvedConfigOption> = [
387387
canUpdateDuringTestTime: false,
388388
}, {
389389
name: 'viewportHeight',
390-
defaultValue: 660,
390+
defaultValue: (options: Record<string, any> = {}) => options.testingType === 'component' ? 500 : 660,
391391
validation: validate.isNumber,
392392
canUpdateDuringTestTime: true,
393393
}, {
394394
name: 'viewportWidth',
395-
defaultValue: 1000,
395+
defaultValue: (options: Record<string, any> = {}) => options.testingType === 'component' ? 500 : 1000,
396396
validation: validate.isNumber,
397397
canUpdateDuringTestTime: true,
398398
}, {

packages/data-context/src/actions/MigrationActions.ts

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'path'
33
import { fork } from 'child_process'
44
import type { ForkOptions } from 'child_process'
55
import assert from 'assert'
6+
import _ from 'lodash'
67
import type { DataContext } from '..'
78
import {
89
cleanUpIntegrationFolder,
@@ -23,10 +24,45 @@ import {
2324
getComponentFolder,
2425
getIntegrationTestFilesGlobs,
2526
getSpecPattern,
27+
legacyOptions,
2628
} from '../sources/migration'
2729
import { makeCoreData } from '../data'
2830
import { LegacyPluginsIpc } from '../data/LegacyPluginsIpc'
2931

32+
export function getConfigWithDefaults (legacyConfig: any) {
33+
const newConfig = _.cloneDeep(legacyConfig)
34+
35+
legacyOptions.forEach(({ defaultValue, name }) => {
36+
if (defaultValue !== undefined && legacyConfig[name] === undefined) {
37+
newConfig[name] = typeof defaultValue === 'function' ? defaultValue() : defaultValue
38+
}
39+
})
40+
41+
return newConfig
42+
}
43+
44+
export function getDiff (oldConfig: any, newConfig: any) {
45+
// get all the values updated
46+
const result: any = _.reduce(oldConfig, (acc: any, value, key) => {
47+
// ignore values that have been removed
48+
if (newConfig[key] && !_.isEqual(value, newConfig[key])) {
49+
acc[key] = newConfig[key]
50+
}
51+
52+
return acc
53+
}, {})
54+
55+
// get all the values added
56+
return _.reduce(newConfig, (acc: any, value, key) => {
57+
// their key is in the new config but not in the old config
58+
if (!oldConfig.hasOwnProperty(key)) {
59+
acc[key] = value
60+
}
61+
62+
return acc
63+
}, result)
64+
}
65+
3066
export async function processConfigViaLegacyPlugins (projectRoot: string, legacyConfig: LegacyCypressConfigJson): Promise<LegacyCypressConfigJson> {
3167
const pluginFile = legacyConfig.pluginsFile ?? await tryGetDefaultLegacyPluginsFile(projectRoot)
3268

@@ -49,12 +85,23 @@ export async function processConfigViaLegacyPlugins (projectRoot: string, legacy
4985
const CHILD_PROCESS_FILE_PATH = require.resolve('@packages/server/lib/plugins/child/require_async_child')
5086
const ipc = new LegacyPluginsIpc(fork(CHILD_PROCESS_FILE_PATH, configProcessArgs, childOptions))
5187

88+
const legacyConfigWithDefaults = getConfigWithDefaults(legacyConfig)
89+
5290
ipc.on('ready', () => {
53-
ipc.send('loadLegacyPlugins', legacyConfig)
91+
ipc.send('loadLegacyPlugins', legacyConfigWithDefaults)
5492
})
5593

5694
ipc.on('loadLegacyPlugins:reply', (modifiedLegacyConfig) => {
57-
resolve(modifiedLegacyConfig)
95+
const diff = getDiff(legacyConfigWithDefaults, modifiedLegacyConfig)
96+
97+
// if env is updated by plugins, avoid adding it to the config file
98+
if (diff.env) {
99+
delete diff.env
100+
}
101+
102+
const legacyConfigWithChanges = _.merge(legacyConfig, diff)
103+
104+
resolve(legacyConfigWithChanges)
58105
ipc.childProcess.kill()
59106
})
60107

packages/data-context/src/sources/MigrationDataSource.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export type LegacyCypressConfigJson = Partial<{
3131
integrationFolder: string
3232
testFiles: string | string[]
3333
ignoreTestFiles: string | string[]
34+
env: { [key: string]: any }
35+
[index: string]: any
3436
}>
3537

3638
export interface MigrationFile {

packages/data-context/src/sources/migration/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
export * from './autoRename'
55
export * from './codegen'
66
export * from './format'
7+
export * from './legacyOptions'
78
export * from './parserUtils'
89
export * from './regexps'
910
export * from './shouldShowSteps'

0 commit comments

Comments
 (0)