forked from act-rules/act-rules.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
560 additions
and
112 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* 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 describeRule = require('../test-utils/describe-rule') | ||
const describePage = require('../test-utils/describe-page') | ||
const isUrl = require('is-url') | ||
const getMarkdownAstNodesOfType = require('../utils/get-markdown-ast-nodes-of-type') | ||
const uniqueArray = require('../utils/unique-array') | ||
|
||
/** | ||
* Map of bad links vs their recommendations | ||
*/ | ||
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', | ||
} | ||
|
||
/** | ||
* Validate `Rules` and `Pages` markdown files | ||
*/ | ||
describe('Validate links are not outdated', () => { | ||
describeRule('Rules', ({ markdownAST }) => validateIfLinksAreOutdated(markdownAST)) | ||
describePage('Pages', ({ markdownAST }) => validateIfLinksAreOutdated(markdownAST)) | ||
}) | ||
|
||
function validateIfLinksAreOutdated(markdownAST) { | ||
/** | ||
* get all links | ||
* -> eg: [Alpha](https://....) | ||
*/ | ||
const pageLinks = getMarkdownAstNodesOfType(markdownAST, 'link').map(({ url }) => url) | ||
/** | ||
* get all definition links | ||
* -> eg: [alpha]: https:// 'Link to something' | ||
*/ | ||
const definitionLinks = getMarkdownAstNodesOfType(markdownAST, 'definition').map(({ url }) => url) | ||
|
||
/** | ||
* get all links that is a valid | ||
* -> this test does not cover glossary/ definition referencing links (see test - 'link-to-glossary-term-valid.js') | ||
*/ | ||
const links = uniqueArray([...pageLinks, ...definitionLinks].filter(isUrl)) | ||
if (links.length === 0) { | ||
return | ||
} | ||
|
||
test.each(links)('%s', link => { | ||
const badLink = Object.keys(badLinksAndRecommendations).find(badLink => link.includes(badLink)) | ||
expect(!!badLink, badLinksAndRecommendations[badLink]).toBe(false) | ||
}) | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Note: | ||
* | ||
* In markdownAST, | ||
* a link reference is something like [Alpha][Bravo] or [Alpha][], and | ||
* a definition is something like [alpha]: https://example.com | ||
* | ||
* See: https://github.com/syntax-tree/mdast#nodes | ||
* | ||
* This test checks that there is a definition in the markdown file for every given link reference | ||
* The test does not verify the integrity of the referred definition, but purely for an existence of a definition | ||
*/ | ||
const describeRule = require('../test-utils/describe-rule') | ||
const describePage = require('../test-utils/describe-page') | ||
const getMarkdownAstNodesOfType = require('../utils/get-markdown-ast-nodes-of-type') | ||
const uniqueArray = require('../utils/unique-array') | ||
|
||
describe(`Validate link references`, () => { | ||
describeRule('Rules', ({ markdownAST }) => validateLinkReferences(markdownAST)) | ||
describePage('Rules', ({ markdownAST }) => validateLinkReferences(markdownAST)) | ||
}) | ||
|
||
function validateLinkReferences(markdownAST) { | ||
const linkReferences = uniqueArray( | ||
getMarkdownAstNodesOfType(markdownAST, 'linkReference').map(({ identifier }) => identifier) | ||
) | ||
if (!linkReferences || !linkReferences.length) { | ||
return | ||
} | ||
|
||
const definitions = uniqueArray( | ||
getMarkdownAstNodesOfType(markdownAST, 'definition').map(({ identifier }) => identifier) | ||
) | ||
|
||
test.each(linkReferences)('%s', linkRef => { | ||
const actual = definitions.includes(linkRef) | ||
const msg = `Link reference -> [${linkRef}] is not defined` | ||
expect(actual, msg).toBe(true) | ||
}) | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* This test checks every link that refers to a glossary term, uses the correct key to reference the glossary term/ definition | ||
*/ | ||
const describeRule = require('../test-utils/describe-rule') | ||
const describePage = require('../test-utils/describe-page') | ||
const isUrl = require('is-url') | ||
const getMarkdownAstNodesOfType = require('../utils/get-markdown-ast-nodes-of-type') | ||
const uniqueArray = require('../utils/unique-array') | ||
|
||
describe(`Validate glossary references`, () => { | ||
/** | ||
* Rules pages | ||
*/ | ||
describeRule('Rules', validateGlossaryReferences) | ||
|
||
/** | ||
* Other pages | ||
* -> in this case we only want to check for glossary terms referenced with glossary pages thyself, | ||
* hence ignoring other pages | ||
*/ | ||
describePage('Pages', (data, metaData) => { | ||
const { path } = data | ||
/** | ||
* Only run validation on glossary pages | ||
*/ | ||
if (!path.includes('/pages/glossary/')) { | ||
return | ||
} | ||
validateGlossaryReferences(data, metaData) | ||
}) | ||
}) | ||
|
||
function validateGlossaryReferences({ markdownAST }, { glossaryKeys = [] }) { | ||
/** | ||
* get all links | ||
* -> eg: [Alpha](https://....) or [Beta](#semantic-role) | ||
*/ | ||
const pageLinks = getMarkdownAstNodesOfType(markdownAST, 'link').map(({ url }) => url) | ||
/** | ||
* get all definition links | ||
* -> eg: [alpha]: https:// 'Link to something' or [beta]: #some-glossary 'Def to some glossary' | ||
*/ | ||
const definitionLinks = getMarkdownAstNodesOfType(markdownAST, 'definition').map(({ url }) => url) | ||
|
||
/** | ||
* get all links that are not a URL (eg: #semantic-role) | ||
* -> this test does not cover normal valid URL's (see test - 'link-is-outdated.js') | ||
*/ | ||
const links = uniqueArray([...pageLinks, ...definitionLinks].filter(link => !isUrl(link))).filter(link => { | ||
const [firstCharacter] = link.split('') | ||
return firstCharacter === '#' | ||
}) | ||
if (!links || !links.length) { | ||
return | ||
} | ||
|
||
test.each(links)('%s', link => { | ||
const key = link.substr(1) | ||
const actual = glossaryKeys.includes(key) | ||
const msg = `Glossary term - [#${key}] does not exist` | ||
expect(actual, msg).toBe(true) | ||
}) | ||
} |
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Oops, something went wrong.