Skip to content

test: for outdated links across all markdown pages #854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions __tests__/hyperlinks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Note:
* This is a top level test suite, which runs across all the markdown pages under `_rules`, `pages` etc.,
* which is why this is not scoped under `__tests__` within any of those sections.
*/
const markdownLinkExtractor = require('markdown-link-extractor')
const isUrl = require('is-url')

const describeRule = require('../test-utils/describe-rule')
const describePage = require('../test-utils/describe-page')

const badLinksAndRecommendations = {
'://www.w3.org/TR/WCAG20/': 'Use WCAG 2.1 reference- https://www.w3.org/WAI/WCAG21/',
'://www.w3.org/TR/UNDERSTANDING-WCAG20/': 'Use WCAG 2.1 reference - https://www.w3.org/WAI/WCAG21/Understanding/',
'://www.w3.org/TR/WCAG20-TECHS/': 'Use WCAG 2.1 reference - https://www.w3.org/WAI/WCAG21/Techniques/',
'://www.w3.org/TR/wai-aria-1.0/': 'Use ARIA 1.1 reference - https://www.w3.org/TR/wai-aria-1.1/',
'://www.w3.org/TR/dom41/': 'Use http://dom.spec.whatwg.org',
'://www.w3.org/TR/html/': 'Use http://html.spec.whatwg.org'
};

/**
* Find first matching bad link for a given link
* @param {String} link link url
* @returns {String}
*/
const getBadLink = link => {
return Object.keys(badLinksAndRecommendations)
.find(badLink => link.includes(badLink))
}

/**
* Test markdown body for outdated links
* @param {String} param markdown body
*/
const validateMarkdownBody = ({ body }) => {
const hyperlinks = markdownLinkExtractor(body).filter(link => isUrl(link))
if (!hyperlinks || !hyperlinks.length) {
return
}
test.each(hyperlinks)('%s', link => {
const badLink = getBadLink(link)
const recommendation = badLinksAndRecommendations[badLink]
expect(!!badLink, recommendation).toBe(false)
})
}

/**
* Validate `Rules` and `Pages` markdown files
*/
describe('Validate hyperlinks are not outdated', () => {
describeRule('hyperlinks', ruleData => validateMarkdownBody(ruleData))
describePage('hyperlinks', pageData => validateMarkdownBody(pageData))
})
33 changes: 0 additions & 33 deletions _rules/__tests__/hyperlinks.js

This file was deleted.

13 changes: 5 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"gfm-code-blocks": "^1.0.0",
"globby": "^10.0.1",
"is-url": "^1.2.4",
"jest-expect-message": "^1.0.2",
"jsonld": "^1.6.2",
"make-dir": "^3.0.0",
"markdown-link-extractor": "^1.2.1",
Expand Down Expand Up @@ -202,10 +203,10 @@
}
},
"jest": {
"verbose": true,
"bail": true,
"verbose": false,
"setupFilesAfterEnv": [
"jest-extended"
"jest-extended",
"jest-expect-message"
],
"testPathIgnorePatterns": [
"<rootDir>/test-utils/",
Expand Down
4 changes: 2 additions & 2 deletions pages/design/definition-of-done.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ The Definition of "Done" is a living document, and might change as the rule writ
## The Definition of "Done"

- The relation between the rule and its accessibility requirements is as described in the [ACT Rules Format](https://www.w3.org/TR/act-rules-format/) under [Accessibility Requirements](https://www.w3.org/TR/act-rules-format/#structure-accessibility-requirements).
- Remember to also check that the rule is in line with supporting documentation, e.g. [Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/) and [Techniques for WCAG 2.0](https://www.w3.org/TR/WCAG-TECHS/)
- Remember to also check that the rule is in line with supporting documentation, e.g. [Understanding WCAG 2.1](https://www.w3.org/WAI/WCAG21/Understanding/) and [Techniques for WCAG 2.1](https://www.w3.org/WAI/WCAG21/Techniques/)
- Applicability (for [atomic](https://www.w3.org/TR/act-rules-format/#test-applicability) / [composed rules](https://www.w3.org/TR/act-rules-format/#aggregation-applicability)) and Expectations (for [atomic](https://www.w3.org/TR/act-rules-format/#test-expectations) / [composed rules](https://www.w3.org/TR/act-rules-format/#aggregation-expectations)) live up to the requirements for these sections in the [ACT Rules Format](https://www.w3.org/TR/act-rules-format/)
- Requirements for use of atomic and composed rules are followed, see [Rule Types](https://www.w3.org/TR/act-rules-format/#rule-types) in the [ACT Rules Format](https://www.w3.org/TR/act-rules-format/)
- The rule follows the WCAG-ACT-RULES-CG [rule template](/design/rule-template.html), especially in relation to headings, styling, test case descriptions, etc.
- The rule is using WCAG-ACT-RULES-CG [Glossary terms]({{ site.url }}/pages/glossary) whenever possible. Be particularly aware of the following much-used algorithms:
- For the Applicability, consider if the definitions [included in the accessibility tree](#included-in-the-accessibility-tree) and [visible on the page](#visible-on-the-page) should be used to narrow down the scope of the rule.
- For the Applicability and Expectations, consider if the definition for [semantic role](#semantic-role) (including specifics of explicit and implicit semantic role) could be used to describe the targets of the rule.
- The rule links to any relevant documentation, e.g. [Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/) and [Techniques for WCAG 2.0](https://www.w3.org/TR/WCAG-TECHS/), specifications used, etc.
- The rule links to any relevant documentation, e.g. [Understanding WCAG 2.1](https://www.w3.org/WAI/WCAG21/Understanding/) and [Techniques for WCAG 2.1](https://www.w3.org/WAI/WCAG21/Techniques/), specifications used, etc.
- The name of the rule is written in plain language, with capitalized initial letter
- The file name of the rule follows the WCAG-ACT-RULES-CG naming convention
- The rule has been spellchecked
Expand Down
2 changes: 1 addition & 1 deletion pages/design/rule-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Many accessibility evaluations (especially automated tools) make assumptions abo

While most assumptions relate to the rule itself, there are some assumptions that apply at other stages of the evaluation:

- It is assumed that the tested web page is the one that has to conform to WCAG 2.0 and that there is no [conforming alternative version](http://www.w3.org/TR/WCAG20/#conforming-alternate-versiondef).
- It is assumed that the tested web page is the one that has to conform to WCAG 2.0 and that there is no [conforming alternative version](https://www.w3.org/TR/WCAG21/#dfn-conforming-alternate-version).

- It is assumed that the following technologies are accessibility supported: HTML, CSS, WAI-ARIA, ... (See also WCAG-ACT-RULES-CG's [explanation on Accessibility Support](accessibility-support.html)).

Expand Down
2 changes: 1 addition & 1 deletion pages/glossary/focusable.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ title: Focusable
key: focusable
---

Elements that can become the target of keyboard input as described in the [HTML](https://www.w3.org/TR/html) specification of [focusable](https://www.w3.org/TR/html/editing.html#focusable) and [can be focused](https://www.w3.org/TR/html/editing.html#can-be-focused).
Elements that can become the target of keyboard input as described in the [HTML](https://www.w3.org/TR/html) specification of [focusable](https://html.spec.whatwg.org/#focusable-area) and [can be focused](https://html.spec.whatwg.org/#specially-focusable).
2 changes: 1 addition & 1 deletion pages/glossary/implicit-role.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ title: Implicit Semantic Role
key: implicit-role
---

The Implicit Semantic Role is the [semantic role](#semantic-role) of each element that is used when no valid [explicit semantic role](#explicit-role) is specified. Elements with no [role attribute](https://www.w3.org/TR/html/dom.html#aria-role-attribute), or with a [role attribute](https://www.w3.org/TR/role-attribute/) containing no valid token, are mapped to their implicit role.
The Implicit Semantic Role is the [semantic role](#semantic-role) of each element that is used when no valid [explicit semantic role](#explicit-role) is specified. Elements with no [role attribute](https://html.spec.whatwg.org/#attr-aria-role), or with a [role attribute](https://www.w3.org/TR/role-attribute/) containing no valid token, are mapped to their implicit role.

Implicit roles for HTML and SVG, are documented in the [HTML accessibility API mappings](https://www.w3.org/TR/html-aam/) (work in progress), the [ARIA in HTML](https://www.w3.org/TR/html-aria/) (work in progress) documentation, and the [SVG accessibility API mappings](https://www.w3.org/TR/svg-aam/) (work in progress).
2 changes: 1 addition & 1 deletion pages/glossary/matching-characters.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ title: Matching characters
key: matching-characters
---

A sequence of [characters](#character) is considered to match another if, after removing leading and trailing [space characters](https://www.w3.org/TR/html/infrastructure.html#space-characters) and replacing remaining occurrences of one or more space characters with a single space, the two sequences of characters are equal character-by-character, ignoring any differences in letter casing.
A sequence of [characters](#character) is considered to match another if, after removing leading and trailing [space characters](https://html.spec.whatwg.org/#white_space) and replacing remaining occurrences of one or more space characters with a single space, the two sequences of characters are equal character-by-character, ignoring any differences in letter casing.
2 changes: 1 addition & 1 deletion pages/glossary/visible-text-content.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ title: Visible Text Content
key: visible-text-content
---

Elements that are [visible](#visible), that are of type text, excluding text content in `title` or `alt` attributes, and are not categorised as [non text content](https://www.w3.org/TR/UNDERSTANDING-WCAG20/text-equiv-all.html).
Elements that are [visible](#visible), that are of type text, excluding text content in `title` or `alt` attributes, and are not categorised as [non text content](https://www.w3.org/WAI/WCAG21/Understanding/non-text-content).

**Note**: These elements should also be ensured to meet the color contrast and visibility requirements.
21 changes: 21 additions & 0 deletions test-utils/describe-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const getPagesMarkdownData = require('../utils/get-pages-markdown-data')

/**
* describe page helper
* @param {String} groupName name of the `describe` block
* @param {Function} runTests function callback of `describle` block, which executes per page
*/
const describePage = (groupName, runTests) => {
const pages = getPagesMarkdownData()

pages.forEach(pageData => {
const { filename } = pageData
describe(filename, () => {
describe(groupName, () => {
runTests(pageData)
})
})
})
}

module.exports = describePage
10 changes: 10 additions & 0 deletions utils/get-pages-markdown-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const globby = require('globby')
const getMarkdownData = require('./get-markdown-data')

/**
* Read all pages & parse the markdown
*/
const getPagesMarkdownData = () => globby.sync([`./pages/**/*.md`])
.map(path => getMarkdownData(path))

module.exports = getPagesMarkdownData