mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-06 06:29:45 -06:00
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 <mjhenkes@gmail.com>
This commit is contained in:
@@ -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',
|
||||
}, {
|
||||
|
||||
@@ -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')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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({
|
||||
@@ -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')
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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 - - -
|
||||
|
||||
|
||||
`
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
e2e: { },
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
it('is true', () => {
|
||||
expect(true).to.be.true
|
||||
})
|
||||
@@ -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,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user