Skip to content

Commit

Permalink
Remove promise returning methods in common pkg
Browse files Browse the repository at this point in the history
This is a continuation of the efforts set in #683.
Handling the Async API handling in the mapping
layer.
  • Loading branch information
inancgumus committed Feb 2, 2023
1 parent c347eae commit 77e12d4
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 102 deletions.
18 changes: 9 additions & 9 deletions api/browser_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import (

// BrowserContext is the public interface of a CDP browser context.
type BrowserContext interface {
AddCookies(cookies goja.Value) *goja.Promise
AddCookies(cookies goja.Value)
AddInitScript(script goja.Value, arg goja.Value)
Browser() Browser
ClearCookies()
ClearPermissions()
Close()
Cookies() *goja.Promise
ExposeBinding(name string, callback goja.Callable, opts goja.Value) *goja.Promise
ExposeFunction(name string, callback goja.Callable) *goja.Promise
Cookies()
ExposeBinding(name string, callback goja.Callable, opts goja.Value)
ExposeFunction(name string, callback goja.Callable)
GrantPermissions(permissions []string, opts goja.Value)
NewCDPSession() *goja.Promise
NewCDPSession()
NewPage() Page
Pages() []Page
Route(url goja.Value, handler goja.Callable) *goja.Promise
Route(url goja.Value, handler goja.Callable)
SetDefaultNavigationTimeout(timeout int64)
SetDefaultTimeout(timeout int64)
SetExtraHTTPHeaders(headers map[string]string) *goja.Promise
SetExtraHTTPHeaders(headers map[string]string)
SetGeolocation(geolocation goja.Value)
// SetHTTPCredentials sets username/password credentials to use for HTTP authentication.
//
Expand All @@ -32,7 +32,7 @@ type BrowserContext interface {
// - https://github.com/microsoft/playwright/pull/2763
SetHTTPCredentials(httpCredentials goja.Value)
SetOffline(offline bool)
StorageState(opts goja.Value) *goja.Promise
Unroute(url goja.Value, handler goja.Callable) *goja.Promise
StorageState(opts goja.Value)
Unroute(url goja.Value, handler goja.Callable)
WaitForEvent(event string, optsOrPredicate goja.Value) any
}
4 changes: 2 additions & 2 deletions api/browser_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

// BrowserType is the public interface of a CDP browser client.
type BrowserType interface {
Connect(opts goja.Value) *goja.Promise
Connect(opts goja.Value)
ExecutablePath() string
Launch(opts goja.Value) Browser
LaunchPersistentContext(userDataDir string, opts goja.Value) *goja.Promise
LaunchPersistentContext(userDataDir string, opts goja.Value)
Name() string
}
2 changes: 1 addition & 1 deletion api/element_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type ElementHandle interface {
ScrollIntoViewIfNeeded(opts goja.Value)
SelectOption(values goja.Value, opts goja.Value) []string
SelectText(opts goja.Value)
SetInputFiles(files goja.Value, opts goja.Value) *goja.Promise
SetInputFiles(files goja.Value, opts goja.Value)
Tap(opts goja.Value)
TextContent() string
Type(text string, opts goja.Value)
Expand Down
6 changes: 3 additions & 3 deletions api/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import "github.com/dop251/goja"

// Frame is the interface of a CDP target frame.
type Frame interface {
AddScriptTag(opts goja.Value) *goja.Promise
AddStyleTag(opts goja.Value) *goja.Promise
AddScriptTag(opts goja.Value)
AddStyleTag(opts goja.Value)
Check(selector string, opts goja.Value)
ChildFrames() []Frame
Click(selector string, opts goja.Value) error
Expand Down Expand Up @@ -42,7 +42,7 @@ type Frame interface {
Press(selector string, key string, opts goja.Value)
SelectOption(selector string, values goja.Value, opts goja.Value) []string
SetContent(html string, opts goja.Value)
SetInputFiles(selector string, files goja.Value, opts goja.Value) *goja.Promise
SetInputFiles(selector string, files goja.Value, opts goja.Value)
Tap(selector string, opts goja.Value)
TextContent(selector string, opts goja.Value) string
Title() string
Expand Down
36 changes: 18 additions & 18 deletions api/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import "github.com/dop251/goja"

// Page is the interface of a single browser tab.
type Page interface {
AddInitScript(script goja.Value, arg goja.Value) *goja.Promise
AddScriptTag(opts goja.Value) *goja.Promise
AddStyleTag(opts goja.Value) *goja.Promise
AddInitScript(script goja.Value, arg goja.Value)
AddScriptTag(opts goja.Value)
AddStyleTag(opts goja.Value)
BringToFront()
Check(selector string, opts goja.Value)
Click(selector string, opts goja.Value) error
Expand All @@ -15,20 +15,20 @@ type Page interface {
Context() BrowserContext
Dblclick(selector string, opts goja.Value)
DispatchEvent(selector string, typ string, eventInit goja.Value, opts goja.Value)
DragAndDrop(source string, target string, opts goja.Value) *goja.Promise
DragAndDrop(source string, target string, opts goja.Value)
EmulateMedia(opts goja.Value)
EmulateVisionDeficiency(typ string)
Evaluate(pageFunc goja.Value, arg ...goja.Value) any
EvaluateHandle(pageFunc goja.Value, arg ...goja.Value) JSHandle
ExposeBinding(name string, callback goja.Callable, opts goja.Value) *goja.Promise
ExposeFunction(name string, callback goja.Callable) *goja.Promise
ExposeBinding(name string, callback goja.Callable, opts goja.Value)
ExposeFunction(name string, callback goja.Callable)
Fill(selector string, value string, opts goja.Value)
Focus(selector string, opts goja.Value)
Frame(frameSelector goja.Value) *goja.Promise
Frame(frameSelector goja.Value)
Frames() []Frame
GetAttribute(selector string, name string, opts goja.Value) goja.Value
GoBack(opts goja.Value) *goja.Promise
GoForward(opts goja.Value) *goja.Promise
GoBack(opts goja.Value)
GoForward(opts goja.Value)
Goto(url string, opts goja.Value) (Response, error)
Hover(selector string, opts goja.Value)
InnerHTML(selector string, opts goja.Value) string
Expand All @@ -45,36 +45,36 @@ type Page interface {
Locator(selector string, opts goja.Value) Locator
MainFrame() Frame
Opener() Page
Pause() *goja.Promise
Pdf(opts goja.Value) *goja.Promise
Pause()
Pdf(opts goja.Value)
Press(selector string, key string, opts goja.Value)
Query(selector string) ElementHandle
QueryAll(selector string) []ElementHandle
Reload(opts goja.Value) Response
Route(url goja.Value, handler goja.Callable) *goja.Promise
Route(url goja.Value, handler goja.Callable)
Screenshot(opts goja.Value) goja.ArrayBuffer
SelectOption(selector string, values goja.Value, opts goja.Value) []string
SetContent(html string, opts goja.Value)
SetDefaultNavigationTimeout(timeout int64)
SetDefaultTimeout(timeout int64)
SetExtraHTTPHeaders(headers map[string]string)
SetInputFiles(selector string, files goja.Value, opts goja.Value) *goja.Promise
SetInputFiles(selector string, files goja.Value, opts goja.Value)
SetViewportSize(viewportSize goja.Value)
Tap(selector string, opts goja.Value)
TextContent(selector string, opts goja.Value) string
Title() string
Type(selector string, text string, opts goja.Value)
Uncheck(selector string, opts goja.Value)
Unroute(url goja.Value, handler goja.Callable) *goja.Promise
Unroute(url goja.Value, handler goja.Callable)
URL() string
Video() *goja.Promise
Video()
ViewportSize() map[string]float64
WaitForEvent(event string, optsOrPredicate goja.Value) *goja.Promise
WaitForEvent(event string, optsOrPredicate goja.Value)
WaitForFunction(fn, opts goja.Value, args ...goja.Value) (any, error)
WaitForLoadState(state string, opts goja.Value)
WaitForNavigation(opts goja.Value) (Response, error)
WaitForRequest(urlOrPredicate, opts goja.Value) *goja.Promise
WaitForResponse(urlOrPredicate, opts goja.Value) *goja.Promise
WaitForRequest(urlOrPredicate, opts goja.Value)
WaitForResponse(urlOrPredicate, opts goja.Value)
WaitForSelector(selector string, opts goja.Value) ElementHandle
WaitForTimeout(timeout int64)
Workers() []Worker
Expand Down
2 changes: 1 addition & 1 deletion api/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "github.com/dop251/goja"
type Response interface {
AllHeaders() map[string]string
Body() goja.ArrayBuffer
Finished() *goja.Promise
Finished()
Frame() Frame
HeaderValue(string) goja.Value
HeaderValues(string) []string
Expand Down
6 changes: 2 additions & 4 deletions chromium/browser_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ func NewBrowserType(vu k6modules.VU) api.BrowserType {
}

// Connect attaches k6 browser to an existing browser instance.
func (b *BrowserType) Connect(opts goja.Value) *goja.Promise {
func (b *BrowserType) Connect(opts goja.Value) {
rt := b.vu.Runtime()
k6common.Throw(rt, errors.New("BrowserType.connect() has not been implemented yet"))
return nil
}

// ExecutablePath returns the path where the extension expects to find the browser executable.
Expand Down Expand Up @@ -205,10 +204,9 @@ func (b *BrowserType) launch(ctx context.Context, opts *common.LaunchOptions) (*
}

// LaunchPersistentContext launches the browser with persistent storage.
func (b *BrowserType) LaunchPersistentContext(userDataDir string, opts goja.Value) *goja.Promise {
func (b *BrowserType) LaunchPersistentContext(userDataDir string, opts goja.Value) {
rt := b.vu.Runtime()
k6common.Throw(rt, errors.New("BrowserType.LaunchPersistentContext(userDataDir, opts) has not been implemented yet"))
return nil
}

// Name returns the name of this browser type.
Expand Down
27 changes: 9 additions & 18 deletions common/browser_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ func NewBrowserContext(
}

// AddCookies is not implemented.
func (b *BrowserContext) AddCookies(cookies goja.Value) *goja.Promise {
func (b *BrowserContext) AddCookies(cookies goja.Value) {
k6ext.Panic(b.ctx, "BrowserContext.addCookies(cookies) has not been implemented yet")
return nil
}

// AddInitScript adds a script that will be initialized on all new pages.
Expand Down Expand Up @@ -143,21 +142,18 @@ func (b *BrowserContext) Close() {
}

// Cookies is not implemented.
func (b *BrowserContext) Cookies() *goja.Promise {
func (b *BrowserContext) Cookies() {
k6ext.Panic(b.ctx, "BrowserContext.cookies() has not been implemented yet")
return nil
}

// ExposeBinding is not implemented.
func (b *BrowserContext) ExposeBinding(name string, callback goja.Callable, opts goja.Value) *goja.Promise {
func (b *BrowserContext) ExposeBinding(name string, callback goja.Callable, opts goja.Value) {
k6ext.Panic(b.ctx, "BrowserContext.exposeBinding(name, callback, opts) has not been implemented yet")
return nil
}

// ExposeFunction is not implemented.
func (b *BrowserContext) ExposeFunction(name string, callback goja.Callable) *goja.Promise {
func (b *BrowserContext) ExposeFunction(name string, callback goja.Callable) {
k6ext.Panic(b.ctx, "BrowserContext.exposeFunction(name, callback) has not been implemented yet")
return nil
}

// GrantPermissions enables the specified permissions, all others will be disabled.
Expand Down Expand Up @@ -206,9 +202,8 @@ func (b *BrowserContext) GrantPermissions(permissions []string, opts goja.Value)
}

// NewCDPSession returns a new CDP session attached to this target.
func (b *BrowserContext) NewCDPSession() *goja.Promise {
func (b *BrowserContext) NewCDPSession() {
k6ext.Panic(b.ctx, "BrowserContext.newCDPSession() has not been implemented yet")
return nil
}

// NewPage creates a new page inside this browser context.
Expand Down Expand Up @@ -245,9 +240,8 @@ func (b *BrowserContext) Pages() []api.Page {
}

// Route is not implemented.
func (b *BrowserContext) Route(url goja.Value, handler goja.Callable) *goja.Promise {
func (b *BrowserContext) Route(url goja.Value, handler goja.Callable) {
k6ext.Panic(b.ctx, "BrowserContext.route(url, handler) has not been implemented yet")
return nil
}

// SetDefaultNavigationTimeout sets the default navigation timeout in milliseconds.
Expand All @@ -265,9 +259,8 @@ func (b *BrowserContext) SetDefaultTimeout(timeout int64) {
}

// SetExtraHTTPHeaders is not implemented.
func (b *BrowserContext) SetExtraHTTPHeaders(headers map[string]string) *goja.Promise {
func (b *BrowserContext) SetExtraHTTPHeaders(headers map[string]string) {
k6ext.Panic(b.ctx, "BrowserContext.setExtraHTTPHeaders(headers) has not been implemented yet")
return nil
}

// SetGeolocation overrides the geo location of the user.
Expand Down Expand Up @@ -320,15 +313,13 @@ func (b *BrowserContext) SetOffline(offline bool) {
}

// StorageState is not implemented.
func (b *BrowserContext) StorageState(opts goja.Value) *goja.Promise {
func (b *BrowserContext) StorageState(opts goja.Value) {
k6ext.Panic(b.ctx, "BrowserContext.storageState(opts) has not been implemented yet")
return nil
}

// Unroute is not implemented.
func (b *BrowserContext) Unroute(url goja.Value, handler goja.Callable) *goja.Promise {
func (b *BrowserContext) Unroute(url goja.Value, handler goja.Callable) {
k6ext.Panic(b.ctx, "BrowserContext.unroute(url, handler) has not been implemented yet")
return nil
}

// WaitForEvent waits for event.
Expand Down
3 changes: 1 addition & 2 deletions common/element_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -1233,10 +1233,9 @@ func (h *ElementHandle) SelectText(opts goja.Value) {
}

// SetInputFiles is not implemented.
func (h *ElementHandle) SetInputFiles(files goja.Value, opts goja.Value) *goja.Promise {
func (h *ElementHandle) SetInputFiles(files goja.Value, opts goja.Value) {
// TODO: implement
k6ext.Panic(h.ctx, "ElementHandle.setInputFiles() has not been implemented yet")
return nil
}

func (h *ElementHandle) Tap(opts goja.Value) {
Expand Down
9 changes: 3 additions & 6 deletions common/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,17 +486,15 @@ func (f *Frame) waitForSelector(selector string, opts *FrameWaitForSelectorOptio
}

// AddScriptTag is not implemented.
func (f *Frame) AddScriptTag(opts goja.Value) *goja.Promise {
func (f *Frame) AddScriptTag(opts goja.Value) {
k6ext.Panic(f.ctx, "Frame.AddScriptTag() has not been implemented yet")
applySlowMo(f.ctx)
return nil
}

// AddStyleTag is not implemented.
func (f *Frame) AddStyleTag(opts goja.Value) *goja.Promise {
func (f *Frame) AddStyleTag(opts goja.Value) {
k6ext.Panic(f.ctx, "Frame.AddStyleTag() has not been implemented yet")
applySlowMo(f.ctx)
return nil
}

// ChildFrames returns a list of child frames.
Expand Down Expand Up @@ -1460,9 +1458,8 @@ func (f *Frame) SetContent(html string, opts goja.Value) {
}

// SetInputFiles is not implemented.
func (f *Frame) SetInputFiles(selector string, files goja.Value, opts goja.Value) *goja.Promise {
func (f *Frame) SetInputFiles(selector string, files goja.Value, opts goja.Value) {
k6ext.Panic(f.ctx, "Frame.setInputFiles(selector, files, opts) has not been implemented yet")
return nil
// TODO: needs slowMo
}

Expand Down
Loading

0 comments on commit 77e12d4

Please sign in to comment.