From c22382cc6d52c047c0eae9dd1f144d0728b6211e Mon Sep 17 00:00:00 2001 From: Tyler Biethman Date: Thu, 9 Jun 2022 08:54:11 -0500 Subject: [PATCH 1/7] fix: Don't glob project path in supportFile lookup --- packages/config/src/options.ts | 1 - packages/server/lib/config.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/config/src/options.ts b/packages/config/src/options.ts index fd583e6d2799..7b708a032eea 100644 --- a/packages/config/src/options.ts +++ b/packages/config/src/options.ts @@ -351,7 +351,6 @@ const resolvedOptions: Array = [ name: 'supportFile', defaultValue: (options: Record = {}) => 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', }, { diff --git a/packages/server/lib/config.ts b/packages/server/lib/config.ts index b230a753436d..675fd5a80c7f 100644 --- a/packages/server/lib/config.ts +++ b/packages/server/lib/config.ts @@ -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) From 26d30c0fc934aecd698f7811b5f61d7b24880128 Mon Sep 17 00:00:00 2001 From: Tyler Biethman Date: Thu, 9 Jun 2022 09:06:03 -0500 Subject: [PATCH 2/7] Updating unit tests around supportFile 'isFolder' --- packages/server/test/unit/config_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/test/unit/config_spec.js b/packages/server/test/unit/config_spec.js index e9cefcd53e0d..260bf1091a47 100644 --- a/packages/server/test/unit/config_spec.js +++ b/packages/server/test/unit/config_spec.js @@ -2218,7 +2218,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', From 1ab1893a879be74d0513b1ba2b09fb797d9034e0 Mon Sep 17 00:00:00 2001 From: Tyler Biethman Date: Thu, 9 Jun 2022 09:22:18 -0500 Subject: [PATCH 3/7] Adding unit test to validate the projectRoot isn't globbed --- packages/server/test/unit/config_spec.js | 20 ++++++++++++++++++- .../cypress.config.js | 3 +++ .../cypress/e2e/app.cy.js | 3 +++ .../cypress/support/e2e.js | 0 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 system-tests/projects/project-with-(glob)-[chars]/cypress.config.js create mode 100644 system-tests/projects/project-with-(glob)-[chars]/cypress/e2e/app.cy.js create mode 100644 system-tests/projects/project-with-(glob)-[chars]/cypress/support/e2e.js diff --git a/packages/server/test/unit/config_spec.js b/packages/server/test/unit/config_spec.js index 260bf1091a47..b6f2aea390de 100644 --- a/packages/server/test/unit/config_spec.js +++ b/packages/server/test/unit/config_spec.js @@ -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 *.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({ @@ -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') diff --git a/system-tests/projects/project-with-(glob)-[chars]/cypress.config.js b/system-tests/projects/project-with-(glob)-[chars]/cypress.config.js new file mode 100644 index 000000000000..80ff2ec38021 --- /dev/null +++ b/system-tests/projects/project-with-(glob)-[chars]/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + e2e: { }, +} diff --git a/system-tests/projects/project-with-(glob)-[chars]/cypress/e2e/app.cy.js b/system-tests/projects/project-with-(glob)-[chars]/cypress/e2e/app.cy.js new file mode 100644 index 000000000000..7258e472bd59 --- /dev/null +++ b/system-tests/projects/project-with-(glob)-[chars]/cypress/e2e/app.cy.js @@ -0,0 +1,3 @@ +it('is true', () => { + expect(true).to.be.true +}) diff --git a/system-tests/projects/project-with-(glob)-[chars]/cypress/support/e2e.js b/system-tests/projects/project-with-(glob)-[chars]/cypress/support/e2e.js new file mode 100644 index 000000000000..e69de29bb2d1 From 5ee91e3fc149fe637b3a4285be568e941f175721 Mon Sep 17 00:00:00 2001 From: Tyler Biethman Date: Thu, 9 Jun 2022 09:34:56 -0500 Subject: [PATCH 4/7] Adding system test to validate successful run --- system-tests/__snapshots__/config_spec.js | 59 +++++++++++++++++++++++ system-tests/test/config_spec.js | 9 ++++ 2 files changed, 68 insertions(+) diff --git a/system-tests/__snapshots__/config_spec.js b/system-tests/__snapshots__/config_spec.js index 5016701848ec..d12efa93e073 100644 --- a/system-tests/__snapshots__/config_spec.js +++ b/system-tests/__snapshots__/config_spec.js @@ -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 - - - + + +` diff --git a/system-tests/test/config_spec.js b/system-tests/test/config_spec.js index 17bf745d0a1f..89c2a0380081 100644 --- a/system-tests/test/config_spec.js +++ b/system-tests/test/config_spec.js @@ -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, + }) + }) }) From 043f99aaa030537db0de1ca7ee25a38407921425 Mon Sep 17 00:00:00 2001 From: Tyler Biethman Date: Thu, 9 Jun 2022 09:39:50 -0500 Subject: [PATCH 5/7] This is more accurate --- packages/server/test/unit/config_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/test/unit/config_spec.js b/packages/server/test/unit/config_spec.js index b6f2aea390de..13e9e66c480a 100644 --- a/packages/server/test/unit/config_spec.js +++ b/packages/server/test/unit/config_spec.js @@ -2086,7 +2086,7 @@ describe('lib/config', () => { }) }) - it('sets the supportFile to default *.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({ From 565222bb3c8c5522a0b79712503d3a23a7744579 Mon Sep 17 00:00:00 2001 From: Tyler Biethman Date: Thu, 9 Jun 2022 10:17:21 -0500 Subject: [PATCH 6/7] Updating snapshot to reflect now missing absolute path from the supportFile value --- system-tests/__snapshots__/multiple_support_files_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system-tests/__snapshots__/multiple_support_files_spec.js b/system-tests/__snapshots__/multiple_support_files_spec.js index acf6c8d84b45..21bb6a5a1698 100644 --- a/system-tests/__snapshots__/multiple_support_files_spec.js +++ b/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: From 05d3228eb9770377c229573b9c01dd6c9d7c2bb0 Mon Sep 17 00:00:00 2001 From: Tyler Biethman Date: Thu, 9 Jun 2022 11:41:49 -0500 Subject: [PATCH 7/7] Adding e2 launchpad test --- packages/launchpad/cypress/e2e/open-mode.cy.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/launchpad/cypress/e2e/open-mode.cy.ts b/packages/launchpad/cypress/e2e/open-mode.cy.ts index d6031b372968..e6804e2e572f 100644 --- a/packages/launchpad/cypress/e2e/open-mode.cy.ts +++ b/packages/launchpad/cypress/e2e/open-mode.cy.ts @@ -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') + }) })