- commit
- 3d3015b77e497494e3a380836a60171bbfc124c0
- parent
- 9f8db1ff74116f4b304e3f385c2566c0b3489701
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-02-03 09:33
wpt: extract subtests
Diffstat
| M | test/test-wpt.js | 77 | +++++++++++++++++++++++++++++++++++++++++++++++-------------- |
1 files changed, 60 insertions, 17 deletions
diff --git a/test/test-wpt.js b/test/test-wpt.js
@@ -1,3 +1,5 @@ -1 1 /* global describe, it, xit, before, after, expect, aria */ -1 2 1 3 describe('wpt', () => { 2 4 var testbed = document.createElement('div'); 3 5 var known_failing = [ @@ -5,33 +7,74 @@ describe('wpt', () => { 5 7 'Name test case 659', 6 8 ]; 7 9 -1 10 var withId = function(element, fn) { -1 11 if (element.id) { -1 12 fn(); -1 13 } else { -1 14 element.id = 'subtest'; -1 15 fn(); -1 16 element.removeAttribute('id'); -1 17 } -1 18 }; -1 19 -1 20 var extractTests = function(data) { -1 21 var tests = []; -1 22 document.body.appendChild(testbed); -1 23 testbed.innerHTML = data.html; -1 24 for (var element of testbed.querySelectorAll(data.selector)) { -1 25 withId(element, () => { -1 26 tests.push({ -1 27 'filename': data.filename, -1 28 'title': element.dataset.testname || data.title, -1 29 'html': testbed.innerHTML, -1 30 'name': element.dataset.expectedlabel, -1 31 'description': element.dataset.expecteddescription, -1 32 'role': element.dataset.expectedrole, -1 33 'selector': `#${element.id}`, -1 34 }); -1 35 }); -1 36 } -1 37 testbed.remove(); -1 38 return tests; -1 39 }; -1 40 -1 41 var registerTest = function(test) { -1 42 var _it = known_failing.includes(test.title) ? xit : it; -1 43 _it(test.title, () => { -1 44 testbed.innerHTML = test.html; -1 45 expect(test.name != null || test.description != null || test.role != null).toBe(true); -1 46 var element = testbed.querySelector(test.selector); -1 47 -1 48 if (test.name != null) { -1 49 expect(aria.getName(element)).toBe(test.name); -1 50 } -1 51 if (test.description != null) { -1 52 expect(aria.getDescription(element)).toBe(test.description); -1 53 } -1 54 if (test.role != null) { -1 55 expect(aria.getRole(element)).toBe(test.role); -1 56 } -1 57 }); -1 58 }; -1 59 8 60 before(() => { 9 61 document.body.appendChild(testbed); 10 62 }); 11 63 12 64 after(() => {13 -1 document.body.removeChild(testbed);-1 65 testbed.remove(); 14 66 }); 15 67 16 68 for (const key in window.wpt) { 17 69 describe(key, () => { 18 70 window.wpt[key].forEach(test => {19 -1 var _it = known_failing.includes(test.title) ? xit : it;20 -1 _it(test.title, () => {21 -1 testbed.innerHTML = test.html;22 -1 for (var element of document.querySelectorAll(test.selector)) {23 -1 var name = element.dataset.expectedlabel ?? test.name ?? null;24 -1 var description = element.dataset.expecteddescription ?? test.description ?? null;25 -1 expect(name ?? description).toNotBe(null);26 -127 -1 if (name !== null) {28 -1 expect(aria.getName(element)).toBe(name);29 -1 }30 -1 if (description !== null) {31 -1 expect(aria.getDescription(element)).toBe(description);32 -1 }33 -1 }34 -1 });-1 71 if (test.selector.startsWith('#')) { -1 72 registerTest(test); -1 73 } else { -1 74 describe(test.title, () => { -1 75 extractTests(test).forEach(registerTest); -1 76 }); -1 77 } 35 78 }); 36 79 }); 37 80 }