j40-cejst-2/client/src/intl/testIntlExtraction.js
Vim d1511287b8
Updates intl file with latest copy (#795)
* Extract 404 page copy to intl

* Move all copy to data copy folder and add tests

- Add test:intl-extraction script
- Fix certain defaultMessages not appearing
- update snapshot
2021-10-14 13:49:16 -07:00

29 lines
1.2 KiB
JavaScript

const enJson = require('./en.json');
const assert = require('assert');
// This file will allow us to test the en.json file and see if any entries are missing a default message.
// 1. Run intl:extract by npm run intl:extract
// 2. Navigate to client folder and in the command line
// 3. npm run test:intl-extraction
// 4. If there is no errors, then everything looks good!
// 5. If there are errors, set debug to true and re-run.
// Todo: Have this run anytime any copy changes occur
const debug = false;
if (debug) console.log('Total number of entries in en.json file: ', Object.entries(enJson).length);
let defaultCount = 0;
const noDefault = [];
Object.entries(enJson).forEach((msg) => msg[1].defaultMessage ? defaultCount++ : noDefault.push(msg[0]));
if (debug) console.log('Total number of defaultMessages in en.json file: ', defaultCount);
noDefault.forEach((msg) => console.log('Entries missing defaultMessage: ', msg));
let description = 0;
Object.entries(enJson).forEach((msg) => msg[1].description ? description++ : null);
if (debug) console.log('Total number of descriptions in en.json file: ', description);
// Assertions will fire on errors:
assert(Object.entries(enJson).length === defaultCount);
assert(Object.entries(enJson).length === description);