Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor k6 object and add testRunID #1235

Merged
merged 4 commits into from Mar 7, 2024
Merged

Conversation

ankur22
Copy link
Collaborator

@ankur22 ankur22 commented Mar 5, 2024

What?

The first few commits refactor how the k6 object is assigned to the window object. Instead of it being done implicitly in the NewBrowserContext constructor, it is now done in the mapping layer after a new browserContext has been created, which is when browser.newPage and browser.newContext are called.

The last commit adds a new field in the k6 object which is testRunId.

Why?

  • The refactor makes it more explicit when a init script is added, instead of it being hidden.
  • It remove the difficult to expand embedded approach to adding the k6 object to window.
  • Adds testRunId to k6 which enables external apps (such as Faro) to link back to the test run.

Checklist

  • I have performed a self-review of my code
  • I have added tests for my changes
  • I have commented on my code, particularly in hard-to-understand areas

Related PR(s)/Issue(s)

https://github.com/grafana/k6-cloud/issues/2066

@ankur22 ankur22 force-pushed the refactor/k6-object-mapping branch 2 times, most recently from 6d15f8a to f7b0ebb Compare March 5, 2024 15:58
This helps it be explicit and easier to spot instead of it being hidden
within the creation of a new browser context.
This is now being performed in newPage which is more explicit, whereas
the previous approach (which is being removed) was too implicit and not
extendable.
This will allow callers to pass the NewVU opts, e.g. to set env vars.
We can now add the testRunId to the k6 object which is injected into
the page, allowing external apps to work with the k6 object, while also
allowing them to link back to the test run id.
@ankur22 ankur22 force-pushed the refactor/k6-object-mapping branch from 6652248 to dd33903 Compare March 5, 2024 16:25
Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

Nice!

@ankur22 ankur22 merged commit 93edd08 into main Mar 7, 2024
17 checks passed
@ankur22 ankur22 deleted the refactor/k6-object-mapping branch March 7, 2024 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants