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

Playwright compatibility: Improve valueFromRemoteObject null detection #1369

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions common/remote_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/grafana/xk6-browser/log"

"github.com/chromedp/cdproto/runtime"
cdpruntime "github.com/chromedp/cdproto/runtime"
)

Expand Down Expand Up @@ -105,8 +106,8 @@ func parseRemoteObjectValue(
if val == "Object" {
return val, nil
}
if st == "null" {
return "null", nil
if st == runtime.SubtypeNull {
return nil, nil //nolint:nilnil
}
case cdpruntime.TypeUndefined:
return "undefined", nil
Expand Down
16 changes: 15 additions & 1 deletion common/remote_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ func TestValueFromRemoteObject(t *testing.T) {
require.Nil(t, arg)
})

t.Run("null", func(t *testing.T) {
t.Parallel()

vu := k6test.NewVU(t)
remoteObject := &runtime.RemoteObject{
Type: cdpruntime.TypeObject,
Subtype: cdpruntime.SubtypeNull,
}

arg, err := valueFromRemoteObject(vu.Context(), remoteObject)
require.NoError(t, err)
require.Nil(t, arg)
})

t.Run("primitive types", func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -236,7 +250,7 @@ func TestParseRemoteObject(t *testing.T) {
name: "null",
subtype: "null",
value: nil,
expected: "null",
expected: nil,
},
}

Expand Down
2 changes: 1 addition & 1 deletion tests/remote_obj_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TestEvalRemoteObjectParse(t *testing.T) {
name: "empty", eval: "", want: "",
},
{
name: "null", eval: "null", want: "null",
name: "null", eval: "null", want: nil,
},
{
name: "undefined", eval: "undefined", want: nil,
Expand Down
Loading