2020-09-27 15:10:11 +03:00
|
|
|
const config = require('../../lib/crowdin-config').read()
|
2020-11-09 22:07:04 +03:00
|
|
|
const loadPages = require('../../lib/pages')
|
|
|
|
const ignoredPagePaths = config.files[0].ignore
|
|
|
|
const ignoredDataPaths = config.files[2].ignore
|
2020-09-27 15:10:11 +03:00
|
|
|
|
|
|
|
describe('crowdin.yml config file', () => {
|
2020-11-09 22:07:04 +03:00
|
|
|
let pages
|
|
|
|
beforeAll(async (done) => {
|
|
|
|
pages = await loadPages()
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
|
2020-09-27 15:10:11 +03:00
|
|
|
test('has expected file stucture', async () => {
|
|
|
|
expect(config.files.length).toBe(3)
|
|
|
|
expect(config.files[0].source).toBe('/content/**/*.md')
|
|
|
|
expect(config.files[0].ignore).toContain('/content/README.md')
|
|
|
|
})
|
2020-11-09 22:07:04 +03:00
|
|
|
|
|
|
|
test('ignores all Early Access paths', async () => {
|
|
|
|
expect(ignoredPagePaths).toContain('content/early-access')
|
|
|
|
expect(ignoredDataPaths).toContain('data/early-access')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('ignores all hidden pages', async () => {
|
|
|
|
const hiddenPages = pages
|
|
|
|
.filter(page => page.hidden && page.languageCode === 'en')
|
|
|
|
.map(page => `/content/${page.relativePath}`)
|
|
|
|
const overlooked = hiddenPages.filter(page => !isIgnored(page, ignoredPagePaths))
|
|
|
|
const message = `Found some hidden pages that are not yet excluded from localization.
|
|
|
|
Please copy and paste the lines below into the \`ignore\` section of /crowdin.yml: \n\n"${overlooked.join('",\n"')}"`
|
|
|
|
|
|
|
|
// This may not be true anymore given the separation of Early Access docs
|
|
|
|
// expect(hiddenPages.length).toBeGreaterThan(0)
|
|
|
|
expect(ignoredPagePaths.length).toBeGreaterThan(0)
|
|
|
|
expect(overlooked, message).toHaveLength(0)
|
|
|
|
})
|
2020-09-27 15:10:11 +03:00
|
|
|
})
|
2020-11-09 22:07:04 +03:00
|
|
|
|
|
|
|
// file is ignored if its exact filename in the list,
|
|
|
|
// or if it's within an ignored directory
|
|
|
|
function isIgnored (filename, ignoredPagePaths) {
|
|
|
|
return ignoredPagePaths.some(ignoredPath => {
|
|
|
|
const isDirectory = !ignoredPath.endsWith('.md')
|
|
|
|
return ignoredPath === filename || (isDirectory && filename.startsWith(ignoredPath))
|
|
|
|
})
|
|
|
|
}
|