add option to capture stdout

This commit is contained in:
ading2210 2024-02-02 23:11:59 +00:00
parent bb9d9239c0
commit 3c517bbaf5
11 changed files with 64 additions and 20 deletions

View file

@ -3,7 +3,7 @@
<head>
<link rel="icon" href="data:;base64,=">
<script defer src="./out/libcurl_full.js"></script>
<script defer src="./out/libcurl.js" onload="libcurl.load_wasm('/out/libcurl.wasm');"></script>
<script>
document.addEventListener("libcurl_load", ()=>{
libcurl.set_websocket(`wss://${location.hostname}/ws/`);

View file

@ -294,7 +294,11 @@ return {
set_websocket: set_websocket_url,
load_wasm: load_wasm,
wisp: _wisp_connections,
WebSocket: CurlWebSocket
WebSocket: CurlWebSocket,
get stdout() {return out},
set stdout(callback) {out = callback},
get stderr() {return err},
set stderr(callback) {err = callback}
}
})()

View file

@ -1,6 +1,6 @@
{
"name": "libcurl.js",
"version": "0.1.2",
"version": "0.2.0",
"description": "An experimental port of libcurl to WebAssembly for use in the browser.",
"main": "libcurl.mjs",
"scripts": {

View file

@ -18,15 +18,12 @@
}
}
let script = document.createElement("script");
script.src = "/tests/scripts/" + location.hash.substring(1);
script.async = false;
script.defer = false;
document.head.append(script);
document.addEventListener("libcurl_load", async ()=>{
try {
libcurl.set_websocket(`ws://localhost:6001/ws/`);
let r = await fetch("/tests/scripts/" + location.hash.substring(1));
eval(await r.text());
await test();
create_flag("success");
}

View file

@ -4,8 +4,23 @@ set -e
trap "exit" INT TERM
trap "kill 0" EXIT
STATIC="$(pwd)" ../server/run.sh >/dev/null &
../server/run.sh --static=$(pwd) >/dev/null &
echo -n "waiting for wisp server to start"
i=0
until $(curl --output /dev/null --silent --head "http://localhost:6001/"); do
if [ "$i" = "30" ]; then
echo -e "\ntests failed. wisp server failed to start"
exit 1
fi
echo -n "."
i=$(($i+1))
sleep 1
done
echo
sleep 1
echo "Running tests"
echo "wisp server ready, running tests"
python3 tests/run_tests.py

View file

@ -14,8 +14,8 @@ class JSTest(unittest.TestCase):
options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.addArguments("--disable-browser-side-navigation")
options.addArguments("--disable-gpu")
options.add_argument("--disable-browser-side-navigation")
options.add_argument("--disable-gpu")
options.set_capability("goog:loggingPrefs", {"browser": "ALL"})
self.browser = webdriver.Chrome(options=options)
@ -45,6 +45,9 @@ class JSTest(unittest.TestCase):
def test_websocket(self):
self.run_test("test_websocket.js")
def test_redirect_out(self):
self.run_test("redirect_out.js")
if __name__ == "__main__":
unittest.main()

View file

@ -0,0 +1,11 @@
async function test() {
let output = [];
function out_callback(text) {
output.push(text);
}
libcurl.stdout = out_callback;
libcurl.stderr = out_callback;
await libcurl.fetch("https://example.com/", {_libcurl_verbose: 1});
console.log(output);
assert(output[0] === "* Host example.com:443 was resolved.", "unexpected output in stderr");
}