Skip to content

Commit 7f69f94

Browse files
authored
fix: resolves correctly specPattern (#21057)
* fix: resolves correctly specPattern * Update test * Update with feedback
1 parent b21ecfb commit 7f69f94

File tree

7 files changed

+156
-11
lines changed

7 files changed

+156
-11
lines changed

packages/app/cypress/e2e/settings.cy.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,14 @@ describe('App: Settings', () => {
194194
})
195195

196196
cy.get('[data-cy="config-code"]').within(() => {
197-
cy.get('.bg-teal-100').contains('tests/_fixtures')
198-
cy.get('.bg-teal-100').contains('abc123')
199-
cy.get('.bg-teal-100').contains('tests/**/*')
200-
cy.get('.bg-teal-100').contains('tests/_support/spec_helper.js')
201-
cy.get('.bg-yellow-100').contains('REMOTE_DEBUGGING_PORT')
202-
cy.get('.bg-yellow-100').contains('INTERNAL_E2E_TESTING_SELF')
203-
cy.get('.bg-yellow-100').contains('INTERNAL_GRAPHQL_PORT')
204-
cy.get('.bg-red-50').contains('4455')
197+
cy.get('[data-cy-config="config"]').contains('tests/_fixtures')
198+
cy.get('[data-cy-config="config"]').contains('abc123')
199+
cy.get('[data-cy-config="config"]').contains('tests/**/*')
200+
cy.get('[data-cy-config="config"]').contains('tests/_support/spec_helper.js')
201+
cy.get('[data-cy-config="env"]').contains('REMOTE_DEBUGGING_PORT')
202+
cy.get('[data-cy-config="env"]').contains('INTERNAL_E2E_TESTING_SELF')
203+
cy.get('[data-cy-config="env"]').contains('INTERNAL_GRAPHQL_PORT')
204+
cy.get('[data-cy-config="cli"]').contains('4455')
205205
})
206206
})
207207

@@ -219,6 +219,35 @@ describe('App: Settings', () => {
219219
expect((ctx.actions.file.openFile as SinonStub).lastCall.args[0]).to.eq(ctx.lifecycleManager.configFilePath)
220220
})
221221
})
222+
223+
it('highlights values set via config file, envFile, env, or CLI in the appropriate color with default specPattern', () => {
224+
cy.scaffoldProject('config-with-js')
225+
cy.openProject('config-with-js')
226+
cy.startAppServer('e2e')
227+
cy.loginUser()
228+
229+
cy.visitApp()
230+
cy.findByText('Settings').click()
231+
cy.findByText('Project Settings').click()
232+
cy.get('[data-cy="config-legend"]').within(() => {
233+
cy.get('.bg-gray-50').contains('default')
234+
cy.get('.bg-teal-100').contains('config')
235+
cy.get('.bg-yellow-100').contains('env')
236+
cy.get('.bg-red-50').contains('cli')
237+
})
238+
239+
cy.get('[data-cy="config-code"]').within(() => {
240+
cy.get('[data-cy-config="default"]').contains('cypress/e2e/**/*.cy.{js,jsx,ts,tsx}')
241+
cy.get('[data-cy-config="config"]').contains('500')
242+
cy.get('[data-cy-config="config"]').contains('10000')
243+
cy.get('[data-cy-config="config"]').contains('false')
244+
cy.get('[data-cy-config="config"]').contains('20')
245+
cy.get('[data-cy-config="env"]').contains('REMOTE_DEBUGGING_PORT')
246+
cy.get('[data-cy-config="env"]').contains('INTERNAL_E2E_TESTING_SELF')
247+
cy.get('[data-cy-config="env"]').contains('INTERNAL_GRAPHQL_PORT')
248+
cy.get('[data-cy-config="cli"]').contains('4455')
249+
})
250+
})
222251
})
223252

224253
describe('external editor', () => {

packages/app/src/settings/project/ConfigCode.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,19 @@
2828
v-if="field === 'browsers' && Array.isArray(value)"
2929
:browsers="value"
3030
:color-classes="`rounded-sm px-2px ${colorMap[from]}`"
31+
:data-cy-config="from"
3132
/>
3233
<RenderObject
3334
v-else-if="value && typeof value === 'object'"
3435
:value="value"
3536
:color-classes="`rounded-sm px-2px ${colorMap[from]}`"
37+
:from="from"
3638
/>
3739
<span
3840
v-else
3941
class="rounded-sm px-2px"
4042
:class="colorMap[from]"
43+
:data-cy-config="from"
4144
>{{ renderPrimitive(value) }}</span>,
4245
<br>
4346
</span>

packages/app/src/settings/project/renderers/RenderObject.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,35 @@
44
:value="value"
55
:depth="props.depth"
66
:color-classes="props.colorClasses"
7+
:data-cy-config="props.from"
78
/><template v-else>
89
<span
910
:class="props.colorClasses"
11+
:data-cy-config="props.from"
1012
>{</span><br><template
1113
v-for="(val, k) in value"
1214
:key="k"
1315
>
1416
<span
1517
:class="props.colorClasses"
1618
:style="`margin-left:${(props.depth + 1) * 24}px`"
19+
:data-cy-config="props.from"
1720
>{{ k }}: </span><RenderObject
1821
v-if="typeof val === 'object'"
1922
:record-key="k"
2023
:value="val"
2124
:color-classes="props.colorClasses"
2225
:depth="props.depth + 1"
26+
:from="props.from"
2327
/><span
2428
v-else
2529
:class="props.colorClasses"
30+
:data-cy-config="props.from"
2631
>{{ renderPrimitive(val) }},</span><br>
2732
</template>
2833
<span
2934
:class="props.colorClasses"
35+
:data-cy-config="props.from"
3036
:style="`margin-left:${props.depth * 24}px`"
3137
>}</span>
3238
</template>
@@ -40,6 +46,7 @@ const props = withDefaults(defineProps<{
4046
value: Record<string, any> | any[]
4147
colorClasses?: string
4248
depth?: number
49+
from: string
4350
}>(), {
4451
colorClasses: '',
4552
depth: 0,

packages/config/__snapshots__/index.spec.ts.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,81 @@ exports['src/index .getPublicConfigKeys returns list of public config keys 1'] =
153153
"modifyObstructiveCode",
154154
"specPattern"
155155
]
156+
157+
exports['src/index .getDefaultValues returns list of public config keys for selected testing type 1'] = {
158+
"animationDistanceThreshold": 5,
159+
"baseUrl": null,
160+
"blockHosts": null,
161+
"chromeWebSecurity": true,
162+
"clientCertificates": [],
163+
"component": {
164+
"specPattern": "**/*.cy.{js,jsx,ts,tsx}",
165+
"indexHtmlFile": "cypress/support/component-index.html"
166+
},
167+
"defaultCommandTimeout": 4000,
168+
"downloadsFolder": "cypress/downloads",
169+
"e2e": {
170+
"specPattern": "cypress/e2e/**/*.cy.{js,jsx,ts,tsx}"
171+
},
172+
"env": {},
173+
"execTimeout": 60000,
174+
"experimentalFetchPolyfill": false,
175+
"experimentalInteractiveRunEvents": false,
176+
"experimentalSessionSupport": false,
177+
"experimentalSourceRewriting": false,
178+
"fileServerFolder": "",
179+
"fixturesFolder": "cypress/fixtures",
180+
"excludeSpecPattern": "*.hot-update.js",
181+
"includeShadowDom": false,
182+
"keystrokeDelay": 0,
183+
"modifyObstructiveCode": true,
184+
"numTestsKeptInMemory": 50,
185+
"pageLoadTimeout": 60000,
186+
"port": null,
187+
"projectId": null,
188+
"redirectionLimit": 20,
189+
"reporter": "spec",
190+
"reporterOptions": null,
191+
"requestTimeout": 5000,
192+
"resolvedNodePath": null,
193+
"resolvedNodeVersion": null,
194+
"responseTimeout": 30000,
195+
"retries": {
196+
"runMode": 0,
197+
"openMode": 0
198+
},
199+
"screenshotOnRunFailure": true,
200+
"screenshotsFolder": "cypress/screenshots",
201+
"slowTestThreshold": 10000,
202+
"scrollBehavior": "top",
203+
"supportFile": "cypress/support/e2e.{js,jsx,ts,tsx}",
204+
"supportFolder": false,
205+
"taskTimeout": 60000,
206+
"trashAssetsBeforeRuns": true,
207+
"userAgent": null,
208+
"video": true,
209+
"videoCompression": 32,
210+
"videosFolder": "cypress/videos",
211+
"videoUploadOnPasses": true,
212+
"viewportHeight": 660,
213+
"viewportWidth": 1000,
214+
"waitForAnimations": true,
215+
"watchForFileChanges": true,
216+
"autoOpen": false,
217+
"browsers": [],
218+
"clientRoute": "/__/",
219+
"configFile": "cypress.config.js",
220+
"cypressBinaryRoot": "/root/cypress",
221+
"devServerPublicPathRoute": "/__cypress/src",
222+
"hosts": null,
223+
"isInteractive": true,
224+
"isTextTerminal": false,
225+
"morgan": true,
226+
"namespace": "__cypress",
227+
"reporterRoute": "/__cypress/reporter",
228+
"socketId": null,
229+
"socketIoCookie": "__socket",
230+
"socketIoRoute": "/__socket",
231+
"xhrRoute": "/xhrs/",
232+
"specPattern": "cypress/e2e/**/*.cy.{js,jsx,ts,tsx}"
233+
}

packages/config/src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,15 @@ export const getBreakingRootKeys = () => {
9898
return breakingRootOptions
9999
}
100100

101-
export const getDefaultValues = (runtimeOptions = {}) => {
101+
export const getDefaultValues = (runtimeOptions: { [k: string]: any } = {}) => {
102102
// Default values can be functions, in which case they are evaluated
103103
// at runtime - for example, slowTestThreshold where the default value
104104
// varies between e2e and component testing.
105-
return _.mapValues(defaultValues, (value) => (typeof value === 'function' ? value(runtimeOptions) : value))
105+
const defaultsForRuntime = _.mapValues(defaultValues, (value) => (typeof value === 'function' ? value(runtimeOptions) : value))
106+
107+
// As we normalize the config based on the selected testing type, we need
108+
// to do the same with the default values to resolve those correctly
109+
return { ...defaultsForRuntime, ...defaultsForRuntime[runtimeOptions.testingType] }
106110
}
107111

108112
export const getPublicConfigKeys = () => {

packages/config/test/unit/index.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@ describe('src/index', () => {
5454

5555
snapshot(defaultValues)
5656
})
57+
58+
it('returns list of public config keys for selected testing type', () => {
59+
const defaultValues = configUtil.getDefaultValues({ testingType: 'e2e' })
60+
61+
expect(defaultValues).to.deep.include({
62+
defaultCommandTimeout: 4000,
63+
scrollBehavior: 'top',
64+
watchForFileChanges: true,
65+
})
66+
67+
expect(defaultValues.env).to.deep.eq({})
68+
69+
// remove these since they are different depending on your machine
70+
;['platform', 'arch', 'version'].forEach((x) => {
71+
expect(defaultValues[x]).to.exist
72+
delete defaultValues[x]
73+
})
74+
75+
snapshot(defaultValues)
76+
})
5777
})
5878

5979
describe('.getPublicConfigKeys', () => {

packages/server/lib/config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ export function mergeDefaults (
148148
additionalIgnorePattern = config.e2e.specPattern
149149
}
150150

151-
config = { ...config, ...config[options.testingType], additionalIgnorePattern }
151+
config = {
152+
...config,
153+
...config[options.testingType],
154+
additionalIgnorePattern,
155+
}
152156

153157
// split out our own app wide env from user env variables
154158
// and delete envFile

0 commit comments

Comments
 (0)