Skip to content

Commit a700280

Browse files
committed
fix arena, add fetch test
1 parent 54734b9 commit a700280

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/browser/fetch/fetch.zig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub fn fetch(input: RequestInput, options: ?RequestInit, page: *Page) !Env.Promi
111111
while (header_iter.next()) |entry| {
112112
// This is fine because curl/headers copies it internally.
113113
const combined = try std.fmt.allocPrintSentinel(
114-
page.call_arena,
114+
page.arena,
115115
"{s}: {s}",
116116
.{ entry.key_ptr.*, entry.value_ptr.* },
117117
0,
@@ -229,3 +229,8 @@ pub fn fetch(input: RequestInput, options: ?RequestInit, page: *Page) !Env.Promi
229229

230230
return resolver.promise();
231231
}
232+
233+
const testing = @import("../../testing.zig");
234+
test "fetch: fetch" {
235+
try testing.htmlRunner("fetch/fetch.html");
236+
}

src/tests/fetch/fetch.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script src="../testing.js"></script>
2+
<script id=fetch type=module>
3+
const promise1 = new Promise((resolve) => {
4+
fetch('http://127.0.0.1:9582/xhr/json')
5+
.then((res) => {
6+
return res.json()
7+
})
8+
.then((json) => {
9+
resolve(json);
10+
});
11+
});
12+
13+
testing.async(promise1, (json) => {
14+
testing.expectEqual({over: '9000!!!'}, json);
15+
});
16+
</script>

src/tests/fetch/response.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,14 @@
3636
let emptyResponse = new Response("");
3737
testing.expectEqual(200, emptyResponse.status);
3838
</script>
39+
40+
<script id=json type=module>
41+
const promise1 = new Promise((resolve) => {
42+
let response = new Response('[]');
43+
response.json().then(resolve)
44+
});
45+
46+
testing.async(promise1, (json) => {
47+
testing.expectEqual([], json);
48+
});
49+
</script>ref

0 commit comments

Comments
 (0)