This repository has been archived by the owner on Jan 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b478107
commit 7ea8e2a
Showing
2 changed files
with
39 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/dop251/goja" | ||
"github.com/grafana/xk6-browser/browser" | ||
"github.com/grafana/xk6-browser/k6ext/k6test" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// startIteration will work with the event system to start chrome and | ||
// (more importantly) set browser as the mapped browser instance which will | ||
// force all tests that work with this to go through the mapping layer. | ||
// This returns a cleanup function which should be deferred. | ||
// The opts are passed to k6test.NewVU as is without any modification. | ||
func startIteration(t *testing.T, opts ...any) (*k6test.VU, *goja.Runtime, *[]string, func()) { | ||
t.Helper() | ||
|
||
vu := k6test.NewVU(t, opts...) | ||
rt := vu.Runtime() | ||
|
||
mod := browser.New().NewModuleInstance(vu) | ||
jsMod, ok := mod.Exports().Default.(*browser.JSModule) | ||
require.Truef(t, ok, "unexpected default mod export type %T", mod.Exports().Default) | ||
|
||
// Setting the mapped browser into the vu's goja runtime. | ||
require.NoError(t, rt.Set("browser", jsMod.Browser)) | ||
|
||
// Setting log, which is used by the callers to assert that certain actions | ||
// have been made. | ||
var log []string | ||
require.NoError(t, rt.Set("log", func(s string) { log = append(log, s) })) | ||
|
||
vu.ActivateVU() | ||
vu.StartIteration(t) | ||
|
||
return vu, rt, &log, func() { t.Helper(); vu.EndIteration(t) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters