Last active
April 29, 2020 16:13
-
-
Save AutoSponge/0091c13cd5efbf14a3f4f670c7551090 to your computer and use it in GitHub Desktop.
Revisions
-
AutoSponge revised this gist
Apr 29, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,12 +8,12 @@ function* walkAxTree(node, filter) { yield* walkAxTree(child, filter); } } function validateHeadings(iterable) { const found = { h1: false, last: null, }; for (const node of iterable) { const next = node.level; const { last, h1 } = found; if (last && next > last + 1) return [false, node]; -
AutoSponge revised this gist
Apr 29, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,6 +26,6 @@ function validateHeadings(arr) { return [true]; } await page.goto('https://sumptuous-peppered-pocket.glitch.me/'); await page.click('button:nth-of-type(2)'); // 1 is no error, 2 skips, 3 repeats h1 var axTree = await page.accessibility.snapshot(); validateHeadings(walkAxTree(axTree, (n) => n.role === 'heading')); -
AutoSponge revised this gist
Apr 29, 2020 . 1 changed file with 13 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,14 +9,23 @@ function* walkAxTree(node, filter) { } } function validateHeadings(arr) { const found = { h1: false, last: null, }; for (const node of arr) { const next = node.level; const { last, h1 } = found; if (last && next > last + 1) return [false, node]; if (next === 1) { if (h1) return [false, node]; found.h1 = true; } found.last = node.level; } return [true]; } await page.goto('https://sumptuous-peppered-pocket.glitch.me/'); await page.click('button:nth-of-type(3)'); var axTree = await page.accessibility.snapshot(); validateHeadings(walkAxTree(axTree, (n) => n.role === 'heading')); -
AutoSponge revised this gist
Apr 29, 2020 . 1 changed file with 8 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,11 @@ // start scriptwriter (see https://scriptwriter.dev) function* walkAxTree(node, filter) { if (filter(node)) { yield node; } const children = node.children || []; for (const child of children) { yield* walkAxTree(child, filter); } } function validateHeadings(arr) { @@ -14,9 +16,7 @@ function validateHeadings(arr) { } return [true]; } await page.goto('https://sumptuous-peppered-pocket.glitch.me/'); await page.click('button:nth-of-type(2)'); var axTree = await page.accessibility.snapshot(); validateHeadings(walkAxTree(axTree, (n) => n.role === 'heading')); -
AutoSponge created this gist
Apr 29, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ // scriptwriter function* walkAxTree(node) { yield node; const children = node.children || []; for (const child of children) { yield* walkAxTree(child); } } function validateHeadings(arr) { let current = 1; for (const node of arr) { if (node.level > current + 1) return [false, node]; current = node.level; } return [true]; } await page.gogo('https://sumptuous-peppered-pocket.glitch.me/'); await page.click('button:nth-of-type(2)'); var axTree = await page.accessibility.snapshot(); var flat = [...walkAxTree(axTree)]; validateHeadings(flat.filter((n) => n.role === 'heading')); // [false, { role: 'heading', name: 'level 3 heading', level: 3 }]