Add single() to k6/html selections#6002
Conversation
|
|
There was a problem hiding this comment.
Pull request overview
This PR adds a new selection.single(selector) API to the k6/html module, intended to provide an optimized equivalent to find(selector).first() by leveraging goquery.Single(selector).
Changes:
- Added
Selection.Single(selector string)tojs/modules/k6/htmlbacked bygoquery.Single(selector). - Added JS-facing tests for the new
single()selection method. - Modernized a non-Linux build-tag file by removing the legacy
// +builddirective.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
js/modules/k6/html/html.go |
Adds the new Selection.Single() method that powers selection.single() in JS. |
js/modules/k6/html/html_test.go |
Adds unit tests covering single() basic behavior, chaining, and no-match behavior. |
internal/js/modules/k6/browser/common/kill_other.go |
Removes legacy build tag comment, relying on //go:build only. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi @rohan-patnaik, can you check the CoPilot review suggestions, please? Thanks! |
98a0400 to
7a78188
Compare
|
@inancgumus addressed the Copilot suggestions and updated the branch. |
7a78188 to
a23361b
Compare
a23361b to
5a6a7d7
Compare
|
@inancgumus resolved the additional Copilot comments. |
|
@mstoykov, I've approved this PR. |
|
Thanks @mstoykov! Will look into the docs update once I have a bit more bandwidth. |
|
@rohan-patnaik, you can use the k6-docs skill from the grafana/skills repository for writing idiomatic docs. |
Adds
selection.single(selector)tok6/html, backed bygoquery.Single(selector).This gives scripts a direct way to select only the first matching descendant instead of collecting all matches with
find(selector).first().Closes #2161.
Testing:
make lintgo test ./js/modules/k6/htmlgo test -race ./js/modules/k6/htmlgo test ./js/modules/k6/httpGOMAXPROCS=1 go test -p 1 -timeout 1600s ./internal/js/modules/k6/browser/tests/...make check; lint passes, but the repo-wide race suite still fails locally when browser tests run with the defaultgo test ./...parallelism.Checklist:
make check