Skip to content

Commit

Permalink
fix: Don't include project path with supportFile glob (cypress-io#22222)
Browse files Browse the repository at this point in the history
* 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 <mjhenkes@gmail.com>
  • Loading branch information
2 people authored and BeijiYang committed Jun 23, 2022
1 parent 3203c2b commit 886ef61
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 5 deletions.
1 change: 0 additions & 1 deletion packages/config/src/options.ts
Expand Up @@ -351,7 +351,6 @@ const resolvedOptions: Array<ResolvedConfigOption> = [
name: 'supportFile',
defaultValue: (options: Record<string, any> = {}) => options.testingType === 'component' ? 'cypress/support/component.{js,jsx,ts,tsx}' : 'cypress/support/e2e.{js,jsx,ts,tsx}',
validation: validate.isStringOrFalse,
isFolder: true,
canUpdateDuringTestTime: false,
requireRestartOnChange: 'server',
}, {
Expand Down
12 changes: 12 additions & 0 deletions packages/launchpad/cypress/e2e/open-mode.cy.ts
Expand Up @@ -211,4 +211,16 @@ describe('Launchpad: Open Mode', () => {
cy.contains('Your project does not contain a default supportFile.')
cy.contains('If a support file is not necessary for your project, set supportFile to false.')
})

// Assert that we do not glob the absolute projectRoot
// and fail supportFile lookups during project initialization.
// https://github.com/cypress-io/cypress/issues/22040
it('opens projects with paths that contain glob syntax', () => {
cy.scaffoldProject('project-with-(glob)-[chars]')
cy.openProject('project-with-(glob)-[chars]', ['--e2e'])
cy.visitLaunchpad()

cy.get('body').should('not.contain.text', 'Your project does not contain a default supportFile.')
cy.get('h1').should('contain', 'Choose a Browser')
})
})
2 changes: 1 addition & 1 deletion packages/server/lib/config.ts
Expand Up @@ -419,7 +419,7 @@ export async function setSupportFileAndFolder (obj) {

const ctx = getCtx()

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

if (supportFilesByGlob.length > 1) {
return errors.throwErr('MULTIPLE_SUPPORT_FILES_FOUND', obj.supportFile, supportFilesByGlob)
Expand Down
22 changes: 20 additions & 2 deletions packages/server/test/unit/config_spec.js
Expand Up @@ -2086,7 +2086,7 @@ describe('lib/config', () => {
})
})

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

const obj = config.setAbsolutePaths({
Expand All @@ -2104,6 +2104,24 @@ describe('lib/config', () => {
})
})

it('finds support file in project path that contains glob syntax', () => {
const projectRoot = Fixtures.projectPath('project-with-(glob)-[chars]')

const obj = config.setAbsolutePaths({
projectRoot,
supportFile: 'cypress/support/e2e.js',
})

return config.setSupportFileAndFolder(obj)
.then((result) => {
expect(result).to.eql({
projectRoot,
supportFile: `${projectRoot}/cypress/support/e2e.js`,
supportFolder: `${projectRoot}/cypress/support`,
})
})
})

it('sets the supportFile to false if it does not exist, support folder exists, and supportFile is the default', () => {
const projectRoot = Fixtures.projectPath('empty-folders')

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

return ['fileServerFolder', 'fixturesFolder', 'supportFile'].forEach((folder) => {
return ['fileServerFolder', 'fixturesFolder'].forEach((folder) => {
it(`converts relative ${folder} to absolute path`, () => {
const obj = {
projectRoot: '/_test-output/path/to/project',
Expand Down
59 changes: 59 additions & 0 deletions system-tests/__snapshots__/config_spec.js
Expand Up @@ -423,3 +423,62 @@ Please remove this option or add this as an e2e testing type property: e2e.exper
https://on.cypress.io/migration-guide
`

exports['e2e config finds supportFiles in projects containing glob syntax 1'] = `
====================================================================================================
(Run Starting)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 1 found (app.cy.js) │
│ Searched: cypress/e2e/**/*.cy.{js,jsx,ts,tsx} │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: app.cy.js (1 of 1)
✓ is true
1 passing
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: X seconds │
│ Spec Ran: app.cy.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /XXX/XXX/XXX/cypress/videos/app.cy.js.mp4 (X second)
====================================================================================================
(Run Finished)
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✔ app.cy.js XX:XX 1 1 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✔ All specs passed! XX:XX 1 1 - - -
`
2 changes: 1 addition & 1 deletion system-tests/__snapshots__/multiple_support_files_spec.js
@@ -1,7 +1,7 @@
exports['e2e multiple support files passes 1'] = `
There were multiple support files found matching your supportFile pattern.
Your supportFile is set to: /foo/bar/.projects/multiple-support-files/cypress/support/e2e.{js,jsx,ts,tsx}
Your supportFile is set to: cypress/support/e2e.{js,jsx,ts,tsx}
We found the following files:
Expand Down
@@ -0,0 +1,3 @@
module.exports = {
e2e: { },
}
@@ -0,0 +1,3 @@
it('is true', () => {
expect(true).to.be.true
})
Empty file.
9 changes: 9 additions & 0 deletions system-tests/test/config_spec.js
Expand Up @@ -236,4 +236,13 @@ describe('e2e config', () => {
snapshot: true,
})
})

it('finds supportFiles in projects containing glob syntax', async function () {
await Fixtures.scaffoldProject('project-with-(glob)-[chars]')

return systemTests.exec(this, {
project: 'project-with-(glob)-[chars]',
snapshot: true,
})
})
})

0 comments on commit 886ef61

Please sign in to comment.