1
1
mirror of https://github.com/primer/css.git synced 2024-09-11 16:36:07 +03:00

Writing some new docs tests

This commit is contained in:
Jon Rohan 2021-03-30 16:53:47 -07:00
parent a4a52c615a
commit ca0c85fae5
No known key found for this signature in database
GPG Key ID: B0BBE304A9A0AECB
12 changed files with 84 additions and 21 deletions

View File

@ -1,7 +0,0 @@
const fs = require('fs')
describe('css imports', () => {
it('all files are imported somewhere', () => {
})
})

View File

@ -1,18 +1,33 @@
const fs = require('fs')
const yaml = require('js-yaml')
const {getNavigationLinks, getContentFrontmatter} = require('./utils/docs')
let nav
let navLinks, contentFM
beforeAll(() => {
nav = yaml.load(fs.readFileSync('./docs/src/@primer/gatsby-theme-doctocat/nav.yml', 'utf8'))
beforeAll(async () => {
contentFM = await getContentFrontmatter()
navLinks = getNavigationLinks()
})
describe('frontmatter', () => {
it('page title matches link title', () => {
navLinks.forEach(link => {
const content = contentFM[link['url']]
expect(content).not.toBeNull()
expect(content['title']).toBe(link['title'])
})
})
it('contains path attribute', () => {
Object.values(contentFM).forEach( v => {
expect(v['path']).not.toBeNull()
})
})
})
describe('navigation', () => {
it('has a file for each nav item', () => {
navLinks.forEach(link => {
const content = contentFM[link['url']]
expect(content).not.toBeNull()
})
})
})

43
__tests__/utils/docs.js Normal file
View File

@ -0,0 +1,43 @@
const fs = require('fs')
const frontMatter = require('front-matter')
const yaml = require('js-yaml')
const globby = require('globby')
const {join} = require('path')
const docsPath = join(__dirname, '../../docs')
function collectNavLinks(links) {
let foundLinks = []
links.forEach(link => {
foundLinks.push({
title: link['title'],
url: link['url']
})
if(link['children']) {
foundLinks = foundLinks.concat(collectNavLinks(link['children']))
}
})
return foundLinks
}
function getNavigationLinks() {
const nav = yaml.load(fs.readFileSync(join(docsPath, './src/@primer/gatsby-theme-doctocat/nav.yml'), 'utf8'))
return collectNavLinks(nav)
}
async function getContentFrontmatter() {
let fm = {}
const paths = await globby(join(docsPath, './content/**/*.md*'))
paths.forEach(path => {
const contents = fs.readFileSync(path, 'utf8')
const fmContents = frontMatter(contents)
fm[path.replace(join(docsPath, './content'), '').replace(/(\/index)?\.mdx?/,'')] = fmContents['attributes']
})
return fm
}
module.exports = {
getContentFrontmatter,
getNavigationLinks
}

View File

@ -1,5 +1,5 @@
---
title: Marketing Buttons
title: Marketing buttons
path: components/marketing-buttons
status: New
source: 'https://github.com/primer/css/tree/main/src/marketing/buttons'

View File

@ -1,5 +1,5 @@
---
title: Table object (deprecated)
title: Table object
path: objects/table-object
status: Deprecated
source: 'https://github.com/primer/css/tree/main/src/table-object'

View File

@ -1,5 +1,5 @@
---
title: Marketing Filters
title: Marketing filters
path: utilities/marketing-filters
status: Stable
status_issue: 'https://github.com/github/design-systems/issues/302'

View File

@ -1,5 +1,5 @@
---
title: Marketing Layout
title: Marketing layout
sort_title: Layout Marketing
path: utilities/marketing-layout
status: Stable

View File

@ -1,5 +1,5 @@
---
title: Marketing Margin
title: Marketing margin
sort_title: Margin Marketing
path: utilities/marketing-margin
status: Stable

View File

@ -1,5 +1,5 @@
---
title: Marketing Padding
title: Marketing padding
sort_title: Padding Marketing
path: utilities/marketing-padding
status: Stable

View File

@ -1,5 +1,5 @@
---
title: Marketing Typography
title: Marketing typography
path: utilities/marketing-type
status: New
source: 'https://github.com/primer/css/tree/main/src/marketing/type'

View File

@ -55,6 +55,7 @@
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.23.1",
"filesize": "4.1.2",
"front-matter": "4.0.2",
"fs-extra": "^4.0.2",
"gh-pages": "^1.0.0",
"globby": "^6.1.0",
@ -84,6 +85,10 @@
"unist-util-stringify-position": "^2.0.1"
},
"jest": {
"testEnvironment": "node"
"testEnvironment": "node",
"testPathIgnorePatterns": [
"/node_modules/",
"/__tests__/utils/"
]
}
}

View File

@ -6815,6 +6815,13 @@ from2@^2.1.0:
inherits "^2.0.1"
readable-stream "^2.0.0"
front-matter@4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/front-matter/-/front-matter-4.0.2.tgz#b14e54dc745cfd7293484f3210d15ea4edd7f4d5"
integrity sha512-I8ZuJ/qG92NWX8i5x1Y8qyj3vizhXS31OxjKDu3LKP+7/qBgfIKValiZIEwoVoJKUHlhWtYrktkxV1XsX+pPlg==
dependencies:
js-yaml "^3.13.1"
fs-extra@^0.30.0:
version "0.30.0"
resolved "https://registry.npmjs.org/fs-extra/-/fs-extra-0.30.0.tgz"