Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't include project path with supportFile glob #22222

Merged
merged 10 commits into from Jun 10, 2022
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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was kinda weird. supportFile was always a file, not a folder, but pre-10.0 we benefited from having the absolute path pre-generated for us prior to resolving the module.

I removed this because 1. it's not a folder and 2. we don't want the absolute path to be appended unknowingly to a glob pattern.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It used to be called supportFolder a long time ago, maybe hold over from then.

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were getting an absolute path prior to this change because obj.supportFile was an absolute path. Now that it's not an absolute path, we need to ensure absolute paths are returned by the results (absolute is true by default in getFilesByGlob)


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 () {
tbiethman marked this conversation as resolved.
Show resolved Hide resolved
await Fixtures.scaffoldProject('project-with-(glob)-[chars]')

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