Skip to content

Commit a037413

Browse files
committed
migrate tests to new html runner
1 parent 055f697 commit a037413

File tree

4 files changed

+52
-48
lines changed

4 files changed

+52
-48
lines changed

src/browser/polyfill/webcomponents.zig

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,6 @@ pub const pre =
3737
;
3838

3939
const testing = @import("../../testing.zig");
40-
test "Browser.webcomponents" {
41-
var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html = "<div id=main></div>" });
42-
defer runner.deinit();
43-
44-
try @import("polyfill.zig").preload(testing.allocator, runner.page.main_context);
45-
46-
try runner.testCases(&.{
47-
.{
48-
\\ class LightPanda extends HTMLElement {
49-
\\ constructor() {
50-
\\ super();
51-
\\ }
52-
\\ connectedCallback() {
53-
\\ this.append('connected');
54-
\\ }
55-
\\ }
56-
\\ window.customElements.define("lightpanda-test", LightPanda);
57-
\\ const main = document.getElementById('main');
58-
\\ main.appendChild(document.createElement('lightpanda-test'));
59-
,
60-
null,
61-
},
62-
63-
.{ "main.innerHTML", "<lightpanda-test>connected</lightpanda-test>" },
64-
.{ "document.createElement('lightpanda-test').dataset", "[object DataSet]" },
65-
.{ "document.createElement('lightpanda-test.x').dataset", "[object DataSet]" },
66-
}, .{});
40+
test "Browser: Polyfill.WebComponents" {
41+
try testing.htmlRunner("polyfill/webcomponents.html");
6742
}

src/browser/storage/storage.zig

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -208,29 +208,11 @@ pub const Bottle = struct {
208208
// -----
209209

210210
const testing = @import("../../testing.zig");
211-
test "Browser.Storage.LocalStorage" {
212-
var runner = try testing.jsRunner(testing.tracking_allocator, .{});
213-
defer runner.deinit();
214-
215-
try runner.testCases(&.{
216-
.{ "localStorage.length", "0" },
217-
218-
.{ "localStorage.setItem('foo', 'bar')", "undefined" },
219-
.{ "localStorage.length", "1" },
220-
.{ "localStorage.getItem('foo')", "bar" },
221-
.{ "localStorage.removeItem('foo')", "undefined" },
222-
.{ "localStorage.length", "0" },
223-
224-
// .{ "localStorage['foo'] = 'bar'", "undefined" },
225-
// .{ "localStorage['foo']", "bar" },
226-
// .{ "localStorage.length", "1" },
227-
228-
.{ "localStorage.clear()", "undefined" },
229-
.{ "localStorage.length", "0" },
230-
}, .{});
211+
test "Browser: Storage.LocalStorage" {
212+
try testing.htmlRunner("storage/local_storage.html");
231213
}
232214

233-
test "storage bottle" {
215+
test "Browser: Storage.Bottle" {
234216
var bottle = Bottle.init(std.testing.allocator);
235217
defer bottle.deinit();
236218

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<script src="../testing.js"></script>
2+
3+
<div id=main></div>
4+
5+
<script id=webcomponents>
6+
class LightPanda extends HTMLElement {
7+
constructor() {
8+
super();
9+
}
10+
connectedCallback() {
11+
this.append('connected');
12+
}
13+
}
14+
15+
window.customElements.define("lightpanda-test", LightPanda);
16+
const main = document.getElementById('main');
17+
main.appendChild(document.createElement('lightpanda-test'));
18+
19+
testing.expectEqual('<lightpanda-test>connected</lightpanda-test>', main.innerHTML)
20+
testing.expectEqual('[object DataSet]', document.createElement('lightpanda-test').dataset.toString());
21+
testing.expectEqual('[object DataSet]', document.createElement('lightpanda-test.x').dataset.toString());
22+
</script>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script src="../testing.js"></script>
2+
3+
<script id=localstorage>
4+
testing.expectEqual(0, localStorage.length);
5+
testing.expectEqual(null, localStorage.getItem('foo'));
6+
7+
localStorage.setItem('foo', 'bar');
8+
testing.expectEqual(1, localStorage.length)
9+
testing.expectEqual('bar', localStorage.getItem('foo'));
10+
11+
localStorage.removeItem('foo');
12+
testing.expectEqual(0, localStorage.length)
13+
testing.expectEqual(null, localStorage.getItem('foo'));
14+
15+
localStorage['foo'] = 'bar';
16+
testing.expectEqual(1, localStorage.length);
17+
testing.expectEqual('bar', localStorage['foo']);
18+
19+
localStorage.setItem('a', '1');
20+
localStorage.setItem('b', '2');
21+
localStorage.setItem('c', '3');
22+
testing.expectEqual(3, localStorage.length)
23+
localStorage.clear();
24+
localStorage.length", "0" },
25+
</script>

0 commit comments

Comments
 (0)