2020-11-29 22:13:27 +00:00
|
|
|
// this test is to make sure I don't shoot myself in the foot and typo something and show the user
|
|
|
|
// a string like intl.nameOfThing rather than "Name of Thing"
|
|
|
|
|
|
|
|
/* global describe it */
|
|
|
|
|
2021-07-05 03:19:04 +00:00
|
|
|
import enIntl from '../../src/intl/en-US.js'
|
2022-11-18 17:32:31 +00:00
|
|
|
import { globby } from 'globby'
|
2020-11-29 22:13:27 +00:00
|
|
|
import path from 'path'
|
|
|
|
import { promisify } from 'util'
|
|
|
|
import fs from 'fs'
|
|
|
|
import assert from 'assert'
|
|
|
|
|
|
|
|
const readFile = promisify(fs.readFile)
|
2021-07-05 03:19:04 +00:00
|
|
|
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
2020-11-29 22:13:27 +00:00
|
|
|
|
|
|
|
describe('test-intl.js', () => {
|
|
|
|
it('has no unused intl strings', async () => {
|
|
|
|
const keys = Object.keys(enIntl)
|
|
|
|
|
2021-04-12 02:40:24 +00:00
|
|
|
const allSourceFilenames = (await globby([path.join(__dirname, '../../src/**/*.{js,html,json}')]))
|
2020-11-29 22:13:27 +00:00
|
|
|
.filter(file => !file.includes('/intl/'))
|
|
|
|
const allSourceFiles = await Promise.all(
|
|
|
|
allSourceFilenames.map(async name => ({ name, content: await readFile(name, 'utf8') }))
|
|
|
|
)
|
|
|
|
for (const key of keys) {
|
|
|
|
assert(
|
|
|
|
allSourceFiles.some(({ content }) => content.includes(`intl.${key}`)),
|
|
|
|
`Unused intl string: ${JSON.stringify(key)}`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|