Skip to content

Commit 61f7cfc

Browse files
authoredMar 24, 2022
fix: scope config to current testing type (#20677)
* fix: scope config to current testing type * Revert options changes * Fix some tests * Fix more tests * Fix more tests * Fix more tests * Update options * Fix tests * Fix tests * Add comments * Remove un-needed quote * Fix test * Fix tests
1 parent 3042ef8 commit 61f7cfc

File tree

32 files changed

+183
-67
lines changed

32 files changed

+183
-67
lines changed
 

‎npm/angular/patches/@cypress+code-coverage+3.9.5.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ index 31e00ee..0c56908 100644
77
/** @type {string} Cypress run-time config has test files string pattern */
88
// @ts-ignore
99
- const testFilePattern = config('testFiles')
10-
+ const testFilePattern = config(Cypress.testingType).specPattern
10+
+ const testFilePattern = config('specPattern')
1111

1212
// test files chould be:
1313
// wild card string "**/*.*" (default)

‎npm/create-cypress-tests/src/component-testing/config-file-updater/configFileUpdater.test.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ describe('lib/util/config-file-updater', () => {
272272
}
273273
`
274274

275-
const output = await insertValueInJSString(src, { component: { specFilePattern: 'src/**/*.spec.cy.js' } })
275+
const output = await insertValueInJSString(src, { component: { specPattern: 'src/**/*.spec.cy.js' } })
276276

277277
const expectedOutput = stripIndent`\
278278
module.exports = {
279279
component: {
280-
specFilePattern: "src/**/*.spec.cy.js",
280+
specPattern: "src/**/*.spec.cy.js",
281281
},
282282
foo: 42
283283
}
@@ -296,12 +296,12 @@ describe('lib/util/config-file-updater', () => {
296296
}
297297
`
298298

299-
const output = await insertValueInJSString(src, { component: { specFilePattern: 'src/**/*.spec.cy.js' } })
299+
const output = await insertValueInJSString(src, { component: { specPattern: 'src/**/*.spec.cy.js' } })
300300

301301
const expectedOutput = stripIndent`\
302302
module.exports = {
303303
component: {
304-
specFilePattern: "src/**/*.spec.cy.js",
304+
specPattern: "src/**/*.spec.cy.js",
305305
viewportWidth: 800
306306
},
307307
foo: 42
@@ -316,18 +316,18 @@ describe('lib/util/config-file-updater', () => {
316316
module.exports = {
317317
foo: 42,
318318
component: {
319-
specFilePattern: 'components/**/*.spec.cy.js',
319+
specPattern: 'components/**/*.spec.cy.js',
320320
foo: 82
321321
}
322322
}`
323323

324-
const output = await insertValueInJSString(src, { component: { specFilePattern: 'src/**/*.spec.cy.js' } })
324+
const output = await insertValueInJSString(src, { component: { specPattern: 'src/**/*.spec.cy.js' } })
325325

326326
const expectedOutput = stripIndent`\
327327
module.exports = {
328328
foo: 42,
329329
component: {
330-
specFilePattern: "src/**/*.spec.cy.js",
330+
specPattern: "src/**/*.spec.cy.js",
331331
foo: 82
332332
}
333333
}`

‎npm/react/plugins/utils/get-transpile-folders.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function getTranspileFolders (config) {
2323
}
2424

2525
// attempt to add directories based on spec pattern
26-
let componentDirs = config.component.specPattern || ''
26+
let componentDirs = config.specPattern || ''
2727

2828
// can be string or array
2929
if (typeof componentDirs === 'string') {

‎npm/vue/examples/code-coverage/patches/@cypress+code-coverage+3.9.5.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ index 31e00ee..0c56908 100644
77
/** @type {string} Cypress run-time config has test files string pattern */
88
// @ts-ignore
99
- const testFilePattern = config('testFiles')
10-
+ const testFilePattern = config(Cypress.testingType).specPattern
10+
+ const testFilePattern = config('specPattern')
1111

1212
// test files chould be:
1313
// wild card string "**/*.*" (default)

‎npm/vue/examples/vue-cli/patches/@cypress+code-coverage+3.9.5.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ index 31e00ee..0c56908 100644
77
/** @type {string} Cypress run-time config has test files string pattern */
88
// @ts-ignore
99
- const testFilePattern = config('testFiles')
10-
+ const testFilePattern = config(Cypress.testingType).specPattern
10+
+ const testFilePattern = config('specPattern')
1111

1212
// test files chould be:
1313
// wild card string "**/*.*" (default)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ describe('App: Settings', () => {
209209
cy.get('[data-cy="config-code"]').within(() => {
210210
cy.get('.bg-teal-100').contains('tests/_fixtures')
211211
cy.get('.bg-teal-100').contains('abc123')
212-
cy.get('.bg-teal-100').contains('specFilePattern')
213-
cy.get('.bg-teal-100').contains('supportFile')
212+
cy.get('.bg-teal-100').contains('tests/**/*')
213+
cy.get('.bg-teal-100').contains('tests/_support/spec_helper.js')
214214
cy.get('.bg-yellow-100').contains('REMOTE_DEBUGGING_PORT')
215215
cy.get('.bg-yellow-100').contains('INTERNAL_E2E_TESTING_SELF')
216216
cy.get('.bg-yellow-100').contains('INTERNAL_GRAPHQL_PORT')

‎packages/app/src/components/SpecPatterns.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const props = defineProps<{
6161
}>()
6262
6363
const specPatterns = computed<string[]>(() => {
64-
let patterns = props.gql.config.find((x) => x.field === props.gql.currentTestingType)?.value?.specPattern
64+
const patterns = props.gql.config.find((x) => x.field === 'specPattern')?.value
6565
6666
if (!patterns) {
6767
return []

‎packages/app/src/settings/project/ConfigCode.cy.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('<ConfigCode />', () => {
4545
}} />
4646
</div>))
4747

48-
const expectedText = `{${Object.entries(objectTest).map(([key, value]) => `'${key}': '${value}'`).join(',')},}`
48+
const expectedText = `{${Object.entries(objectTest).map(([key, value]) => `${key}: '${value}'`).join(',')},}`
4949

5050
cy.contains(`objectTest:`).should('contain.text', expectedText)
5151
})

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<span
1515
:class="props.colorClasses"
1616
:style="`margin-left:${(props.depth + 1) * 24}px`"
17-
>'{{ k }}': </span><RenderObject
17+
>{{ k }}: </span><RenderObject
1818
v-if="typeof val === 'object'"
1919
:record-key="k"
2020
:value="val"

‎packages/app/src/specs/NoSpecsPage.cy.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ describe('<NoSpecsPage />', { viewportHeight: 655, viewportWidth: 1032 }, () =>
9696
onResult: (res) => {
9797
if (res.currentProject?.config) {
9898
res.currentProject.config = res.currentProject.config.map((x) => {
99-
if (x.field === 'e2e') {
100-
return { ...x, value: { ...x.value, specPattern: customSpecPattern } }
99+
if (x.field === 'specPattern') {
100+
return { ...x, value: customSpecPattern }
101101
}
102102

103103
return x

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,6 @@ exports['src/index .getPublicConfigKeys returns list of public config keys 1'] =
148148
"browsers",
149149
"hosts",
150150
"isInteractive",
151-
"modifyObstructiveCode"
151+
"modifyObstructiveCode",
152+
"specPattern"
152153
]

‎packages/config/src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import _ from 'lodash'
22
import Debug from 'debug'
3-
import { options, breakingOptions, breakingRootOptions, testingTypeBreakingOptions } from './options'
3+
import { defaultSpecPattern, options, breakingOptions, breakingRootOptions, testingTypeBreakingOptions, additionalOptionsToResolveConfig } from './options'
44
import type { BreakingOption, BreakingOptionErrorKey } from './options'
55

66
// this export has to be done in 2 lines because of a bug in babel typescript
77
import * as validation from './validation'
88

99
export {
10+
defaultSpecPattern,
1011
validation,
1112
options,
1213
breakingOptions,
@@ -31,7 +32,7 @@ function createIndex<T extends Record<string, any>> (arr: Array<T>, keyKey: keyo
3132

3233
const breakingKeys = _.map(breakingOptions, 'name')
3334
const defaultValues = createIndex(options, 'name', 'defaultValue')
34-
const publicConfigKeys = _(options).reject({ isInternal: true }).map('name').value()
35+
const publicConfigKeys = _([...options, ...additionalOptionsToResolveConfig]).reject({ isInternal: true }).map('name').value()
3536
const validationRules = createIndex(options, 'name', 'validation')
3637
const testConfigOverrideOptions = createIndex(options, 'name', 'canUpdateDuringTestTime')
3738

‎packages/config/src/options.ts

+26-2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ const isValidConfig = (key: string, config: any) => {
9898
return true
9999
}
100100

101+
export const defaultSpecPattern = {
102+
e2e: 'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
103+
component: '**/*.cy.{js,jsx,ts,tsx}',
104+
}
105+
101106
// NOTE:
102107
// If you add/remove/change a config value, make sure to update the following
103108
// - cli/types/index.d.ts (including allowed config options on TestOptions)
@@ -141,7 +146,7 @@ const resolvedOptions: Array<ResolvedConfigOption> = [
141146
name: 'component',
142147
// runner-ct overrides
143148
defaultValue: {
144-
specPattern: '**/*.cy.{js,jsx,ts,tsx}',
149+
specPattern: defaultSpecPattern.component,
145150
},
146151
validation: isValidConfig,
147152
canUpdateDuringTestTime: false,
@@ -160,7 +165,7 @@ const resolvedOptions: Array<ResolvedConfigOption> = [
160165
name: 'e2e',
161166
// e2e runner overrides
162167
defaultValue: {
163-
specPattern: 'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
168+
specPattern: defaultSpecPattern.e2e,
164169
},
165170
validation: isValidConfig,
166171
canUpdateDuringTestTime: false,
@@ -500,6 +505,16 @@ const runtimeOptions: Array<RuntimeConfigOption> = [
500505
validation: validate.isString,
501506
isInternal: true,
502507
canUpdateDuringTestTime: false,
508+
}, {
509+
// Internal config field, useful to ignore the e2e specPattern set by the user
510+
// or the default one when looking fot CT, it needs to be a config property because after
511+
// having the final config that has the e2e property flattened/compacted
512+
// we may not be able to get the value to ignore.
513+
name: 'additionalIgnorePattern',
514+
defaultValue: (options: Record<string, any> = {}) => options.testingType === 'component' ? defaultSpecPattern.e2e : undefined,
515+
validation: validate.isString,
516+
isInternal: true,
517+
canUpdateDuringTestTime: false,
503518
},
504519
]
505520

@@ -508,6 +523,15 @@ export const options: Array<ResolvedConfigOption | RuntimeConfigOption> = [
508523
...runtimeOptions,
509524
]
510525

526+
// These properties are going to be added to the resolved properties of the
527+
// config, but do not mean that are valid config properties coming from the user.
528+
export const additionalOptionsToResolveConfig = [
529+
{
530+
name: 'specPattern',
531+
isInternal: false,
532+
},
533+
]
534+
511535
/**
512536
* Values not allowed in 10.X+ in the root, e2e and component config
513537
*/

‎packages/data-context/src/actions/ProjectActions.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,9 @@ export class ProjectActions {
421421
await this.setSpecsFoundBySpecPattern({
422422
path: this.ctx.currentProject,
423423
testingType,
424-
specPattern: cfg[testingType]?.specPattern,
425-
excludeSpecPattern: cfg[testingType]?.excludeSpecPattern,
426-
additionalIgnorePattern: testingType === 'component' ? cfg?.e2e?.specPattern : undefined,
424+
specPattern: cfg.specPattern,
425+
excludeSpecPattern: cfg.excludeSpecPattern,
426+
additionalIgnorePattern: cfg.additionalIgnorePattern,
427427
})
428428
}
429429

‎packages/data-context/src/data/ProjectLifecycleManager.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1286,13 +1286,13 @@ export class ProjectLifecycleManager {
12861286

12871287
this._pendingInitialize?.resolve(finalConfig)
12881288

1289-
if (this._currentTestingType && finalConfig[this._currentTestingType]?.specPattern) {
1289+
if (this._currentTestingType && finalConfig.specPattern) {
12901290
return this.ctx.actions.project.setSpecsFoundBySpecPattern({
12911291
path: this.projectRoot,
12921292
testingType: this._currentTestingType,
1293-
specPattern: this.ctx.modeOptions.spec || finalConfig[this._currentTestingType]?.specPattern,
1294-
excludeSpecPattern: finalConfig[this._currentTestingType]?.excludeSpecPattern,
1295-
additionalIgnorePattern: this._currentTestingType === 'component' ? finalConfig.e2e?.specPattern : undefined,
1293+
specPattern: this.ctx.modeOptions.spec || finalConfig.specPattern,
1294+
excludeSpecPattern: finalConfig.excludeSpecPattern,
1295+
additionalIgnorePattern: finalConfig.additionalIgnorePattern,
12961296
})
12971297
}
12981298

‎packages/data-context/src/sources/ProjectDataSource.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import path from 'path'
88
import Debug from 'debug'
99
import commonPathPrefix from 'common-path-prefix'
1010
import type { FSWatcher } from 'chokidar'
11+
import { defaultSpecPattern } from '@packages/config'
1112
import parseGlob from 'parse-glob'
1213
import mm from 'micromatch'
1314
import RandExp from 'randexp'
@@ -19,7 +20,6 @@ import type { DataContext } from '..'
1920
import { toPosix } from '../util/file'
2021
import type { FilePartsShape } from '@packages/graphql/src/schemaTypes/objectTypes/gql-FileParts'
2122
import { STORIES_GLOB } from '.'
22-
import { getDefaultSpecPatterns } from '../util/config-options'
2323

2424
export type SpecWithRelativeRoot = FoundSpec & { relativeToCommonRoot: string }
2525

@@ -198,7 +198,7 @@ export class ProjectDataSource {
198198
this.ctx.coreData.app.relaunchBrowser = relaunchBrowser
199199
}
200200

201-
async specPatternsForTestingType (projectRoot: string, testingType: Cypress.TestingType): Promise<{
201+
async specPatterns (): Promise<{
202202
specPattern?: string[]
203203
excludeSpecPattern?: string[]
204204
}> {
@@ -207,8 +207,8 @@ export class ProjectDataSource {
207207
const config = await this.getConfig()
208208

209209
return {
210-
specPattern: toArray(config[testingType]?.specPattern),
211-
excludeSpecPattern: toArray(config[testingType]?.excludeSpecPattern),
210+
specPattern: toArray(config.specPattern),
211+
excludeSpecPattern: toArray(config.excludeSpecPattern),
212212
}
213213
}
214214

@@ -272,7 +272,7 @@ export class ProjectDataSource {
272272
}
273273

274274
let specPatternSet: string | undefined
275-
const { specPattern = [] } = await this.ctx.project.specPatternsForTestingType(this.ctx.currentProject, this.ctx.coreData.currentTestingType)
275+
const { specPattern = [] } = await this.ctx.project.specPatterns()
276276

277277
if (Array.isArray(specPattern)) {
278278
specPatternSet = specPattern[0]
@@ -301,7 +301,7 @@ export class ProjectDataSource {
301301

302302
const MINIMATCH_OPTIONS = { dot: true, matchBase: true }
303303

304-
const { specPattern = [], excludeSpecPattern = [] } = await this.ctx.project.specPatternsForTestingType(this.ctx.currentProject, this.ctx.coreData.currentTestingType)
304+
const { specPattern = [], excludeSpecPattern = [] } = await this.ctx.project.specPatterns()
305305

306306
for (const pattern of excludeSpecPattern) {
307307
if (minimatch(specFile, pattern, MINIMATCH_OPTIONS)) {
@@ -415,9 +415,9 @@ export class ProjectDataSource {
415415
assert(this.ctx.currentProject)
416416
assert(this.ctx.coreData.currentTestingType)
417417

418-
const { e2e, component } = getDefaultSpecPatterns()
418+
const { e2e, component } = defaultSpecPattern
419419

420-
const { specPattern } = await this.ctx.project.specPatternsForTestingType(this.ctx.currentProject, this.ctx.coreData.currentTestingType)
420+
const { specPattern } = await this.ctx.project.specPatterns()
421421

422422
if (this.ctx.coreData.currentTestingType === 'e2e') {
423423
return isEqual(specPattern, [e2e])

‎packages/data-context/src/util/config-options.ts

-8
This file was deleted.

‎packages/data-context/src/util/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
export * from './autoBindDebug'
55
export * from './cached'
66
export * from './config-file-updater'
7-
export * from './config-options'
87
export * from './file'
98
export * from './urqlCacheKeys'

‎packages/data-context/test/unit/config-file-updater.spec.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,12 @@ describe('lib/util/config-file-updater', () => {
255255
}
256256
`
257257

258-
const output = await insertValueInJSString(src, { component: { specFilePattern: 'src/**/*.spec.cy.js' } }, errors)
258+
const output = await insertValueInJSString(src, { component: { specPattern: 'src/**/*.spec.cy.js' } }, errors)
259259

260260
const expectedOutput = stripIndent`\
261261
module.exports = {
262262
component: {
263-
specFilePattern: 'src/**/*.spec.cy.js',
263+
specPattern: 'src/**/*.spec.cy.js',
264264
},
265265
foo: 42
266266
}
@@ -279,12 +279,12 @@ describe('lib/util/config-file-updater', () => {
279279
}
280280
`
281281

282-
const output = await insertValueInJSString(src, { component: { specFilePattern: 'src/**/*.spec.cy.js' } }, errors)
282+
const output = await insertValueInJSString(src, { component: { specPattern: 'src/**/*.spec.cy.js' } }, errors)
283283

284284
const expectedOutput = stripIndent`\
285285
module.exports = {
286286
'component': {
287-
specFilePattern: 'src/**/*.spec.cy.js',
287+
specPattern: 'src/**/*.spec.cy.js',
288288
viewportWidth: 800
289289
},
290290
foo: 42
@@ -299,18 +299,18 @@ describe('lib/util/config-file-updater', () => {
299299
module.exports = {
300300
foo: 42,
301301
component: {
302-
specFilePattern: 'components/**/*.spec.cy.js',
302+
specPattern: 'components/**/*.spec.cy.js',
303303
foo: 82
304304
}
305305
}`
306306

307-
const output = await insertValueInJSString(src, { component: { specFilePattern: 'src/**/*.spec.cy.js' } }, errors)
307+
const output = await insertValueInJSString(src, { component: { specPattern: 'src/**/*.spec.cy.js' } }, errors)
308308

309309
const expectedOutput = stripIndent`\
310310
module.exports = {
311311
foo: 42,
312312
component: {
313-
specFilePattern: 'src/**/*.spec.cy.js',
313+
specPattern: 'src/**/*.spec.cy.js',
314314
foo: 82
315315
}
316316
}`

0 commit comments

Comments
 (0)