mirror of
https://github.com/ading2210/libcurl.js.git
synced 2025-05-12 22:10:01 -04:00
add unit tests
This commit is contained in:
parent
b071019761
commit
2d98b82ee3
9 changed files with 147 additions and 2 deletions
7
client/tests/scripts/fetch_multiple.js
Normal file
7
client/tests/scripts/fetch_multiple.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
async function test() {
|
||||
await libcurl.fetch("https://example.com/");
|
||||
for (let i=0; i<20; i++) {
|
||||
let r = await libcurl.fetch("https://example.com/");
|
||||
assert(r.status === 200, "wrong status");
|
||||
}
|
||||
}
|
4
client/tests/scripts/fetch_once.js
Normal file
4
client/tests/scripts/fetch_once.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
async function test() {
|
||||
let r = await libcurl.fetch("https://example.com/");
|
||||
assert(r.status === 200, "wrong status");
|
||||
}
|
8
client/tests/scripts/fetch_parallel.js
Normal file
8
client/tests/scripts/fetch_parallel.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
async function test() {
|
||||
await libcurl.fetch("https://www.example.com/");
|
||||
let promises = [];
|
||||
for (let i=0; i<10; i++) {
|
||||
promises.push(libcurl.fetch("https://www.example.com/"))
|
||||
}
|
||||
await Promise.all(promises);
|
||||
}
|
24
client/tests/scripts/test_websocket.js
Normal file
24
client/tests/scripts/test_websocket.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
function test() {
|
||||
let message_len = 128*1024;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
let ws = new libcurl.WebSocket("wss://echo.websocket.org");
|
||||
ws.addEventListener("open", () => {
|
||||
ws.send("hello".repeat(message_len));
|
||||
});
|
||||
|
||||
let messages = 0;
|
||||
ws.addEventListener("message", (event) => {
|
||||
messages += 1;
|
||||
if (messages >= 2) {
|
||||
if (event.data !== "hello".repeat(message_len)) reject("unexpected response");
|
||||
if (messages >= 11) resolve();
|
||||
ws.send("hello".repeat(message_len));
|
||||
}
|
||||
});
|
||||
|
||||
ws.addEventListener("error", () => {
|
||||
reject("ws error occurred");
|
||||
});
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue