From f2894c474010625050f1b417c6b4586b72a53a1f Mon Sep 17 00:00:00 2001 From: Mikhail Date: Mon, 3 Jun 2024 20:53:00 +0300 Subject: [PATCH] perf: optimize reduce in wrapConsoleProps (#29501) * fix: optimize reduce in wrapConsoleProps * Added changelog notes * Update changelog entry --------- Co-authored-by: Cacie Prins Co-authored-by: Jennifer Shehane --- cli/CHANGELOG.md | 4 ++++ packages/driver/src/cypress/log.ts | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 390f71d085b1..a3952f027c7d 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -7,6 +7,10 @@ _Released 6/4/2024 (PENDING)_ - Added support for [Next.js 14](https://nextjs.org/blog/next-14) for component testing. Addresses [#28185](https://github.com/cypress-io/cypress/issues/28185). +**Performance:** + +- Improved performance when setting console props within `Cypress.log`. Addressed in [#29501](https://github.com/cypress-io/cypress/pull/29501). + **Bugfixes:** - Pre-emptively fix behavior with Chrome for when `unload` events are forcefully deprecated by using `pagehide` as a proxy. Fixes [#29241](https://github.com/cypress-io/cypress/issues/29241). diff --git a/packages/driver/src/cypress/log.ts b/packages/driver/src/cypress/log.ts index cae0752593ea..18c886b2972b 100644 --- a/packages/driver/src/cypress/log.ts +++ b/packages/driver/src/cypress/log.ts @@ -569,7 +569,11 @@ export class Log { const expectedProperties = ['name', 'type', 'error', 'snapshot', 'args', 'groups', 'table', 'props'] const expectedPropertiesObj = _.reduce(_.pick(consoleObjResult, expectedProperties), (memo, value, key) => { // don't include properties with undefined values - return value === undefined ? memo : _.extend(memo, { [key]: value }) + if (value !== undefined) { + memo[key] = value + } + + return memo }, consoleObj) // any other key/value pairs need to be added to the `props` property const rest = _.omit(consoleObjResult, expectedProperties)