Skip to content

Commit f8f2418

Browse files
tbiethmanmjhenkes
andauthored
fix: Don't include project path with supportFile glob (#22222)
* fix: Don't glob project path in supportFile lookup * Updating unit tests around supportFile 'isFolder' * Adding unit test to validate the projectRoot isn't globbed * Adding system test to validate successful run * This is more accurate * Updating snapshot to reflect now missing absolute path from the supportFile value * Adding e2 launchpad test Co-authored-by: Matt Henkes <[email protected]>
1 parent 1e61923 commit f8f2418

File tree

10 files changed

+108
-5
lines changed

10 files changed

+108
-5
lines changed

packages/config/src/options.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ const resolvedOptions: Array<ResolvedConfigOption> = [
351351
name: 'supportFile',
352352
defaultValue: (options: Record<string, any> = {}) => options.testingType === 'component' ? 'cypress/support/component.{js,jsx,ts,tsx}' : 'cypress/support/e2e.{js,jsx,ts,tsx}',
353353
validation: validate.isStringOrFalse,
354-
isFolder: true,
355354
canUpdateDuringTestTime: false,
356355
requireRestartOnChange: 'server',
357356
}, {

packages/launchpad/cypress/e2e/open-mode.cy.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,16 @@ describe('Launchpad: Open Mode', () => {
211211
cy.contains('Your project does not contain a default supportFile.')
212212
cy.contains('If a support file is not necessary for your project, set supportFile to false.')
213213
})
214+
215+
// Assert that we do not glob the absolute projectRoot
216+
// and fail supportFile lookups during project initialization.
217+
// https://github.com/cypress-io/cypress/issues/22040
218+
it('opens projects with paths that contain glob syntax', () => {
219+
cy.scaffoldProject('project-with-(glob)-[chars]')
220+
cy.openProject('project-with-(glob)-[chars]', ['--e2e'])
221+
cy.visitLaunchpad()
222+
223+
cy.get('body').should('not.contain.text', 'Your project does not contain a default supportFile.')
224+
cy.get('h1').should('contain', 'Choose a Browser')
225+
})
214226
})

packages/server/lib/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ export async function setSupportFileAndFolder (obj) {
419419

420420
const ctx = getCtx()
421421

422-
const supportFilesByGlob = await ctx.file.getFilesByGlob(obj.projectRoot, obj.supportFile, { absolute: false })
422+
const supportFilesByGlob = await ctx.file.getFilesByGlob(obj.projectRoot, obj.supportFile)
423423

424424
if (supportFilesByGlob.length > 1) {
425425
return errors.throwErr('MULTIPLE_SUPPORT_FILES_FOUND', obj.supportFile, supportFilesByGlob)

packages/server/test/unit/config_spec.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,7 +2086,7 @@ describe('lib/config', () => {
20862086
})
20872087
})
20882088

2089-
it('sets the supportFile to default index.js if it does not exist, support folder does not exist, and supportFile is the default', () => {
2089+
it('sets the supportFile to default e2e.js if it does not exist, support folder does not exist, and supportFile is the default', () => {
20902090
const projectRoot = Fixtures.projectPath('no-scaffolding')
20912091

20922092
const obj = config.setAbsolutePaths({
@@ -2104,6 +2104,24 @@ describe('lib/config', () => {
21042104
})
21052105
})
21062106

2107+
it('finds support file in project path that contains glob syntax', () => {
2108+
const projectRoot = Fixtures.projectPath('project-with-(glob)-[chars]')
2109+
2110+
const obj = config.setAbsolutePaths({
2111+
projectRoot,
2112+
supportFile: 'cypress/support/e2e.js',
2113+
})
2114+
2115+
return config.setSupportFileAndFolder(obj)
2116+
.then((result) => {
2117+
expect(result).to.eql({
2118+
projectRoot,
2119+
supportFile: `${projectRoot}/cypress/support/e2e.js`,
2120+
supportFolder: `${projectRoot}/cypress/support`,
2121+
})
2122+
})
2123+
})
2124+
21072125
it('sets the supportFile to false if it does not exist, support folder exists, and supportFile is the default', () => {
21082126
const projectRoot = Fixtures.projectPath('empty-folders')
21092127

@@ -2218,7 +2236,7 @@ describe('lib/config', () => {
22182236
expect(config.setAbsolutePaths(obj)).to.deep.eq(obj)
22192237
})
22202238

2221-
return ['fileServerFolder', 'fixturesFolder', 'supportFile'].forEach((folder) => {
2239+
return ['fileServerFolder', 'fixturesFolder'].forEach((folder) => {
22222240
it(`converts relative ${folder} to absolute path`, () => {
22232241
const obj = {
22242242
projectRoot: '/_test-output/path/to/project',

system-tests/__snapshots__/config_spec.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,3 +423,62 @@ Please remove this option or add this as an e2e testing type property: e2e.exper
423423
https://on.cypress.io/migration-guide
424424
425425
`
426+
427+
exports['e2e config finds supportFiles in projects containing glob syntax 1'] = `
428+
429+
====================================================================================================
430+
431+
(Run Starting)
432+
433+
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
434+
│ Cypress: 1.2.3 │
435+
│ Browser: FooBrowser 88 │
436+
│ Specs: 1 found (app.cy.js) │
437+
│ Searched: cypress/e2e/**/*.cy.{js,jsx,ts,tsx} │
438+
└────────────────────────────────────────────────────────────────────────────────────────────────┘
439+
440+
441+
────────────────────────────────────────────────────────────────────────────────────────────────────
442+
443+
Running: app.cy.js (1 of 1)
444+
445+
446+
✓ is true
447+
448+
1 passing
449+
450+
451+
(Results)
452+
453+
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
454+
│ Tests: 1 │
455+
│ Passing: 1 │
456+
│ Failing: 0 │
457+
│ Pending: 0 │
458+
│ Skipped: 0 │
459+
│ Screenshots: 0 │
460+
│ Video: true │
461+
│ Duration: X seconds │
462+
│ Spec Ran: app.cy.js │
463+
└────────────────────────────────────────────────────────────────────────────────────────────────┘
464+
465+
466+
(Video)
467+
468+
- Started processing: Compressing to 32 CRF
469+
- Finished processing: /XXX/XXX/XXX/cypress/videos/app.cy.js.mp4 (X second)
470+
471+
472+
====================================================================================================
473+
474+
(Run Finished)
475+
476+
477+
Spec Tests Passing Failing Pending Skipped
478+
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
479+
│ ✔ app.cy.js XX:XX 1 1 - - - │
480+
└────────────────────────────────────────────────────────────────────────────────────────────────┘
481+
✔ All specs passed! XX:XX 1 1 - - -
482+
483+
484+
`

system-tests/__snapshots__/multiple_support_files_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
exports['e2e multiple support files passes 1'] = `
22
There were multiple support files found matching your supportFile pattern.
33
4-
Your supportFile is set to: /foo/bar/.projects/multiple-support-files/cypress/support/e2e.{js,jsx,ts,tsx}
4+
Your supportFile is set to: cypress/support/e2e.{js,jsx,ts,tsx}
55
66
We found the following files:
77
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
e2e: { },
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
it('is true', () => {
2+
expect(true).to.be.true
3+
})

system-tests/projects/project-with-(glob)-[chars]/cypress/support/e2e.js

Whitespace-only changes.

system-tests/test/config_spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,13 @@ describe('e2e config', () => {
236236
snapshot: true,
237237
})
238238
})
239+
240+
it('finds supportFiles in projects containing glob syntax', async function () {
241+
await Fixtures.scaffoldProject('project-with-(glob)-[chars]')
242+
243+
return systemTests.exec(this, {
244+
project: 'project-with-(glob)-[chars]',
245+
snapshot: true,
246+
})
247+
})
239248
})

0 commit comments

Comments
 (0)