Skip to content

Commit

Permalink
Remove K6_BROWSER_ENABLED flag requirement
Browse files Browse the repository at this point in the history
Currently (as of grafana/[email protected]) the browser extension
requires the definition of the browser type parameter inside the options
element for every scenario that wants to use the browser module.
Therefore the K6_BROWSER_ENABLED flag has become redundant, as both
parameters have to be set, being the scenario one more restrictive.

Because we no longer have to parse the environment variable, the module
wrapper implementation can be removed completely and use the xk6-browser
root module constructor directly instead.
  • Loading branch information
ka3de committed Jul 28, 2023
1 parent 28d3e24 commit 6184d29
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 134 deletions.
74 changes: 0 additions & 74 deletions cmd/tests/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions js/jsmodules.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ 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"
"go.k6.io/k6/js/modules/k6/http"
"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"
Expand All @@ -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(),
Expand Down
58 changes: 0 additions & 58 deletions js/modules/k6/experimental/browser/rootmodule.go

This file was deleted.

0 comments on commit 6184d29

Please sign in to comment.