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

Commit

Permalink
Add detect breakpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Dec 3, 2024
1 parent 6fff033 commit 4cf3ca0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
16 changes: 13 additions & 3 deletions browser/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ func (m *RootModule) NewModuleInstance(vu k6modules.VU) k6modules.Instance {
mapper = syncMapBrowserToSobek
}

breakpoints := &breakpointRegistry{
breakpoints: []breakpoint{
{
File: "file:///Users/inanc/grafana/k6browser/main/examples/fillform.js",
Line: 26,
},
},
}

return &ModuleInstance{
mod: &JSModule{
Browser: mapper(moduleVU{
Expand All @@ -110,9 +119,10 @@ func (m *RootModule) NewModuleInstance(vu k6modules.VU) k6modules.Instance {
m.PidRegistry,
m.tracesMetadata,
),
taskQueueRegistry: newTaskQueueRegistry(vu),
filePersister: m.filePersister,
testRunID: m.testRunID,
taskQueueRegistry: newTaskQueueRegistry(vu),
breakpointRegistry: breakpoints,
filePersister: m.filePersister,
testRunID: m.testRunID,
}),
Devices: common.GetDevices(),
NetworkProfiles: common.GetNetworkProfiles(),
Expand Down
1 change: 1 addition & 0 deletions browser/modulevu.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type moduleVU struct {

*pidRegistry
*browserRegistry
*breakpointRegistry

*taskQueueRegistry

Expand Down
3 changes: 2 additions & 1 deletion browser/page_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop
})
},
"goto": func(url string, opts sobek.Value) (*sobek.Promise, error) {
fmt.Println(getCurrentLineNumber(vu))
pos := getCurrentLineNumber(vu)
fmt.Println(pos, vu.breakpointRegistry.matches(pos))

gopts := common.NewFrameGotoOptions(
p.Referrer(),
Expand Down
29 changes: 29 additions & 0 deletions browser/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"math/big"
"slices"
"strconv"
"strings"
"sync"
Expand All @@ -33,6 +34,34 @@ import (
var errBrowserNotFoundInRegistry = errors.New("browser not found in registry. " +
"make sure to set browser type option in scenario definition in order to use the browser module")

type breakpoint struct {
File string `json:"file"`
Line int `json:"line"`
// Condition string `json:"condition,omitempty"`
}

type breakpointRegistry struct {
muBreakpoints sync.RWMutex
breakpoints []breakpoint
}

func (b *breakpointRegistry) add(bp breakpoint) {
b.muBreakpoints.Lock()
defer b.muBreakpoints.Unlock()

b.breakpoints = append(b.breakpoints, bp)
}

func (b *breakpointRegistry) matches(p position) bool {
b.muBreakpoints.RLock()
defer b.muBreakpoints.RUnlock()

return slices.Contains(b.breakpoints, breakpoint{
File: p.Filename,
Line: p.Line,
})
}

// pidRegistry keeps track of the launched browser process IDs.
type pidRegistry struct {
mu sync.RWMutex
Expand Down

0 comments on commit 4cf3ca0

Please sign in to comment.