Skip to content

Commit

Permalink
fix: retain original array after defaultsDeep #27240 (#27312)
Browse files Browse the repository at this point in the history
* modifying object after array combination to hold older values

* regression test

* made suggested changes

* config defaults

* log

* logs

* log

* log again

* update log

* changelog

* updates changelog

* fix typo and move changelog entry and fix link

---------

Co-authored-by: Nihar Phansalkar <phansalkarnihar@gmail.com>
Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
Co-authored-by: Cacie Prins <cacieprins@users.noreply.github.com>
Co-authored-by: Cacie Prins <cacie@cypress.io>
Co-authored-by: AtofStryker <bglesias@gmail.com>
  • Loading branch information
6 people committed Mar 26, 2024
1 parent d4cab4d commit 8b482e9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
8 changes: 8 additions & 0 deletions cli/CHANGELOG.md
@@ -1,4 +1,12 @@
<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->
## 13.7.2

_Released 4/2/2024 (PENDING)_

**Bugfixes:**

- Fixed a bug where fields using arrays in `cypress.config` are not correctly processed. Fixes [#27103](https://github.com/cypress-io/cypress/issues/27103). Fixed in [#27312](https://github.com/cypress-io/cypress/pull/27312).

## 13.7.1

_Released 3/26/2024 (PENDING)_
Expand Down
Expand Up @@ -444,6 +444,40 @@ e2e: {

cy.get('[data-cy="file-match-indicator"]', { timeout: 7500 })
.should('contain', '3 matches')

// Regression for https://github.com/cypress-io/cypress/issues/27103
cy.withCtx(async (ctx) => {
await ctx.actions.file.writeFileInProject('cypress.config.js',
`
module.exports = {
projectId: 'abc123',
experimentalInteractiveRunEvents: true,
component: {
specPattern: 'src/**/*.{spec,cy}.{js,jsx,ts,tsx}',
supportFile: false,
devServer: {
framework: 'react',
bundler: 'webpack',
}
},
e2e: {
specPattern: ['cypress/e2e/**/dom-cont*.spec.{js,ts}'],
supportFile: false,
setupNodeEvents(on, config) {
/**
* This should make Cypress yield a "no specs found" error.
*
* This stops being the case if 'specPattern' is an array.
*/
config.specPattern = [];
return config;
},
},
}`)
})

cy.get('[data-cy="create-spec-page-title"]')
.should('contain', defaultMessages.createSpec.page.customPatternNoSpecs.title)
})
})
})
10 changes: 9 additions & 1 deletion packages/config/src/project/index.ts
Expand Up @@ -105,8 +105,16 @@ export function updateWithPluginValues (cfg: FullConfig, modifiedConfig: any, te
debug('resolved config object %o', cfg.resolved)
}

const diffsClone = _.cloneDeep(diffs) ?? {}

// merge cfg into overrides
const merged = _.defaultsDeep(diffs, cfg)
const merged = _.defaultsDeep(diffs, cfg) ?? {}

for (const [key, value] of Object.entries(diffsClone)) {
if (Array.isArray(value)) {
merged[key] = _.cloneDeep(value)
}
}

debug('merged config object %o', merged)

Expand Down

0 comments on commit 8b482e9

Please sign in to comment.