-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Writing the first docs test and fixing the broken anchor link errors …
…it found (#1233) * writing the first docs test and fixing the errors it found * Creating a GitHub Action * Update docs.yml * fixes to the test runner and actions * removing jest from docs
- Loading branch information
Melissa McEwen
authored
Oct 7, 2020
1 parent
b21848b
commit 75ad503
Showing
8 changed files
with
3,104 additions
and
45 deletions.
There are no files selected for viewing
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,24 @@ | ||
name: Test Docs | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
env: | ||
node_version: 14 | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2.3.2 | ||
- name: Use Node.js ${{ env.node_version }} | ||
uses: actions/setup-node@v2.1.1 | ||
with: | ||
node-version: ${{ env.node_version }} | ||
- name: test | ||
run: | | ||
yarn --ignore-engines | ||
yarn test:docs |
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,25 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const cheerio = require('cheerio'); | ||
|
||
const $ = cheerio.load(fs.readFileSync(path.join('_site', 'index.html'))); | ||
|
||
function escapeRegExp(string) { | ||
return string.replace(/[.*+?^$%&{}()|[\]\\]/g, '\\$&'); // $& means the whole matched string | ||
} | ||
|
||
describe('each anchor link should have a corresponding anchor', () => { | ||
$('a').each(function (i, link) { | ||
const href = $(link).attr('href'); | ||
// link must include # and must not be an external link | ||
if (href.includes('#') && !href.includes('https://') && !href.includes('http://')) { | ||
// let's try to only get the #ID selector by removing anything else | ||
let anchor = escapeRegExp(href.slice(href.indexOf('#'))); | ||
|
||
test(`there is a link to ${href} so expect there to be an item with the ID ${anchor} on the page`, () => { | ||
expect($(anchor).length).toBe(1); | ||
}); | ||
} | ||
}); | ||
}); |
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
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.
75ad503
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: