Skip to content

Commit f77693d

Browse files
committed
migrate more tests to htmlRunner
1 parent edd41b3 commit f77693d

File tree

10 files changed

+284
-331
lines changed

10 files changed

+284
-331
lines changed

src/browser/console/console.zig

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -166,74 +166,3 @@ pub const Console = struct {
166166
fn timestamp() u32 {
167167
return @import("../../datetime.zig").timestamp();
168168
}
169-
170-
// const testing = @import("../../testing.zig");
171-
// test "Browser.Console" {
172-
// defer testing.reset();
173-
174-
// var runner = try testing.jsRunner(testing.tracking_allocator, .{});
175-
// defer runner.deinit();
176-
177-
// {
178-
// try runner.testCases(&.{
179-
// .{ "console.log('a')", "undefined" },
180-
// .{ "console.warn('hello world', 23, true, new Object())", "undefined" },
181-
// }, .{});
182-
183-
// const captured = test_capture.captured.items;
184-
// try testing.expectEqual("[info] args= 1: a", captured[0]);
185-
// try testing.expectEqual("[warn] args= 1: hello world 2: 23 3: true 4: #<Object>", captured[1]);
186-
// }
187-
188-
// {
189-
// test_capture.reset();
190-
// try runner.testCases(&.{
191-
// .{ "console.countReset()", "undefined" },
192-
// .{ "console.count()", "undefined" },
193-
// .{ "console.count('teg')", "undefined" },
194-
// .{ "console.count('teg')", "undefined" },
195-
// .{ "console.count('teg')", "undefined" },
196-
// .{ "console.count()", "undefined" },
197-
// .{ "console.countReset('teg')", "undefined" },
198-
// .{ "console.countReset()", "undefined" },
199-
// .{ "console.count()", "undefined" },
200-
// }, .{});
201-
202-
// const captured = test_capture.captured.items;
203-
// try testing.expectEqual("[invalid counter] label=default", captured[0]);
204-
// try testing.expectEqual("[count] label=default count=1", captured[1]);
205-
// try testing.expectEqual("[count] label=teg count=1", captured[2]);
206-
// try testing.expectEqual("[count] label=teg count=2", captured[3]);
207-
// try testing.expectEqual("[count] label=teg count=3", captured[4]);
208-
// try testing.expectEqual("[count] label=default count=2", captured[5]);
209-
// try testing.expectEqual("[count reset] label=teg count=3", captured[6]);
210-
// try testing.expectEqual("[count reset] label=default count=2", captured[7]);
211-
// try testing.expectEqual("[count] label=default count=1", captured[8]);
212-
// }
213-
214-
// {
215-
// test_capture.reset();
216-
// try runner.testCases(&.{
217-
// .{ "console.assert(true)", "undefined" },
218-
// .{ "console.assert('a', 2, 3, 4)", "undefined" },
219-
// .{ "console.assert('')", "undefined" },
220-
// .{ "console.assert('', 'x', true)", "undefined" },
221-
// .{ "console.assert(false, 'x')", "undefined" },
222-
// }, .{});
223-
224-
// const captured = test_capture.captured.items;
225-
// try testing.expectEqual("[assertion failed] values=", captured[0]);
226-
// try testing.expectEqual("[assertion failed] values= 1: x 2: true", captured[1]);
227-
// try testing.expectEqual("[assertion failed] values= 1: x", captured[2]);
228-
// }
229-
230-
// {
231-
// test_capture.reset();
232-
// try runner.testCases(&.{
233-
// .{ "[1].forEach(console.log)", null },
234-
// }, .{});
235-
236-
// const captured = test_capture.captured.items;
237-
// try testing.expectEqual("[info] args= 1: 1 2: 0 3: [1]", captured[0]);
238-
// }
239-
// }

src/browser/xhr/File.zig

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ pub fn constructor() File {
2929
}
3030

3131
const testing = @import("../../testing.zig");
32-
test "Browser.File" {
33-
var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html = "" });
34-
defer runner.deinit();
35-
36-
try runner.testCases(&.{
37-
.{ "let f = new File()", null },
38-
.{ "f instanceof File", "true" },
39-
}, .{});
32+
test "Browser: File" {
33+
try testing.htmlRunner("xhr/file.html");
4034
}

src/browser/xhr/form_data.zig

Lines changed: 4 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub const FormData = struct {
100100
return kv.urlEncode(self.entries, .form, writer);
101101
}
102102

103-
log.warn(.web_api, "not implemented", .{
103+
log.debug(.web_api, "not implemented", .{
104104
.feature = "form data encoding",
105105
.encoding = encoding,
106106
});
@@ -265,132 +265,11 @@ fn getSubmitterName(submitter_: ?*parser.ElementHTML) !?[]const u8 {
265265
}
266266

267267
const testing = @import("../../testing.zig");
268-
test "Browser.FormData" {
269-
var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html =
270-
\\ <form id="form1">
271-
\\ <input id="has_no_name" value="nope1">
272-
\\ <input id="is_disabled" disabled value="nope2">
273-
\\
274-
\\ <input name="txt-1" value="txt-1-v">
275-
\\ <input name="txt-2" value="txt-~-v" type=password>
276-
\\
277-
\\ <input name="chk-3" value="chk-3-va" type=checkbox>
278-
\\ <input name="chk-3" value="chk-3-vb" type=checkbox checked>
279-
\\ <input name="chk-3" value="chk-3-vc" type=checkbox checked>
280-
\\ <input name="chk-4" value="chk-4-va" type=checkbox>
281-
\\ <input name="chk-4" value="chk-4-va" type=checkbox>
282-
\\
283-
\\ <input name="rdi-1" value="rdi-1-va" type=radio>
284-
\\ <input name="rdi-1" value="rdi-1-vb" type=radio>
285-
\\ <input name="rdi-1" value="rdi-1-vc" type=radio checked>
286-
\\ <input name="rdi-2" value="rdi-2-va" type=radio>
287-
\\ <input name="rdi-2" value="rdi-2-vb" type=radio>
288-
\\
289-
\\ <textarea name="ta-1"> ta-1-v</textarea>
290-
\\ <textarea name="ta"></textarea>
291-
\\
292-
\\ <input type=hidden name=h1 value="h1-v">
293-
\\ <input type=hidden name=h2 value="h2-v" disabled=disabled>
294-
\\
295-
\\ <select name="sel-1"><option>blue<option>red</select>
296-
\\ <select name="sel-2"><option>blue<option value=sel-2-v selected>red</select>
297-
\\ <select name="sel-3"><option disabled>nope1<option>nope2</select>
298-
\\ <select name="mlt-1" multiple><option>water<option>tea</select>
299-
\\ <select name="mlt-2" multiple><option selected>water<option selected>tea<option>coffee</select>
300-
\\ <input type=submit id=s1 name=s1 value=s1-v>
301-
\\ <input type=submit name=s2 value=s2-v>
302-
\\ <input type=image name=i1 value=i1-v>
303-
\\ </form>
304-
\\ <input type=text name=abc value=123 form=form1>
305-
});
306-
defer runner.deinit();
307-
308-
try runner.testCases(&.{
309-
.{ "let f = new FormData()", null },
310-
.{ "f.get('a')", "null" },
311-
.{ "f.has('a')", "false" },
312-
.{ "f.getAll('a')", "" },
313-
.{ "f.delete('a')", "undefined" },
314-
315-
.{ "f.set('a', 1)", "undefined" },
316-
.{ "f.has('a')", "true" },
317-
.{ "f.get('a')", "1" },
318-
.{ "f.getAll('a')", "1" },
319-
320-
.{ "f.append('a', 2)", "undefined" },
321-
.{ "f.has('a')", "true" },
322-
.{ "f.get('a')", "1" },
323-
.{ "f.getAll('a')", "1,2" },
324-
325-
.{ "f.append('b', '3')", "undefined" },
326-
.{ "f.has('a')", "true" },
327-
.{ "f.get('a')", "1" },
328-
.{ "f.getAll('a')", "1,2" },
329-
.{ "f.has('b')", "true" },
330-
.{ "f.get('b')", "3" },
331-
.{ "f.getAll('b')", "3" },
332-
333-
.{ "let acc = [];", null },
334-
.{ "for (const key of f.keys()) { acc.push(key) }; acc;", "a,a,b" },
335-
336-
.{ "acc = [];", null },
337-
.{ "for (const value of f.values()) { acc.push(value) }; acc;", "1,2,3" },
338-
339-
.{ "acc = [];", null },
340-
.{ "for (const entry of f.entries()) { acc.push(entry) }; acc;", "a,1,a,2,b,3" },
341-
342-
.{ "acc = [];", null },
343-
.{ "for (const entry of f) { acc.push(entry) }; acc;", "a,1,a,2,b,3" },
344-
345-
.{ "f.delete('a')", "undefined" },
346-
.{ "f.has('a')", "false" },
347-
.{ "f.has('b')", "true" },
348-
349-
.{ "acc = [];", null },
350-
.{ "for (const key of f.keys()) { acc.push(key) }; acc;", "b" },
351-
352-
.{ "acc = [];", null },
353-
.{ "for (const value of f.values()) { acc.push(value) }; acc;", "3" },
354-
355-
.{ "acc = [];", null },
356-
.{ "for (const entry of f.entries()) { acc.push(entry) }; acc;", "b,3" },
357-
358-
.{ "acc = [];", null },
359-
.{ "for (const entry of f) { acc.push(entry) }; acc;", "b,3" },
360-
}, .{});
361-
362-
try runner.testCases(&.{
363-
.{ "let form1 = document.getElementById('form1')", null },
364-
.{ "let input = document.createElement('input');", null },
365-
.{ "input.name = 'dyn'; input.value= 'dyn-v'; form1.appendChild(input);", null },
366-
.{ "let submit1 = document.getElementById('s1')", null },
367-
.{ "let f2 = new FormData(form1, submit1)", null },
368-
.{ "acc = '';", null },
369-
.{
370-
\\ for (const entry of f2) {
371-
\\ acc += entry[0] + '=' + entry[1] + '\n';
372-
\\ };
373-
\\ acc.slice(0, -1)
374-
,
375-
\\txt-1=txt-1-v
376-
\\txt-2=txt-~-v
377-
\\chk-3=chk-3-vb
378-
\\chk-3=chk-3-vc
379-
\\rdi-1=rdi-1-vc
380-
\\ta-1= ta-1-v
381-
\\ta=
382-
\\h1=h1-v
383-
\\sel-1=blue
384-
\\sel-2=sel-2-v
385-
\\mlt-2=water
386-
\\mlt-2=tea
387-
\\s1=s1-v
388-
\\dyn=dyn-v
389-
},
390-
}, .{});
268+
test "Browser: FormData" {
269+
try testing.htmlRunner("xhr/form_data.html");
391270
}
392271

393-
test "Browser.FormData: urlEncode" {
272+
test "Browser: FormData.urlEncode" {
394273
var arr: std.ArrayListUnmanaged(u8) = .empty;
395274
defer arr.deinit(testing.allocator);
396275

src/browser/xhr/progress_event.zig

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,6 @@ pub const ProgressEvent = struct {
6767
};
6868

6969
const testing = @import("../../testing.zig");
70-
test "Browser.XHR.ProgressEvent" {
71-
var runner = try testing.jsRunner(testing.tracking_allocator, .{});
72-
defer runner.deinit();
73-
74-
try runner.testCases(&.{
75-
.{ "let pevt = new ProgressEvent('foo');", "undefined" },
76-
.{ "pevt.loaded", "0" },
77-
.{ "pevt instanceof ProgressEvent", "true" },
78-
.{ "var nnb = 0; var eevt = null; function ccbk(event) { nnb ++; eevt = event; }", "undefined" },
79-
.{ "document.addEventListener('foo', ccbk)", "undefined" },
80-
.{ "document.dispatchEvent(pevt)", "true" },
81-
.{ "eevt.type", "foo" },
82-
.{ "eevt instanceof ProgressEvent", "true" },
83-
}, .{});
70+
test "Browser: XHR.ProgressEvent" {
71+
try testing.htmlRunner("xhr/progress_event.html");
8472
}

src/browser/xhr/xhr.zig

Lines changed: 2 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -755,117 +755,6 @@ pub const XMLHttpRequest = struct {
755755
};
756756

757757
const testing = @import("../../testing.zig");
758-
test "Browser.XHR.XMLHttpRequest" {
759-
var runner = try testing.jsRunner(testing.tracking_allocator, .{});
760-
defer runner.deinit();
761-
762-
try runner.testCases(&.{
763-
.{ "var nb = 0; var evt = null; function cbk(event) { nb ++; evt = event; }", "undefined" },
764-
.{ "const req = new XMLHttpRequest()", "undefined" },
765-
766-
.{ "req.onload = cbk", "function cbk(event) { nb ++; evt = event; }" },
767-
768-
.{ "req.onload", "function cbk(event) { nb ++; evt = event; }" },
769-
.{ "req.onload = cbk", "function cbk(event) { nb ++; evt = event; }" },
770-
771-
.{ "req.open('GET', 'http://127.0.0.1:9582/xhr')", null },
772-
773-
// ensure open resets values
774-
.{ "req.status ", "0" },
775-
.{ "req.statusText", "" },
776-
.{ "req.getAllResponseHeaders()", "" },
777-
.{ "req.getResponseHeader('Content-Type')", "null" },
778-
.{ "req.responseText", "" },
779-
780-
.{ "req.send(); nb", "0" },
781-
782-
// Each case executed waits for all loop callback calls.
783-
// So the url has been retrieved.
784-
.{ "nb", "1" },
785-
.{ "evt.type", "load" },
786-
.{ "evt.loaded > 0", "true" },
787-
.{ "evt instanceof ProgressEvent", "true" },
788-
.{ "req.status", "200" },
789-
.{ "req.statusText", "OK" },
790-
.{ "req.getResponseHeader('Content-Type')", "text/html; charset=utf-8" },
791-
.{ "req.getAllResponseHeaders()", "content-length: 100\r\n" ++
792-
"Content-Type: text/html; charset=utf-8\r\n" },
793-
.{ "req.responseText.length", "100" },
794-
.{ "req.response.length == req.responseText.length", "true" },
795-
.{ "req.responseXML instanceof Document", "true" },
796-
}, .{});
797-
798-
try runner.testCases(&.{
799-
.{ "const req2 = new XMLHttpRequest()", "undefined" },
800-
.{ "req2.open('GET', 'http://127.0.0.1:9582/xhr')", "undefined" },
801-
.{ "req2.responseType = 'document'", "document" },
802-
803-
.{ "req2.send()", "undefined" },
804-
805-
// Each case executed waits for all loop callaback calls.
806-
// So the url has been retrieved.
807-
.{ "req2.status", "200" },
808-
.{ "req2.statusText", "OK" },
809-
.{ "req2.response instanceof Document", "true" },
810-
.{ "req2.responseXML instanceof Document", "true" },
811-
}, .{});
812-
813-
try runner.testCases(&.{
814-
.{ "const req3 = new XMLHttpRequest()", "undefined" },
815-
.{ "req3.open('GET', 'http://127.0.0.1:9582/xhr/json')", "undefined" },
816-
.{ "req3.responseType = 'json'", "json" },
817-
818-
.{ "req3.send()", "undefined" },
819-
820-
// Each case executed waits for all loop callaback calls.
821-
// So the url has been retrieved.
822-
.{ "req3.status", "200" },
823-
.{ "req3.statusText", "OK" },
824-
.{ "req3.response.over", "9000!!!" },
825-
}, .{});
826-
827-
try runner.testCases(&.{
828-
.{ "const req4 = new XMLHttpRequest()", "undefined" },
829-
.{ "req4.open('POST', 'http://127.0.0.1:9582/xhr')", "undefined" },
830-
.{ "req4.send('foo')", "undefined" },
831-
832-
// Each case executed waits for all loop callaback calls.
833-
// So the url has been retrieved.
834-
.{ "req4.status", "200" },
835-
.{ "req4.statusText", "OK" },
836-
.{ "req4.responseText.length > 64", "true" },
837-
}, .{});
838-
839-
try runner.testCases(&.{
840-
.{ "const req5 = new XMLHttpRequest()", "undefined" },
841-
.{ "req5.open('GET', 'http://127.0.0.1:9582/xhr')", "undefined" },
842-
.{ "var status = 0; req5.onload = function () { status = this.status };", "function () { status = this.status }" },
843-
.{ "req5.send()", "undefined" },
844-
845-
// Each case executed waits for all loop callaback calls.
846-
// So the url has been retrieved.
847-
.{ "status", "200" },
848-
}, .{});
849-
850-
try runner.testCases(&.{
851-
.{ "const req6 = new XMLHttpRequest()", null },
852-
.{
853-
\\ var readyStates = [];
854-
\\ var currentTarget = null;
855-
\\ req6.onreadystatechange = (e) => {
856-
\\ currentTarget = e.currentTarget;
857-
\\ readyStates.push(req6.readyState);
858-
\\ }
859-
,
860-
null,
861-
},
862-
.{ "req6.open('GET', 'http://127.0.0.1:9582/xhr')", null },
863-
.{ "req6.send()", null },
864-
.{ "readyStates.length", "4" },
865-
.{ "readyStates[0] === XMLHttpRequest.OPENED", "true" },
866-
.{ "readyStates[1] === XMLHttpRequest.HEADERS_RECEIVED", "true" },
867-
.{ "readyStates[2] === XMLHttpRequest.LOADING", "true" },
868-
.{ "readyStates[3] === XMLHttpRequest.DONE", "true" },
869-
.{ "currentTarget == req6", "true" },
870-
}, .{});
758+
test "Browser: XHR.XMLHttpRequest" {
759+
try testing.htmlRunner("xhr/xhr.html");
871760
}

0 commit comments

Comments
 (0)