pinafore/tests/unit/test-intl.mjs
Nolan Lawson 16e66346d7
fix!: remove esm package, use native Node ES modules (#2064)
BREAKING CHANGE: Node v12.20+, v14.14+, or v16.0+ is required

* fix!: remove esm package, use native Node ES modules

* fix: fix some CJS imports
2021-07-04 20:19:04 -07:00

33 lines
1.1 KiB
JavaScript

// 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 */
import enIntl from '../../src/intl/en-US.js'
import globby from 'globby'
import path from 'path'
import { promisify } from 'util'
import fs from 'fs'
import assert from 'assert'
const readFile = promisify(fs.readFile)
const __dirname = path.dirname(new URL(import.meta.url).pathname)
describe('test-intl.js', () => {
it('has no unused intl strings', async () => {
const keys = Object.keys(enIntl)
const allSourceFilenames = (await globby([path.join(__dirname, '../../src/**/*.{js,html,json}')]))
.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)}`
)
}
})
})