@@ -3,6 +3,7 @@ import path from 'path'
33import { fork } from 'child_process'
44import type { ForkOptions } from 'child_process'
55import assert from 'assert'
6+ import _ from 'lodash'
67import type { DataContext } from '..'
78import {
89 cleanUpIntegrationFolder ,
@@ -23,15 +24,47 @@ import {
2324 getComponentFolder ,
2425 getIntegrationTestFilesGlobs ,
2526 getSpecPattern ,
27+ legacyOptions ,
2628} from '../sources/migration'
2729import { makeCoreData } from '../data'
2830import { 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+
3065export 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
0 commit comments