Skip to content

Commit

Permalink
switching tests back to one web server, many pages (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
zangster300 authored Feb 5, 2025
1 parent d3b50bc commit bc21b05
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion site/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ type SiteIndexDoc struct {
}

func indexSiteContent(ctx context.Context, index bleve.Index) error {
markdownDir := "site/static/md"
markdownDir := "../../site/static/md"
extractor := plaintext.NewHtmlExtractor()

return filepath.WalkDir(markdownDir, func(path string, d fs.DirEntry, err error) error {
Expand Down
30 changes: 21 additions & 9 deletions site/smoketests/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,43 @@ import (
"fmt"
"sync"
"testing"
"time"

"github.com/delaneyj/toolbelt"
"github.com/go-rod/rod"
"github.com/starfederation/datastar/site"
"github.com/stretchr/testify/require"
)

type runnerFn func(name string, fn func(t *testing.T, page *rod.Page))
var (
baseURL string
browser *rod.Browser
)

func setupPageTest(t *testing.T, subURL string, gen func(runner runnerFn)) {
t.Parallel()
browser := rod.New().MustConnect()
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
func TestMain(m *testing.M) {
ctx := context.Background()

port, err := toolbelt.FreePort()
require.NoError(t, err)
if err != nil {
panic(err)
}

baseURL := fmt.Sprintf("http://localhost:%d", port)
baseURL = fmt.Sprintf("http://localhost:%d", port)

readyCh := make(chan struct{})
go site.RunBlocking(port, readyCh)(ctx)
<-readyCh

browser = rod.New().MustConnect()

m.Run()

ctx.Done()
}

type runnerFn func(name string, fn func(t *testing.T, page *rod.Page))

func setupPageTest(t *testing.T, subURL string, gen func(runner runnerFn)) {
t.Parallel()
page := browser.MustIncognito().MustPage(fmt.Sprintf("%s/%s", baseURL, subURL))
require.NotNil(t, page)
t.Cleanup(page.MustClose)
Expand Down

0 comments on commit bc21b05

Please sign in to comment.