check / check (push) Waiting to run
static/js/alpine.min.js is now committed: package/dist/cdn.min.js from the @alpinejs/csp 3.14.9 npm package, byte for byte, taken once from the package file that was in 3p/. The build no longer unpacks it, so script/assets, the assets make target, its Dockerfile steps and the ignore entries for the file are gone, and so is the package file. Prettier and ESLint both ignore the file, so it stays as published. Comments and the README now describe the committed file. Model: opus-5-5
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package server_test
|
|
|
|
import (
|
|
"net/http"
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"sneak.berlin/go/webhooker/templates"
|
|
)
|
|
|
|
// TestBaseTemplateScriptsAreServed walks every /s/ script the base
|
|
// template loads on each page and fetches it through the real router.
|
|
func TestBaseTemplateScriptsAreServed(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// scriptSrc matches the src of every <script> tag pointing at the
|
|
// /s/ static mount.
|
|
scriptSrc := regexp.MustCompile(`<script[^>]+src="(/s/[^"]+)"`)
|
|
|
|
base, err := templates.Templates.ReadFile("base.html")
|
|
require.NoError(t, err)
|
|
|
|
matches := scriptSrc.FindAllStringSubmatch(string(base), -1)
|
|
require.NotEmpty(t, matches, "base.html should load scripts from /s/")
|
|
|
|
env := newTestEnv(t)
|
|
|
|
for _, m := range matches {
|
|
src := m[1]
|
|
t.Run(src, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
w := env.get(src, nil)
|
|
|
|
require.Equalf(
|
|
t, http.StatusOK, w.Code,
|
|
"base.html loads %s but the server does not serve it", src,
|
|
)
|
|
assert.NotEmptyf(
|
|
t, w.Body.Bytes(), "%s is served but empty", src,
|
|
)
|
|
})
|
|
}
|
|
}
|