diff --git a/cmd/tests/cmd_run_test.go b/cmd/tests/cmd_run_test.go index 0df7021af5dd..4472ae21a1d4 100644 --- a/cmd/tests/cmd_run_test.go +++ b/cmd/tests/cmd_run_test.go @@ -1827,80 +1827,6 @@ func BenchmarkReadResponseBody(b *testing.B) { cmd.ExecuteWithGlobalState(ts.GlobalState) } -func TestBrowserPermissions(t *testing.T) { - t.Parallel() - - tests := []struct { - name string - envVarValue string - envVarMsgValue string - expectedExitCode exitcodes.ExitCode - expectedError string - }{ - { - name: "no env var set", - envVarValue: "", - expectedExitCode: 107, - expectedError: "To run browser tests set env var K6_BROWSER_ENABLED=true", - }, - { - name: "env var set but set to false", - envVarValue: "false", - expectedExitCode: 107, - expectedError: "To run browser tests set env var K6_BROWSER_ENABLED=true", - }, - { - name: "env var set but set to 09adsu", - envVarValue: "09adsu", - expectedExitCode: 107, - expectedError: "To run browser tests set env var K6_BROWSER_ENABLED=true", - }, - { - name: "with custom message", - envVarValue: "09adsu", - envVarMsgValue: "Try again later", - expectedExitCode: 107, - expectedError: "Try again later", - }, - { - name: "env var set and set to true", - envVarValue: "true", - expectedExitCode: 0, - expectedError: "", - }, - } - - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - t.Parallel() - script := ` - import { chromium } from 'k6/experimental/browser'; - - export default function() {}; - ` - - ts := getSingleFileTestState(t, script, []string{}, tt.expectedExitCode) - if tt.envVarValue != "" { - ts.Env["K6_BROWSER_ENABLED"] = tt.envVarValue - } - if tt.envVarMsgValue != "" { - ts.Env["K6_BROWSER_ENABLED_MSG"] = tt.envVarMsgValue - } - cmd.ExecuteWithGlobalState(ts.GlobalState) - - loglines := ts.LoggerHook.Drain() - - if tt.expectedError == "" { - require.Len(t, loglines, 0) - return - } - - assert.Contains(t, loglines[0].Message, tt.expectedError) - }) - } -} - func TestUIRenderOutput(t *testing.T) { t.Parallel() diff --git a/js/jsmodules.go b/js/jsmodules.go index c068db47a972..6080ab2608b1 100644 --- a/js/jsmodules.go +++ b/js/jsmodules.go @@ -8,7 +8,6 @@ import ( "go.k6.io/k6/js/modules/k6/data" "go.k6.io/k6/js/modules/k6/encoding" "go.k6.io/k6/js/modules/k6/execution" - "go.k6.io/k6/js/modules/k6/experimental/browser" "go.k6.io/k6/js/modules/k6/experimental/tracing" "go.k6.io/k6/js/modules/k6/grpc" "go.k6.io/k6/js/modules/k6/html" @@ -16,6 +15,7 @@ import ( "go.k6.io/k6/js/modules/k6/metrics" "go.k6.io/k6/js/modules/k6/ws" + expBrowser "github.com/grafana/xk6-browser/browser" expGrpc "github.com/grafana/xk6-grpc/grpc" "github.com/grafana/xk6-redis/redis" "github.com/grafana/xk6-timers/timers" @@ -37,7 +37,7 @@ func getInternalJSModules() map[string]interface{} { "k6/experimental/grpc": expGrpc.New(), "k6/experimental/timers": timers.New(), "k6/experimental/tracing": tracing.New(), - "k6/experimental/browser": browser.New(), + "k6/experimental/browser": expBrowser.New(), "k6/net/grpc": grpc.New(), "k6/html": html.New(), "k6/http": http.New(), diff --git a/js/modules/k6/experimental/browser/rootmodule.go b/js/modules/k6/experimental/browser/rootmodule.go deleted file mode 100644 index f0ba4f872600..000000000000 --- a/js/modules/k6/experimental/browser/rootmodule.go +++ /dev/null @@ -1,58 +0,0 @@ -// Package browser contains a RootModule wrapper -// that wraps around the experimental browser -// RootModule. -package browser - -import ( - "errors" - "strconv" - - xk6browser "github.com/grafana/xk6-browser/browser" - "go.k6.io/k6/js/common" - "go.k6.io/k6/js/modules" -) - -type ( - // RootModule is a wrapper around the experimental - // browser RootModule. It will prevent browser test - // runs unless K6_BROWSER_ENABLED env var is set. - RootModule struct { - rm *xk6browser.RootModule - } -) - -// New creates an experimental browser RootModule -// and wraps it around this internal RootModule. -func New() *RootModule { - return &RootModule{ - rm: xk6browser.New(), - } -} - -// NewModuleInstance will check to see if -// K6_BROWSER_ENABLED is set before allowing -// test runs to continue. -func (r *RootModule) NewModuleInstance(vu modules.VU) modules.Instance { - env := vu.InitEnv() - - throwError := func() { - msg := "To run browser tests set env var K6_BROWSER_ENABLED=true" - if m, ok := env.LookupEnv("K6_BROWSER_ENABLED_MSG"); ok && m != "" { - msg = m - } - - common.Throw(vu.Runtime(), errors.New(msg)) - } - - vs, ok := env.LookupEnv("K6_BROWSER_ENABLED") - if !ok { - throwError() - } - - v, err := strconv.ParseBool(vs) - if err != nil || !v { - throwError() - } - - return r.rm.NewModuleInstance(vu) -}