Skip to content

Instantly share code, notes, and snippets.

@AutoSponge
Last active April 29, 2020 16:13
Show Gist options
  • Select an option

  • Save AutoSponge/0091c13cd5efbf14a3f4f670c7551090 to your computer and use it in GitHub Desktop.

Select an option

Save AutoSponge/0091c13cd5efbf14a3f4f670c7551090 to your computer and use it in GitHub Desktop.

Revisions

  1. AutoSponge revised this gist Apr 29, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions shadow-walk-ax.js
    Original file line number Diff line number Diff line change
    @@ -8,12 +8,12 @@ function* walkAxTree(node, filter) {
    yield* walkAxTree(child, filter);
    }
    }
    function validateHeadings(arr) {
    function validateHeadings(iterable) {
    const found = {
    h1: false,
    last: null,
    };
    for (const node of arr) {
    for (const node of iterable) {
    const next = node.level;
    const { last, h1 } = found;
    if (last && next > last + 1) return [false, node];
  2. AutoSponge revised this gist Apr 29, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion shadow-walk-ax.js
    Original 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(3)');
    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'));
  3. AutoSponge revised this gist Apr 29, 2020. 1 changed file with 13 additions and 4 deletions.
    17 changes: 13 additions & 4 deletions shadow-walk-ax.js
    Original file line number Diff line number Diff line change
    @@ -9,14 +9,23 @@ function* walkAxTree(node, filter) {
    }
    }
    function validateHeadings(arr) {
    let current = 1;
    const found = {
    h1: false,
    last: null,
    };
    for (const node of arr) {
    if (node.level > current + 1) return [false, node];
    current = node.level;
    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(2)');
    await page.click('button:nth-of-type(3)');
    var axTree = await page.accessibility.snapshot();
    validateHeadings(walkAxTree(axTree, (n) => n.role === 'heading'));
  4. AutoSponge revised this gist Apr 29, 2020. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions shadow-walk-ax.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,11 @@
    // scriptwriter
    function* walkAxTree(node) {
    yield node;
    // 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);
    yield* walkAxTree(child, filter);
    }
    }
    function validateHeadings(arr) {
    @@ -14,9 +16,7 @@ function validateHeadings(arr) {
    }
    return [true];
    }
    await page.gogo('https://sumptuous-peppered-pocket.glitch.me/');
    await page.goto('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 }]

    validateHeadings(walkAxTree(axTree, (n) => n.role === 'heading'));
  5. AutoSponge created this gist Apr 29, 2020.
    22 changes: 22 additions & 0 deletions shadow-walk-ax.js
    Original 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 }]