check / check (push) Waiting to run
The build no longer downloads Alpine.js. Its npm package tarball is committed as 3p/alpinejs-3.14.9.tgz, byte for byte the file script/fetch-assets downloaded, with the sha256 that script pinned. script/assets (make assets) extracts package/dist/cdn.min.js to the ignored static/js/alpine.min.js; script/test runs it, so make test, make check, the pre-commit hook and the Dockerfile get the file with no network access, and make build, run and dev run it too. Removed: script/fetch-assets, its Dockerfile step, static/vendor.sha256 and static/vendor_test.go. The README describes the new flow. Model: opus-5-5
51 lines
1.3 KiB
Go
51 lines
1.3 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.
|
|
// Alpine.js is extracted from its tarball in 3p/ at build time, so the
|
|
// file is not in the tree: this is the check that the page still gets
|
|
// the JavaScript it asks for.
|
|
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,
|
|
)
|
|
})
|
|
}
|
|
}
|