Skip to content

Commit

Permalink
adds context.WithTimeout to site smoketests
Browse files Browse the repository at this point in the history
removes got lib refs
  • Loading branch information
zangster300 committed Dec 9, 2024
1 parent 4c20476 commit 8ba2529
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ require (
github.com/valyala/bytebufferpool v1.0.0
github.com/valyala/quicktemplate v1.8.0
github.com/wcharczuk/go-chart/v2 v2.1.2
github.com/ysmood/got v0.40.0
github.com/ysmood/gson v0.7.3
github.com/zeebo/xxh3 v1.0.2
)
Expand Down Expand Up @@ -71,7 +70,7 @@ require (
github.com/segmentio/asm v1.2.0 // indirect
github.com/ysmood/fetchup v0.2.4 // indirect
github.com/ysmood/goob v0.4.0 // indirect
github.com/ysmood/gop v0.2.0 // indirect
github.com/ysmood/got v0.40.0 // indirect
github.com/ysmood/leakless v0.9.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
Expand Down
25 changes: 13 additions & 12 deletions site/smoketests/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import (
"context"
"fmt"
"testing"
"time"

"github.com/delaneyj/toolbelt"
"github.com/go-rod/rod"
"github.com/starfederation/datastar/site"
"github.com/ysmood/got"
)

var (
baseURL string
)

// test context
type G struct {
got.G
type UnitTest struct {
t *testing.T
ctx context.Context
browser *rod.Browser
}

Expand All @@ -40,18 +40,19 @@ func TestMain(m *testing.M) {
ctx.Done()
}

var setup = func() func(t *testing.T) G {

var setup = func() func(t *testing.T) UnitTest {
browser := rod.New().MustConnect()
return func(t *testing.T) UnitTest {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

return func(t *testing.T) G {
t.Parallel() // run each test concurrently
return G{got.New(t), browser}
return UnitTest{t, ctx, browser}
}
}()

func (g G) page(url string) *rod.Page {
page := g.browser.MustIncognito().MustPage(fmt.Sprintf("%s/%s", baseURL, url))
g.Cleanup(page.MustClose)
func (u UnitTest) page(url string) *rod.Page {
page := u.browser.MustIncognito().MustPage(fmt.Sprintf("%s/%s", baseURL, url))
u.t.Cleanup(page.MustClose)
return page
}

0 comments on commit 8ba2529

Please sign in to comment.