Skip to content

Commit 90da848

Browse files
authored
Merge pull request #15812 from github/repo-sync
repo sync
2 parents f35b451 + 245f6b9 commit 90da848

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

lib/page.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ import getLinkData from './get-link-data.js'
1818
import getDocumentType from './get-document-type.js'
1919
import { union } from 'lodash-es'
2020

21+
// We're going to check a lot of pages' "ID" (the first part of
22+
// the relativePath) against `productMap` to make sure it's valid.
23+
// To avoid having to do `Object.keys(productMap).includes(id)`
24+
// every single time, we turn it into a Set once.
25+
const productMapKeysAsSet = new Set(Object.keys(productMap))
26+
2127
// Wrapper on renderContent() that caches the output depending on the
2228
// `context` by extracting information about the page's current permalink
2329
const _renderContentCache = new Map()
@@ -162,10 +168,7 @@ class Page {
162168

163169
// make sure the ID is valid
164170
if (process.env.NODE_ENV !== 'test') {
165-
assert(
166-
Object.keys(productMap).includes(id),
167-
`page ${this.fullPath} has an invalid product ID: ${id}`
168-
)
171+
assert(productMapKeysAsSet.has(id), `page ${this.fullPath} has an invalid product ID: ${id}`)
169172
}
170173

171174
return id

tests/content/site-data.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,19 @@ describe('siteData module (English)', () => {
4848
expect(reusable.includes('任意のページの左上で')).toBe(true)
4949
})
5050

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

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

0 commit comments

Comments
 (0)