LibWeb/Tests: Added example test for how to use http-test-server.py

The example shows how to write a test that depends on custom HTTP
headers in the response. This will be useful for testing browser JS
that depends on how Ladybird processes response headers, eg CORS
headers like Access-Control-Allow-Origin and others.
This commit is contained in:
Cory Virok 2024-10-14 22:25:24 -07:00 committed by Andrew Kaster
commit 39f844f77c
Notes: github-actions[bot] 2024-11-09 20:30:53 +00:00
4 changed files with 59 additions and 0 deletions

View file

@ -0,0 +1,29 @@
<script src="./include.js"></script>
<script>
asyncTest(async (done) => {
try {
const httpServer = httpTestServer();
const url = await httpServer.createEcho("GET", "/test-http-test-server", {
status: 200,
headers: {
"Access-Control-Allow-Origin": "*", // necessary when running test using file://...
"Access-Control-Expose-Headers": "X-Custom-Header", // tells the browser which headers to expose to JS
"Content-Type": "text/plain",
"X-Custom-Header": "well hello friends",
},
body: "hello world!",
});
const result = await fetch(url);
const headers = result.headers;
if (headers.get("X-Custom-Header") === "well hello friends") {
println("PASS");
} else {
println("FAIL");
}
} catch (err) {
println("FAIL - " + err);
}
done();
});
</script>