Skip to content

Commit

Permalink
Merge pull request #3235 from grafana/upgrade/k6-latest-1-0-0
Browse files Browse the repository at this point in the history
Upgrade xk6-browser to v1.0.2
  • Loading branch information
codebien authored Aug 9, 2023
2 parents fcb19fb + 0837ee5 commit 9598ef5
Show file tree
Hide file tree
Showing 38 changed files with 1,074 additions and 724 deletions.
136 changes: 62 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 Expand Up @@ -2228,3 +2154,65 @@ func BenchmarkRunEvents(b *testing.B) {
}
}
}

func TestBrowserPermissions(t *testing.T) {
t.Parallel()

tests := []struct {
name string
options string
expectedExitCode exitcodes.ExitCode
expectedError string
}{
{
name: "browser option not set",
options: "",
expectedExitCode: 0,
expectedError: "GoError: browser not found in registry. make sure to set browser type option in scenario definition in order to use the browser module",
},
{
name: "browser option set",
options: `export const options = {
scenarios: {
browser: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
}`,
expectedExitCode: 0,
expectedError: "",
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
script := fmt.Sprintf(`
import { browser } from 'k6/experimental/browser';
%s
export default function() {
browser.isConnected();
};
`, tt.options)

ts := getSingleFileTestState(t, script, []string{}, tt.expectedExitCode)
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)
})
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/go-sourcemap/sourcemap v2.1.4-0.20211119122758-180fcef48034+incompatible
github.com/golang/protobuf v1.5.3
github.com/gorilla/websocket v1.5.0
github.com/grafana/xk6-browser v0.10.0
github.com/grafana/xk6-browser v1.0.2
github.com/grafana/xk6-grpc v0.1.3-0.20230717090346-fb49221e0ce1
github.com/grafana/xk6-output-prometheus-remote v0.2.3
github.com/grafana/xk6-redis v0.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grafana/xk6-browser v0.10.0 h1:Mnx0Ho+mlyFGlV7zW7zXkN0njRglh9JflLV+OzXSaRk=
github.com/grafana/xk6-browser v0.10.0/go.mod h1:ax6OHARpNEu9hSGYOAI4grAwiRapsNPi9TBQxDYurKw=
github.com/grafana/xk6-browser v1.0.2 h1:B9ll8xLH68hfCBy3sTzhmksCxwgJBIcqgPeX3mht6jM=
github.com/grafana/xk6-browser v1.0.2/go.mod h1:LV/ECGBCN3vRN/A4St+Ep9JUpbKJuRsj+6TBihQptGw=
github.com/grafana/xk6-grpc v0.1.3-0.20230717090346-fb49221e0ce1 h1:SdMihJN+fkH6cO/1NeAnVxSVOnJ3ZkZ1v7FJnrcqhog=
github.com/grafana/xk6-grpc v0.1.3-0.20230717090346-fb49221e0ce1/go.mod h1:iq6qHN64XgAEmDHKf0OXZ4mvoqF4Udr22fiCIXNpXA0=
github.com/grafana/xk6-output-prometheus-remote v0.2.3 h1:ta4wFrO85+29H0papAbeMCavHrBuHDZ4bdKC1Zv8zlo=
Expand Down
2 changes: 1 addition & 1 deletion 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"

"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 Down
58 changes: 0 additions & 58 deletions js/modules/k6/experimental/browser/rootmodule.go

This file was deleted.

2 changes: 1 addition & 1 deletion vendor/github.com/grafana/xk6-browser/api/browser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions vendor/github.com/grafana/xk6-browser/api/browser_type.go

This file was deleted.

8 changes: 7 additions & 1 deletion vendor/github.com/grafana/xk6-browser/api/frame.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9598ef5

Please sign in to comment.