Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
71 lines
2.2 KiB
Go
71 lines
2.2 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestPeriodicalChromium(t *testing.T) {
|
|
if os.Getenv("PAGESWIKI_BROWSER_TEST") != "1" {
|
|
t.Skip("opt-in Chromium")
|
|
}
|
|
for _, width := range []string{"1440", "390"} {
|
|
t.Run(width, func(t *testing.T) {
|
|
s, token, domain, _ := periodicalFixture(t)
|
|
page, err := s.store.CreatePageAtPathInDomain(domain, "/journal/browser")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err = s.store.SaveRevision(page, "<p>Diary/blog fixture Page</p>", ""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
script, err := os.ReadFile("internal/server/testdata/periodicals-browser.js")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
r.Host = "localhost"
|
|
r.Header.Set("Authorization", "Bearer "+token)
|
|
if r.Header.Get("Origin") != "" {
|
|
r.Header.Set("Origin", "http://localhost")
|
|
}
|
|
if r.Method == "GET" && r.URL.Path == "/-/sys/config" {
|
|
rec := httptest.NewRecorder()
|
|
s.withAuthorization(s.mux).ServeHTTP(rec, r)
|
|
for key, values := range rec.Header() {
|
|
w.Header()[key] = values
|
|
}
|
|
w.WriteHeader(rec.Code)
|
|
_, _ = w.Write([]byte(strings.Replace(rec.Body.String(), "</body>", browserFixtureScript(rec.Header(), script)+"</body>", 1)))
|
|
return
|
|
}
|
|
s.withAuthorization(s.mux).ServeHTTP(w, r)
|
|
}))
|
|
defer server.Close()
|
|
ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
|
|
defer cancel()
|
|
screenshot := ""
|
|
if dir := os.Getenv("PAGESWIKI_PERIODICAL_SCREENSHOT_DIR"); dir != "" {
|
|
if err = os.MkdirAll(dir, 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
screenshot = filepath.Join(dir, "periodicals-"+width+".png")
|
|
}
|
|
out, err := exec.CommandContext(ctx, "node", "internal/server/testdata/vim-browser-smoke.mjs", server.URL+"/-/sys/config?panel=diary", t.TempDir(), screenshot, width).CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("browser %v %s", err, out)
|
|
}
|
|
if actual, err := s.store.ResolvePathInDomain(domain, "/journal/browser"); err != nil || actual != page {
|
|
t.Fatal("unregister removed Page", err)
|
|
}
|
|
})
|
|
}
|
|
}
|