Skip to content

repo sync #15812

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 3 commits into from
Feb 24, 2022
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
11 changes: 7 additions & 4 deletions lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import getLinkData from './get-link-data.js'
import getDocumentType from './get-document-type.js'
import { union } from 'lodash-es'

// We're going to check a lot of pages' "ID" (the first part of
// the relativePath) against `productMap` to make sure it's valid.
// To avoid having to do `Object.keys(productMap).includes(id)`
// every single time, we turn it into a Set once.
const productMapKeysAsSet = new Set(Object.keys(productMap))

// Wrapper on renderContent() that caches the output depending on the
// `context` by extracting information about the page's current permalink
const _renderContentCache = new Map()
Expand Down Expand Up @@ -162,10 +168,7 @@ class Page {

// make sure the ID is valid
if (process.env.NODE_ENV !== 'test') {
assert(
Object.keys(productMap).includes(id),
`page ${this.fullPath} has an invalid product ID: ${id}`
)
assert(productMapKeysAsSet.has(id), `page ${this.fullPath} has an invalid product ID: ${id}`)
}

return id
Expand Down
20 changes: 12 additions & 8 deletions tests/content/site-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,19 @@ describe('siteData module (English)', () => {
expect(reusable.includes('任意のページの左上で')).toBe(true)
})

// TODO: re-enable once Janky flakyness is resolved
// Docs Engineering issue: 964
test.skip('backfills missing translated site data with English values', async () => {
test('backfills missing translated site data with English values', async () => {
const newFile = path.join(__dirname, '../../data/newfile.yml')
await fs.writeFile(newFile, 'newvalue: bar')
const data = await loadSiteData()
expect(get(data, 'en.site.data.newfile.newvalue')).toEqual('bar')
expect(get(data, 'ja.site.data.newfile.newvalue')).toEqual('bar')
await fs.unlink(newFile)
fs.writeFileSync(newFile, 'newvalue: bar')
try {
const data = loadSiteData()
expect(get(data, 'en.site.data.newfile.newvalue')).toEqual('bar')
expect(get(data, 'ja.site.data.newfile.newvalue')).toEqual('bar')
} finally {
// If an error is thrown above, it will still "bubble up"
// to the jest reporter, but we still always need to clean up
// the temporary file.
fs.unlinkSync(newFile)
}
})

test('all Liquid templating is valid', async () => {
Expand Down