- commit
- 8996d5ae54a6ea809e3f9c3f7f43db17d660b6b9
- parent
- 90540e1acf3f7e2591d85c967da7ab11cfd75878
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-02-02 18:53
wpt: generalize
Diffstat
| M | Makefile | 6 | +++--- |
| M | test/index.html | 2 | +- |
| M | test/test-wpt.js | 36 | ++++++++++++++++++++---------------- |
| R | test/wpt-accname.js -> test/wpt.js | 4 | ++-- |
| M | wpt.py | 71 | +++++++++++++++++++++++++++++++++++-------------------------- |
5 files changed, 67 insertions, 52 deletions
diff --git a/Makefile b/Makefile
@@ -6,10 +6,10 @@ wpt-master: 6 6 wget https://github.com/web-platform-tests/wpt/archive/refs/heads/master.zip -O wpt-master.zip 7 7 unzip wpt-master.zip 8 89 -1 test/wpt-accname.js: wpt.py wpt-master10 -1 python wpt.py wpt-master/accname/ > $@-1 9 test/wpt.js: wpt.py wpt-master -1 10 python wpt.py > $@ 11 1112 -1 test: test/wpt-accname.js-1 12 test: test/wpt.js 13 13 PUPPETEER_EXECUTABLE_PATH=$$(which chromium) npx mocha-headless-chrome -a no-sandbox -f test/index.html 14 14 15 15 install:
diff --git a/test/index.html b/test/index.html
@@ -13,7 +13,7 @@ 13 13 <script src="../dist/aria.js"></script> 14 14 15 15 <script>mocha.setup('bdd')</script>16 -1 <script src="wpt-accname.js"></script>-1 16 <script src="wpt.js"></script> 17 17 <script src="test-name.js"></script> 18 18 <script src="test-role.js"></script> 19 19 <script src="test-hidden.js"></script>
diff --git a/test/test-wpt.js b/test/test-wpt.js
@@ -13,22 +13,26 @@ describe('wpt', () => {
13 13 document.body.removeChild(testbed);
14 14 });
15 15
16 -1 window.wpt.accname.forEach(test => {
17 -1 var _it = known_failing.includes(test.title) ? xit : it;
18 -1 _it(test.title, () => {
19 -1 testbed.innerHTML = test.html;
20 -1 for (var element of document.querySelectorAll(test.selector)) {
21 -1 var name = element.dataset.expectedlabel ?? test.name;
22 -1 var description = element.dataset.expecteddescription ?? test.description;
23 -1 expect(name ?? description).toNotBe(null);
-1 16 for (const key in window.wpt) {
-1 17 describe(key, () => {
-1 18 window.wpt[key].forEach(test => {
-1 19 var _it = known_failing.includes(test.title) ? xit : it;
-1 20 _it(test.title, () => {
-1 21 testbed.innerHTML = test.html;
-1 22 for (var element of document.querySelectorAll(test.selector)) {
-1 23 var name = element.dataset.expectedlabel ?? test.name;
-1 24 var description = element.dataset.expecteddescription ?? test.description;
-1 25 expect(name ?? description).toNotBe(null);
24 26
25 -1 if (name !== null) {
26 -1 expect(aria.getName(element)).toBe(name);
27 -1 }
28 -1 if (description !== null) {
29 -1 expect(aria.getDescription(element)).toBe(description);
30 -1 }
31 -1 }
-1 27 if (name !== null) {
-1 28 expect(aria.getName(element)).toBe(name);
-1 29 }
-1 30 if (description !== null) {
-1 31 expect(aria.getDescription(element)).toBe(description);
-1 32 }
-1 33 }
-1 34 });
-1 35 });
32 36 });
33 -1 });
-1 37 }
34 38 });
diff --git a/test/wpt-accname.js b/test/wpt.js
@@ -1,5 +1,5 @@ 1 1 window.wpt = window.wpt || {};2 -1 window.wpt.accname = [-1 2 window.wpt["accname"] = [ 3 3 { 4 4 "filename": "description_test_case_666-manual.html", 5 5 "title": "Description test case 666", @@ -1336,4 +1336,4 @@ window.wpt.accname = [ 1336 1336 "description": null, 1337 1337 "selector": ".ex" 1338 1338 }1339 -1 ]-1 1339 ];
diff --git a/wpt.py b/wpt.py
@@ -1,8 +1,6 @@1 -1 import sys2 -1 import os3 1 import json4 -15 -1 tests = []-1 2 import os -1 3 import sys 6 4 7 5 8 6 def fenced(before, after, s): @@ -20,31 +18,44 @@ def get_value(word, s): 20 18 return fenced('"is",', ']', s[start + len(word):]).strip().strip('"') 21 19 22 2023 -1 for root, _dirs, files in sorted(os.walk(sys.argv[1])):24 -1 for filename in files:25 -1 if not filename.endswith('.html'):26 -1 continue27 -128 -1 with open(os.path.join(root, filename)) as fh:29 -1 raw = fh.read()30 -1 if '<div id="manualMode">' in raw:31 -1 tests.append({32 -1 'filename': filename,33 -1 'title': fenced('<title>', '</title>', raw),34 -1 'html': fenced('<body>', '<div id="manualMode">', raw).strip(),35 -1 'name': get_value('"accName"', raw),36 -1 'description': get_value('"accDescription"', raw),37 -1 'selector': '#test',38 -1 })39 -1 elif 'class="ex"' in raw:40 -1 tests.append({41 -1 'filename': filename,42 -1 'title': fenced('<title>', '</title>', raw),43 -1 'html': fenced('<body>', '<script>', raw).strip(),44 -1 'name': None,45 -1 'description': None,46 -1 'selector': '.ex',47 -1 })-1 21 def extract_tests(path): -1 22 tests = [] -1 23 -1 24 for root, _dirs, files in sorted(os.walk(path)): -1 25 for filename in files: -1 26 if not filename.endswith('.html'): -1 27 continue -1 28 -1 29 with open(os.path.join(root, filename)) as fh: -1 30 raw = fh.read() -1 31 -1 32 if '<div id="manualMode">' in raw: -1 33 tests.append({ -1 34 'filename': filename, -1 35 'title': fenced('<title>', '</title>', raw), -1 36 'html': fenced('<body>', '<div id="manualMode">', raw).strip(), -1 37 'name': get_value('"accName"', raw), -1 38 'description': get_value('"accDescription"', raw), -1 39 'selector': '#test', -1 40 }) -1 41 elif 'class="ex"' in raw: -1 42 tests.append({ -1 43 'filename': filename, -1 44 'title': fenced('<title>', '</title>', raw), -1 45 'html': fenced('<body>', '<script>', raw).strip(), -1 46 'name': None, -1 47 'description': None, -1 48 'selector': '.ex', -1 49 }) -1 50 return tests -1 51 -1 52 -1 53 def render_tests(name): -1 54 path = os.path.join('wpt-master', name) -1 55 tests = extract_tests(path) -1 56 rendered = json.dumps(tests, indent='\t') -1 57 print(f'window.wpt["{name}"] = {rendered};') -1 58 48 59 49 60 print('window.wpt = window.wpt || {};')50 -1 print('window.wpt.accname = ' + json.dumps(tests, indent='\t'))-1 61 render_tests('accname')