-
Notifications
You must be signed in to change notification settings - Fork 61k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cope with possible translation drift (#24842)
* cope with possible translation drift * fix test * don't shallow clone * fix unit tests * update code comments * more code comment corrections * more code comment * feedbacked
- Loading branch information
Showing
5 changed files
with
218 additions
and
24 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import path from 'path' | ||
import { fileURLToPath } from 'url' | ||
|
||
import { expect } from '@jest/globals' | ||
|
||
import languages from '../../lib/languages.js' | ||
import Page from '../../lib/page.js' | ||
import { loadPageMap, correctTranslationOrphans } from '../../lib/page-data.js' | ||
const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
|
||
describe('loading page map with translation orphans', () => { | ||
test('inject missing translations from English', async () => { | ||
const basePath = path.join(__dirname, '../fixtures') | ||
const page = await Page.init({ | ||
relativePath: 'page-that-does-not-exist-in-translations-dir.md', | ||
basePath, | ||
languageCode: 'en', | ||
}) | ||
console.assert(page, 'page could not be loaded') | ||
|
||
const pageList = [page] | ||
const pageMap = await loadPageMap(await correctTranslationOrphans(pageList, basePath)) | ||
// It should make a copy of the English into each language | ||
expect(Object.keys(pageMap).length).toBe(Object.keys(languages).length) | ||
|
||
// +1 for the test just above, 2 tests per language. | ||
expect.assertions(1 + Object.keys(languages).length * 2) | ||
|
||
for (const languageCode of Object.keys(languages)) { | ||
for (const permalink of page.permalinks) { | ||
const translationHref = permalink.href.replace('/en', `/${languageCode}`) | ||
const translationPage = pageMap[translationHref] | ||
expect(translationPage).toBeTruthy() | ||
expect(translationPage.languageCode).toBe(languageCode) | ||
} | ||
} | ||
}) | ||
|
||
test('remove translation pages that were not in English', async () => { | ||
const basePath = path.join(__dirname, '../fixtures') | ||
const page = await Page.init({ | ||
relativePath: 'page-that-does-not-exist-in-translations-dir.md', | ||
basePath, | ||
languageCode: 'en', | ||
}) | ||
console.assert(page, 'page could not be loaded') | ||
const orphan = await Page.init({ | ||
relativePath: 'article-with-videos.md', | ||
basePath, | ||
languageCode: 'ja', | ||
}) | ||
console.assert(orphan, 'page could not be loaded') | ||
const orphanPermalinks = orphan.permalinks.map((p) => p.href) | ||
|
||
const pageList = await correctTranslationOrphans([page, orphan], basePath) | ||
const pageMap = await loadPageMap(pageList) | ||
expect(pageMap[orphanPermalinks[0]]).toBeFalsy() | ||
expect(Object.keys(pageMap).length).toBe(Object.keys(languages).length) | ||
}) | ||
}) |
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