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

chore: refactor server/lib/config.ts to pkg/config #22530

Merged
merged 45 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
aa59a6b
test
sainthkh Jun 27, 2022
99992ed
fix
sainthkh Jun 27, 2022
187f955
Migrate origin.js to pkg/network.
sainthkh Jun 28, 2022
0e022e1
Migrate util/keys.js, path_helpers.js to pkg/config.
sainthkh Jun 28, 2022
1b123ea
Migrate config.ts to pkg/config.
sainthkh Jun 28, 2022
5dfd312
fix
sainthkh Jun 28, 2022
a9fc499
fix
sainthkh Jun 28, 2022
918795e
move parseEnv and related things.
sainthkh Jul 8, 2022
91e51e7
add types
sainthkh Jul 8, 2022
346803a
Move resolveConfigValues
sainthkh Jul 8, 2022
b5b656b
setPluginResolvedOn
sainthkh Jul 8, 2022
17a7952
setUrls
sainthkh Jul 8, 2022
0684cbc
setUrls
sainthkh Jul 8, 2022
ea3ad12
setAbsolutePaths
sainthkh Jul 8, 2022
51455ca
setNodeBinary
sainthkh Jul 12, 2022
84f7981
relativeToProjectRoot
sainthkh Jul 12, 2022
a524ef8
setSupportFileAndFolder
sainthkh Jul 13, 2022
da91738
mergeDefaults
sainthkh Jul 13, 2022
e843451
index.ts types & tests
sainthkh Jul 13, 2022
48f4b18
use direct uri path.
sainthkh Jul 14, 2022
77e47bc
fix type errors + migrate server/util/config
sainthkh Jul 15, 2022
4005eeb
fix types
sainthkh Jul 15, 2022
78a24fe
Remove configApi
sainthkh Jul 18, 2022
cecdff3
fix typo.
sainthkh Jul 18, 2022
2ae6e58
Fix server unit test failures.
sainthkh Jul 18, 2022
57eace1
feedback
sainthkh Jul 19, 2022
9f6248f
fix types.
sainthkh Jul 19, 2022
6a7d5b7
feedback
sainthkh Jul 22, 2022
9eac66f
Merge branch 'develop'
sainthkh Jul 29, 2022
b387035
remove pkg/data-context from pkg/config/src.
sainthkh Jul 29, 2022
c110394
Fix tests.
sainthkh Jul 29, 2022
9752697
Merge branch 'develop' into issue-21781
rachelruderman Jul 29, 2022
33947ff
Merge branch 'develop' into issue-21781
sainthkh Aug 4, 2022
be35d7a
remove data-context
sainthkh Aug 4, 2022
8e59c4c
remove globalContext file
sainthkh Aug 5, 2022
e4e681c
Merge remote-tracking branch 'upstream/develop' into issue-21781
sainthkh Aug 5, 2022
9054ea0
Merge branch 'develop' into issue-21781
emilyrohrbough Aug 10, 2022
2e811a2
Fix merge conflicts.
sainthkh Aug 15, 2022
0153307
Copy develop/packages/data-context/src/index.ts
sainthkh Aug 15, 2022
8fdb994
fix test failure.
sainthkh Aug 15, 2022
fd0f915
Merge branch 'develop' into issue-21781
rachelruderman Aug 16, 2022
551ff00
Merge branch 'develop' into issue-21781
rachelruderman Aug 17, 2022
917416f
Delete zombie code that snuck in with merge conflict
rachelruderman Aug 17, 2022
d2af72f
add experimentalSingleTabRunMode
rachelruderman Aug 17, 2022
ac3da44
Merge branch 'develop' into issue-21781
rachelruderman Aug 17, 2022
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"@types/send": "^0.17.1",
"@types/sinon-chai": "3.2.3",
"@types/through2": "^2.0.36",
"@types/underscore.string": "0.0.38",
"@typescript-eslint/eslint-plugin": "4.18.0",
"@typescript-eslint/parser": "4.18.0",
"@urql/introspection": "^0.3.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
"debug": "^4.3.2",
"fs-extra": "^9.1.0",
"lodash": "^4.17.21",
"recast": "0.20.4"
"recast": "0.20.4",
"return-deep-diff": "0.4.0"
},
"devDependencies": {
"@packages/errors": "0.0.0-development",
"@packages/root": "0.0.0-development",
"@packages/ts": "0.0.0-development",
"@packages/types": "0.0.0-development",
Expand Down
4 changes: 4 additions & 0 deletions packages/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
// babel transforms, etc. into client-side usage of the config code
export * from './browser'

export * from './project'

export { addProjectIdToCypressConfig, addToCypressConfig, addTestingTypeToCypressConfig, AddTestingTypeToCypressConfigOptions, defineConfigAvailable } from './ast-utils/addToCypressConfig'

export * from './utils'
133 changes: 133 additions & 0 deletions packages/config/src/project/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import _ from 'lodash'
import Debug from 'debug'
import deepDiff from 'return-deep-diff'

import errors, { ConfigValidationFailureInfo, CypressError } from '@packages/errors'
sainthkh marked this conversation as resolved.
Show resolved Hide resolved
import type {
ResolvedFromConfig, TestingType, FullConfig,
} from '@packages/types'

import {
validate,
validateNoBreakingConfig,
} from '../browser'
import {
setPluginResolvedOn,
mergeDefaults,
} from './utils'

const debug = Debug('cypress:config:project')

// TODO: any -> SetupFullConfigOptions in data-context/src/data/ProjectConfigManager.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using data-context/src/data/ProjectConfigManager.ts type definitions breaks the type. It seems that some types are missing. I postponed it for now because I need to read a lot of code to be sure that the new types are correct.

export function setupFullConfigWithDefaults (obj: any = {}, getFilesByGlob: any): Promise<FullConfig> {
debug('setting config object %o', obj)
let { projectRoot, projectName, config, envFile, options, cliConfig } = obj

// just force config to be an object so we dont have to do as much
// work in our tests
if (config == null) {
config = {}
}

debug('config is %o', config)

// flatten the object's properties into the master config object
config.envFile = envFile
config.projectRoot = projectRoot
config.projectName = projectName

// @ts-ignore
return mergeDefaults(config, options, cliConfig, getFilesByGlob)
}

// TODO: update types from data-context/src/data/ProjectLifecycleManager.ts
// updateWithPluginValues(config: FullConfig, modifiedConfig: Partial<Cypress.ConfigOptions>, testingType: TestingType): FullConfig
export function updateWithPluginValues (cfg: FullConfig, modifiedConfig: any, testingType: TestingType): FullConfig {
if (!modifiedConfig) {
modifiedConfig = {}
}

debug('updateWithPluginValues %o', { cfg, modifiedConfig })

// make sure every option returned from the plugins file
// passes our validation functions
validate(modifiedConfig, (validationResult: ConfigValidationFailureInfo | string) => {
let configFile = cfg.configFile!

if (_.isString(validationResult)) {
return errors.throwErr('CONFIG_VALIDATION_MSG_ERROR', 'configFile', configFile, validationResult)
}

return errors.throwErr('CONFIG_VALIDATION_ERROR', 'configFile', configFile, validationResult)
})

debug('validate that there is no breaking config options added by setupNodeEvents')

function makeSetupError (cyError: CypressError) {
cyError.name = `Error running ${testingType}.setupNodeEvents()`

return cyError
}

validateNoBreakingConfig(modifiedConfig, errors.warning, (err, options) => {
throw makeSetupError(errors.get(err, options))
}, testingType)

validateNoBreakingConfig(modifiedConfig[testingType], errors.warning, (err, options) => {
throw makeSetupError(errors.get(err, {
...options,
name: `${testingType}.${options.name}`,
}))
}, testingType)

const originalResolvedBrowsers = _.cloneDeep(cfg?.resolved?.browsers) ?? {
value: cfg.browsers,
from: 'default',
} as ResolvedFromConfig

const diffs = deepDiff(cfg, modifiedConfig, true)

debug('config diffs %o', diffs)

const userBrowserList = diffs && diffs.browsers && _.cloneDeep(diffs.browsers)

if (userBrowserList) {
debug('user browser list %o', userBrowserList)
}

// for each override go through
// and change the resolved values of cfg
// to point to the plugin
if (diffs) {
debug('resolved config before diffs %o', cfg.resolved)
setPluginResolvedOn(cfg.resolved, diffs)
debug('resolved config object %o', cfg.resolved)
}

// merge cfg into overrides
const merged = _.defaultsDeep(diffs, cfg)

debug('merged config object %o', merged)

// the above _.defaultsDeep combines arrays,
// if diffs.browsers = [1] and cfg.browsers = [1, 2]
// then the merged result merged.browsers = [1, 2]
// which is NOT what we want
if (Array.isArray(userBrowserList) && userBrowserList.length) {
merged.browsers = userBrowserList
merged.resolved.browsers.value = userBrowserList
}

if (modifiedConfig.browsers === null) {
// null breaks everything when merging lists
debug('replacing null browsers with original list %o', originalResolvedBrowsers)
merged.browsers = cfg.browsers
if (originalResolvedBrowsers) {
merged.resolved.browsers = originalResolvedBrowsers
}
}

debug('merged plugins config %o', merged)

return merged
}
1 change: 1 addition & 0 deletions packages/config/src/project/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Config = Record<string, any>
Loading