Skip to content

Add single() to k6/html selections#6002

Merged
mstoykov merged 2 commits into
grafana:masterfrom
rohan-patnaik:add-html-single-selection
Jun 11, 2026
Merged

Add single() to k6/html selections#6002
mstoykov merged 2 commits into
grafana:masterfrom
rohan-patnaik:add-html-single-selection

Conversation

@rohan-patnaik

@rohan-patnaik rohan-patnaik commented May 16, 2026

Copy link
Copy Markdown
Contributor

Adds selection.single(selector) to k6/html, backed by goquery.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 lint
  • go test ./js/modules/k6/html
  • go test -race ./js/modules/k6/html
  • go test ./js/modules/k6/http
  • GOMAXPROCS=1 go test -p 1 -timeout 1600s ./internal/js/modules/k6/browser/tests/...
  • Retried full make check; lint passes, but the repo-wide race suite still fails locally when browser tests run with the default go test ./... parallelism.

Checklist:

  • Self-reviewed
  • Added tests
  • Ran full make check

@rohan-patnaik
rohan-patnaik requested a review from a team as a code owner May 16, 2026 18:56
@rohan-patnaik
rohan-patnaik requested review from inancgumus and mstoykov and removed request for a team May 16, 2026 18:56
@cla-assistant

cla-assistant Bot commented May 16, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cla-assistant

cla-assistant Bot commented May 16, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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) to js/modules/k6/html backed by goquery.Single(selector).
  • Added JS-facing tests for the new single() selection method.
  • Modernized a non-Linux build-tag file by removing the legacy // +build directive.

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.

Comment thread js/modules/k6/html/html.go Outdated
Comment thread js/modules/k6/html/html_test.go Outdated
Comment thread js/modules/k6/html/html_test.go
@inancgumus

Copy link
Copy Markdown
Contributor

Hi @rohan-patnaik, can you check the CoPilot review suggestions, please? Thanks!

@rohan-patnaik
rohan-patnaik force-pushed the add-html-single-selection branch from 98a0400 to 7a78188 Compare June 9, 2026 17:26
@rohan-patnaik

Copy link
Copy Markdown
Contributor Author

@inancgumus addressed the Copilot suggestions and updated the branch.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread js/modules/k6/html/html.go
@rohan-patnaik
rohan-patnaik force-pushed the add-html-single-selection branch from a23361b to 5a6a7d7 Compare June 9, 2026 17:48
@rohan-patnaik

Copy link
Copy Markdown
Contributor Author

@inancgumus resolved the additional Copilot comments.
Hopefully no more feedback comments!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@rohan-patnaik
rohan-patnaik temporarily deployed to azure-trusted-signing June 9, 2026 18:30 — with GitHub Actions Inactive
@rohan-patnaik
rohan-patnaik temporarily deployed to azure-trusted-signing June 9, 2026 18:32 — with GitHub Actions Inactive
@inancgumus

Copy link
Copy Markdown
Contributor

@mstoykov, I've approved this PR.

@mstoykov mstoykov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thank you for the change!

Would you like to open a PR to add thsi to the docs as well

@mstoykov mstoykov added the documentation-needed A PR which will need a separate PR for documentation label Jun 11, 2026
@mstoykov mstoykov added this to the v2.1.0 milestone Jun 11, 2026
@mstoykov
mstoykov merged commit 8b92155 into grafana:master Jun 11, 2026
51 of 54 checks passed
@rohan-patnaik

rohan-patnaik commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @mstoykov! Will look into the docs update once I have a bit more bandwidth.

@inancgumus

Copy link
Copy Markdown
Contributor

@rohan-patnaik, you can use the k6-docs skill from the grafana/skills repository for writing idiomatic docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation-needed A PR which will need a separate PR for documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update goquery and add new Single method to k6/html

4 participants