Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Refactor k6 VU and tests #315

Merged
merged 1 commit into from
May 19, 2022
Merged

Refactor k6 VU and tests #315

merged 1 commit into from
May 19, 2022

Conversation

inancgumus
Copy link
Member

@inancgumus inancgumus commented May 18, 2022

This PR refactors the VU usage in the extension.

  • Removes rt, state, and samples fields from the test browser according to the new k6 modules interface.
  • newMockVU was duplicated. This commit moves it into a new package named k6.
  • Replaces mockVU with vu for brevity.
  • Instead of crowding the common package (which is already big), moves the handling of VUs in contexts to the k6 package. And testing into the k6test package.
  • Provides helper methods for the functions we need to use frequently.

Renamings:

  • mockVu -> vu
  • mockVU.RuntimeField.ToValue -> vu.ToGojaValue
  • tests/test_browser.go runtime|toGojaValue
  • test_context.go mockVU/newMockVU -> k6test.VU k6test.NewVU
  • common/helpers_test.go mockVU/newMockVU -> k6test.VU k6test.NewVU
  • GetVU(ctx).Runtime() -> k6.Runtime(ctx)
  • vu.CtxField -> vu.Context()
  • common.WithVU -> k6.WithVU
  • common.GetVU -> k6.GetVU

@inancgumus inancgumus requested a review from ankur22 May 18, 2022 14:33
@inancgumus inancgumus added this to the v0.4.0 milestone May 18, 2022
@inancgumus inancgumus self-assigned this May 18, 2022
@inancgumus inancgumus force-pushed the refactor/mock-vu branch 5 times, most recently from 99f13df to 1013570 Compare May 18, 2022 15:19
@inancgumus
Copy link
Member Author

inancgumus commented May 18, 2022

Hey, @ankur22, thanks for your review 🙏

I made the following changes according to your suggestions.

I split the k6 package into k6 and k6test (in the same sense http/httptest).

Renamings:

  • RT -> Runtime
  • k6.NewMockVU -> k6test.NewVU
  • V -> ToGojaValue
  • TestBrowser.RT|V -> .runtime|toGojaValue

By the way, note that I needed to remove the gci linter as it seems buggy, and I couldn't figure out how to solve the problem. For example, it says common/browser_context_options_test.go:7:1 gci Expected '\t', Found '\n' at common/browser_context_options_test.go[line 7,col 1] for the following file:

package common

import (
	"testing"

	"github.com/grafana/xk6-browser/k6/k6test"

	"github.com/stretchr/testify/assert"
)

// ...other content here

And there is no problem with that file. Please let me know if you have an idea.

Update: I guess I found a solution to this problem in #316 🥳

inancgumus added a commit that referenced this pull request May 18, 2022
Renamings:

* `RT` -> `Runtime`
* `k6.NewMockVU` -> `k6test.NewVU`
* `V` -> `ToGojaValue`
* `TestBrowser.RT|V` -> `.runtime|toGojaValue`

I split the `k6` package into `k6` and `k6test`. By the way, note that
I needed to use `//nolint` in a couple of places because the gci linter
has bugs that prevent me from passing the linter
(see: daixiang0/gci#59).
@inancgumus inancgumus requested a review from ankur22 May 18, 2022 20:43
inancgumus added a commit that referenced this pull request May 18, 2022
Renamings:

* `RT` -> `Runtime`
* `k6.NewMockVU` -> `k6test.NewVU`
* `V` -> `ToGojaValue`
* `TestBrowser.RT|V` -> `.runtime|toGojaValue`

I split the `k6` package into `k6` and `k6test`. By the way, note that
I needed to use `//nolint` in a couple of places because the gci linter
has bugs that prevent me from passing the linter
(see: daixiang0/gci#59).
inancgumus added a commit that referenced this pull request May 18, 2022
Renamings:

* `RT` -> `Runtime`
* `k6.NewMockVU` -> `k6test.NewVU`
* `V` -> `ToGojaValue`
* `TestBrowser.RT|V` -> `.runtime|toGojaValue`

I split the `k6` package into `k6` and `k6test`. By the way, note that
I needed to use `//nolint` in a couple of places because the gci linter
has bugs that prevent me from passing the linter
(see: daixiang0/gci#59).
@inancgumus inancgumus mentioned this pull request May 18, 2022
- newMockVU was duplicated. This commit moves it into a new package
  named k6.
- Replaces "mockVU" to "vu" for brevity.
- Instead of crowding the common package (which is already big), moves
  the handling of VUs in contexts to the k6 package.
- Provides helper methods in the k6 package for the function that we
  need to use frequently.
- Splits the `k6` package into `k6` and `k6test`.
@inancgumus inancgumus merged commit 6ae2f1f into main May 19, 2022
@inancgumus inancgumus deleted the refactor/mock-vu branch May 19, 2022 10:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants