Skip to content

Commit b444c8e

Browse files
committed
fix: use 9.X options to default migration
1 parent 9e5c5c7 commit b444c8e

File tree

4 files changed

+417
-5
lines changed

4 files changed

+417
-5
lines changed

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

Lines changed: 48 additions & 4 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,15 +24,47 @@ 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+
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+
function getDiff (oldConfig: any, newConfig: any) {
45+
// get all the values updated during the process
46+
const result: any = _.reduce(oldConfig, (acc: any, value, key) => {
47+
if (!_.isEqual(value, newConfig[key])) {
48+
acc[key] = newConfig[key]
49+
}
50+
51+
return acc
52+
}, {})
53+
54+
// get all the values added during the process
55+
return _.reduce(newConfig, (acc: any, value, key) => {
56+
// their key is in the new config but not in the old config
57+
if (!oldConfig.hasOwnProperty(key)) {
58+
acc[key] = value
59+
}
60+
61+
return acc
62+
}, result)
63+
}
64+
3065
export async function processConfigViaLegacyPlugins (projectRoot: string, legacyConfig: LegacyCypressConfigJson): Promise<LegacyCypressConfigJson> {
3166
const pluginFile = legacyConfig.pluginsFile ?? await tryGetDefaultLegacyPluginsFile(projectRoot)
3267

33-
legacyConfig.env = legacyConfig.env ?? {}
34-
3568
return new Promise((resolve, reject) => {
3669
// couldn't find a pluginsFile
3770
// just bail with initial config
@@ -51,12 +84,23 @@ export async function processConfigViaLegacyPlugins (projectRoot: string, legacy
5184
const CHILD_PROCESS_FILE_PATH = require.resolve('@packages/server/lib/plugins/child/require_async_child')
5285
const ipc = new LegacyPluginsIpc(fork(CHILD_PROCESS_FILE_PATH, configProcessArgs, childOptions))
5386

87+
const legacyConfigWithDefaults = getConfigWithDefaults(legacyConfig)
88+
5489
ipc.on('ready', () => {
55-
ipc.send('loadLegacyPlugins', legacyConfig)
90+
ipc.send('loadLegacyPlugins', legacyConfigWithDefaults)
5691
})
5792

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

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)