mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-02 16:33:13 +00:00
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:
parent
3fdb2b081f
commit
39f844f77c
Notes:
github-actions[bot]
2024-11-09 20:30:53 +00:00
Author: https://github.com/coryvirok
Commit: 39f844f77c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1801
Reviewed-by: https://github.com/rmg-x
4 changed files with 59 additions and 0 deletions
|
@ -98,3 +98,31 @@ function promiseTest(f) {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
class HTTPTestServer {
|
||||
constructor(baseURL) {
|
||||
this.baseURL = baseURL;
|
||||
}
|
||||
async createEcho(method, path, options) {
|
||||
const result = await fetch(`${this.baseURL}/create`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ ...options, method, path }),
|
||||
});
|
||||
if (!result.ok) {
|
||||
throw new Error("Error creating echo: " + result.statusText);
|
||||
}
|
||||
return `${this.baseURL}${path}`;
|
||||
}
|
||||
getStaticURL(path) {
|
||||
return `${this.baseURL}/static/${path}`;
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Get the port from internals
|
||||
const __httpTestServer = new HTTPTestServer("http://localhost:8123");
|
||||
function httpTestServer() {
|
||||
return __httpTestServer;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue