Skip to content

Commit

Permalink
Refactor cookies to work with ErrFatal
Browse files Browse the repository at this point in the history
This is to show that the whole test run will also stop when we try
to use an unimplemented unpromisified API.
  • Loading branch information
ankur22 committed Mar 6, 2023
1 parent bbe8fb0 commit 9453a1a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion api/browser_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type BrowserContext interface {
ClearCookies()
ClearPermissions()
Close()
Cookies() []any // TODO: make it []Cookie later on
Cookies() ([]any, error) // TODO: make it []Cookie later on
ExposeBinding(name string, callback goja.Callable, opts goja.Value)
ExposeFunction(name string, callback goja.Callable)
GrantPermissions(permissions []string, opts goja.Value)
Expand Down
19 changes: 12 additions & 7 deletions browser/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,13 +578,18 @@ func mapWorker(vu moduleVU, w api.Worker) mapping {
func mapBrowserContext(vu moduleVU, bc api.BrowserContext) mapping {
rt := vu.Runtime()
return mapping{
"addCookies": bc.AddCookies,
"addInitScript": bc.AddInitScript,
"browser": bc.Browser,
"clearCookies": bc.ClearCookies,
"clearPermissions": bc.ClearPermissions,
"close": bc.Close,
"cookies": bc.Cookies,
"addCookies": bc.AddCookies,
"addInitScript": bc.AddInitScript,
"browser": bc.Browser,
"clearCookies": bc.ClearCookies,
"clearPermissions": bc.ClearPermissions,
"close": bc.Close,
"cookies": func() ([]any, error) {
cc, err := bc.Cookies()
ctx := vu.Context()
panicIfFatalError(ctx, err)
return cc, err //nolint:wrapcheck
},
"exposeBinding": bc.ExposeBinding,
"exposeFunction": bc.ExposeFunction,
"grantPermissions": bc.GrantPermissions,
Expand Down
5 changes: 2 additions & 3 deletions common/browser_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ func (b *BrowserContext) Close() {
}

// Cookies is not implemented.
func (b *BrowserContext) Cookies() []any {
k6ext.Panic(b.ctx, "BrowserContext.cookies() has not been implemented yet")
return nil
func (b *BrowserContext) Cookies() ([]any, error) {
return nil, fmt.Errorf("BrowserContext.cookies() has not been implemented yet: %w", k6error.ErrFatal)
}

// ExposeBinding is not implemented.
Expand Down

0 comments on commit 9453a1a

Please sign in to comment.