package main import ( "net/http" "net/http/httptest" "strings" "testing" "wxch.org/wxch/web" ) // The chess page is plain static files on the control host: no login, and the engine's WebAssembly file must be sent as // such or browsers refuse to start it the fast way. func TestChessPageAndEngineAreServed(t *testing.T) { h := pageHandler(http.FileServer(http.FS(web.FS()))) get := func(p string) *httptest.ResponseRecorder { w := httptest.NewRecorder() h.ServeHTTP(w, httptest.NewRequest("GET", p, nil)) return w } if w := get("/chess/"); w.Code != 200 || !strings.Contains(w.Body.String(), "Stockfish") || !strings.HasPrefix(w.Header().Get("Content-Type"), "text/html") { t.Errorf("/chess/: %d %s", w.Code, w.Header().Get("Content-Type")) } if w := get("/chess/stockfish-19-lite-single.wasm"); w.Code != 200 || w.Header().Get("Content-Type") != "application/wasm" || w.Body.Len() < 1_000_000 { t.Errorf("wasm: %d %q %d bytes", w.Code, w.Header().Get("Content-Type"), w.Body.Len()) } for _, f := range []string{"stockfish-19-lite-single.js", "game.js", "chess.js"} { if w := get("/chess/" + f); w.Code != 200 || !strings.Contains(w.Header().Get("Content-Type"), "javascript") { t.Errorf("%s: %d %q", f, w.Code, w.Header().Get("Content-Type")) } } if w := get("/chess/COPYING-stockfish.txt"); w.Code != 200 || !strings.Contains(w.Body.String(), "GNU GENERAL PUBLIC LICENSE") { t.Errorf("licence: %d", w.Code) } }