зеркало из https://github.com/github/docs.git
Add tests for site-data-references within article metadata
This commit is contained in:
Родитель
5c6f5bb351
Коммит
a53255c8c9
|
@ -2,6 +2,7 @@ const { isEqual, get, uniqWith } = require('lodash')
|
|||
const loadSiteData = require('../../lib/site-data')
|
||||
const loadPages = require('../../lib/pages')
|
||||
const getDataReferences = require('../../lib/get-liquid-data-references')
|
||||
const frontmatter = require('@github-docs/frontmatter')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
|
@ -32,6 +33,25 @@ describe('data references', () => {
|
|||
expect(errors.length, JSON.stringify(errors, null, 2)).toBe(0)
|
||||
})
|
||||
|
||||
test('every data reference found in metadata of English content files is defined and has a value', () => {
|
||||
let errors = []
|
||||
expect(pages.length).toBeGreaterThan(0)
|
||||
|
||||
pages.forEach(page => {
|
||||
const metadataFile = path.join('content', page.relativePath)
|
||||
const fileContents = fs.readFileSync(path.join(__dirname, '../..', metadataFile))
|
||||
const { data: metadata } = frontmatter(fileContents, { filepath: page.fullPath })
|
||||
const metadataRefs = getDataReferences(JSON.stringify(metadata))
|
||||
metadataRefs.forEach(key => {
|
||||
const value = get(data.en, key)
|
||||
if (typeof value !== 'string') errors.push({ key, value, metadataFile })
|
||||
})
|
||||
})
|
||||
|
||||
errors = uniqWith(errors, isEqual) // remove duplicates
|
||||
expect(errors.length, JSON.stringify(errors, null, 2)).toBe(0)
|
||||
})
|
||||
|
||||
test('every data reference found in English reusable files is defined and has a value', () => {
|
||||
let errors = []
|
||||
const allReusables = data.en.site.data.reusables
|
||||
|
|
Загрузка…
Ссылка в новой задаче