Skip to content

Commit

Permalink
perf: improve performance when finding unique selectors for Test Repl…
Browse files Browse the repository at this point in the history
…ay (#28536)
  • Loading branch information
mschile authored Dec 15, 2023
1 parent 17eea15 commit fa971f1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 24 deletions.
4 changes: 4 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ _Released 12/19/2023 (PENDING)_
- Fixed a regression in [`13.6.1`](https://docs.cypress.io/guides/references/changelog/13.6.1) where a malformed URI would crash Cypress. Fixes [#28521](https://github.com/cypress-io/cypress/issues/28521).
- Fixed a regression in [`12.4.0`](https://docs.cypress.io/guides/references/changelog/12.4.0) where erroneous `<br>` tags were displaying in error messages in the Command Log making them less readable. Fixes [#28452](https://github.com/cypress-io/cypress/issues/28452).

**Performance:**

- Improved performance when finding unique selectors for command log snapshots for Test Replay. Addressed in [#28536](https://github.com/cypress-io/cypress/pull/28536).

**Dependency Updates:**

- Updated ts-node from `10.9.1` to `10.9.2`. Fixed in [#28528](https://github.com/cypress-io/cypress/pull/28528).
Expand Down
1 change: 1 addition & 0 deletions packages/driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@cypress/webpack-dev-server": "0.0.0-development",
"@cypress/webpack-preprocessor": "0.0.0-development",
"@cypress/what-is-circular": "1.0.1",
"@medv/finder": "3.1.0",
"@packages/config": "0.0.0-development",
"@packages/network": "0.0.0-development",
"@packages/rewriter": "0.0.0-development",
Expand Down
16 changes: 4 additions & 12 deletions packages/driver/src/cy/snapshots.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import $ from 'jquery'
import _ from 'lodash'
import uniqueSelector from '@cypress/unique-selector'
import type { $Cy } from '../cypress/cy'
import type { StateFunc } from '../cypress/state'
import $dom from '../dom'
import { create as createSnapshotsCSS } from './snapshots_css'
import { debug as Debug } from 'debug'

const debug = Debug('cypress:driver:snapshots')
import { finder } from '@medv/finder'

export const HIGHLIGHT_ATTR = 'data-cypress-el'

Expand Down Expand Up @@ -272,14 +269,9 @@ export const create = ($$: $Cy['$$'], state: StateFunc) => {
return []
}

const selector = uniqueSelector(el)

if (!selector) {
debug('could not find a unique selector for element %o', el)

return []
}

// finder tries to find the shortest unique selector to an element,
// but since we are more concerned with speed, we set the threshold to 1 and maxNumberOfTries to 0
const selector = finder(el, { root: ownerDoc.body, threshold: 1, maxNumberOfTries: 0 })
const frameId = elWindow['__cypressProtocolMetadata']?.frameId

return [{ selector, frameId }]
Expand Down
2 changes: 1 addition & 1 deletion packages/network/lib/uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// - https://nodejs.org/api/url.html#url_url_format_urlobject

import _ from 'lodash'
import url, { URL } from 'url'
import url from 'url'

// yup, protocol contains a: ':' colon
// at the end of it (-______________-)
Expand Down
22 changes: 11 additions & 11 deletions system-tests/__snapshots__/protocol_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4814,7 +4814,7 @@ exports['e2e events'] = `
"timestamp": "Any.Number",
"elementsToHighlight": [
{
"selector": "h1"
"selector": "h1:nth-child(1)"
}
]
}
Expand Down Expand Up @@ -4846,7 +4846,7 @@ exports['e2e events'] = `
"timestamp": "Any.Number",
"elementsToHighlight": [
{
"selector": "h1"
"selector": "h1:nth-child(1)"
}
]
},
Expand All @@ -4855,7 +4855,7 @@ exports['e2e events'] = `
"timestamp": "Any.Number",
"elementsToHighlight": [
{
"selector": "h1"
"selector": "h1:nth-child(1)"
}
]
}
Expand Down Expand Up @@ -6277,7 +6277,7 @@ exports['component events - experimentalSingleTabRunMode: true'] = `
"timestamp": "Any.Number",
"elementsToHighlight": [
{
"selector": ":nth-child(1) > div"
"selector": "div:nth-child(1) > div:nth-child(1)"
}
]
}
Expand Down Expand Up @@ -6308,7 +6308,7 @@ exports['component events - experimentalSingleTabRunMode: true'] = `
"timestamp": "Any.Number",
"elementsToHighlight": [
{
"selector": ":nth-child(1) > div"
"selector": "div:nth-child(1) > div:nth-child(1)"
}
]
}
Expand Down Expand Up @@ -6561,7 +6561,7 @@ exports['component events - experimentalSingleTabRunMode: true'] = `
"timestamp": "Any.Number",
"elementsToHighlight": [
{
"selector": ":nth-child(1) > div"
"selector": "div:nth-child(1) > div:nth-child(1)"
}
]
}
Expand Down Expand Up @@ -6592,7 +6592,7 @@ exports['component events - experimentalSingleTabRunMode: true'] = `
"timestamp": "Any.Number",
"elementsToHighlight": [
{
"selector": ":nth-child(1) > div"
"selector": "div:nth-child(1) > div:nth-child(1)"
}
]
}
Expand Down Expand Up @@ -8016,7 +8016,7 @@ exports['component events - experimentalSingleTabRunMode: false'] = `
"timestamp": "Any.Number",
"elementsToHighlight": [
{
"selector": ":nth-child(1) > div"
"selector": "div:nth-child(1) > div:nth-child(1)"
}
]
}
Expand Down Expand Up @@ -8047,7 +8047,7 @@ exports['component events - experimentalSingleTabRunMode: false'] = `
"timestamp": "Any.Number",
"elementsToHighlight": [
{
"selector": ":nth-child(1) > div"
"selector": "div:nth-child(1) > div:nth-child(1)"
}
]
}
Expand Down Expand Up @@ -8300,7 +8300,7 @@ exports['component events - experimentalSingleTabRunMode: false'] = `
"timestamp": "Any.Number",
"elementsToHighlight": [
{
"selector": ":nth-child(1) > div"
"selector": "div:nth-child(1) > div:nth-child(1)"
}
]
}
Expand Down Expand Up @@ -8331,7 +8331,7 @@ exports['component events - experimentalSingleTabRunMode: false'] = `
"timestamp": "Any.Number",
"elementsToHighlight": [
{
"selector": ":nth-child(1) > div"
"selector": "div:nth-child(1) > div:nth-child(1)"
}
]
}
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4438,6 +4438,11 @@
lodash "^4.17.15"
tmp-promise "^3.0.2"

"@medv/[email protected]":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@medv/finder/-/finder-3.1.0.tgz#e157c68f166ade9f113a1314603365bf81dd8b8c"
integrity sha512-ojkXjR3K0Zz3jnCR80tqPL+0yvbZk/lEodb6RIVjLz7W8RVA2wrw8ym/CzCpXO9SYVUIKHFUpc7jvf8UKfIM3w==

"@microsoft/[email protected]":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@microsoft/fetch-event-source/-/fetch-event-source-2.0.1.tgz#9ceecc94b49fbaa15666e38ae8587f64acce007d"
Expand Down

4 comments on commit fa971f1

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on fa971f1 Dec 15, 2023

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.2/linux-x64/develop-fa971f1bc8afe1db06acb1dbe7604a4a2f757013/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on fa971f1 Dec 15, 2023

Choose a reason for hiding this comment

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

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.2/linux-arm64/develop-fa971f1bc8afe1db06acb1dbe7604a4a2f757013/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on fa971f1 Dec 15, 2023

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.2/darwin-x64/develop-fa971f1bc8afe1db06acb1dbe7604a4a2f757013/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on fa971f1 Dec 15, 2023

Choose a reason for hiding this comment

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

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.2/win32-x64/develop-fa971f1bc8afe1db06acb1dbe7604a4a2f757013/cypress.tgz

Please sign in to comment.