Update location of test dictionary data

This commit is contained in:
toasted-nutbread 2020-02-22 12:58:33 -05:00
parent 4daf3435c2
commit a54f44122a
10 changed files with 7 additions and 14 deletions

View File

@ -121,7 +121,7 @@ async function clearDatabase() {
async function testDatabase1() { async function testDatabase1() {
// Load dictionary data // Load dictionary data
const testDictionary = yomichanTest.createTestDictionaryArchive(); const testDictionary = yomichanTest.createTestDictionaryArchive('valid-dictionary1');
const testDictionarySource = await testDictionary.generateAsync({type: 'string'}); const testDictionarySource = await testDictionary.generateAsync({type: 'string'});
const testDictionaryIndex = JSON.parse(await testDictionary.files['index.json'].async('string')); const testDictionaryIndex = JSON.parse(await testDictionary.files['index.json'].async('string'));
@ -800,7 +800,7 @@ async function testFindTagForTitle1(database, title) {
async function testDatabase2() { async function testDatabase2() {
// Load dictionary data // Load dictionary data
const testDictionary = yomichanTest.createTestDictionaryArchive(); const testDictionary = yomichanTest.createTestDictionaryArchive('valid-dictionary1');
const testDictionarySource = await testDictionary.generateAsync({type: 'string'}); const testDictionarySource = await testDictionary.generateAsync({type: 'string'});
const testDictionaryIndex = JSON.parse(await testDictionary.files['index.json'].async('string')); const testDictionaryIndex = JSON.parse(await testDictionary.files['index.json'].async('string'));

View File

@ -3,7 +3,7 @@ const dictionaryValidate = require('./dictionary-validate');
async function main() { async function main() {
const archive = yomichanTest.createTestDictionaryArchive(); const archive = yomichanTest.createTestDictionaryArchive('valid-dictionary1');
const schemas = dictionaryValidate.getSchemas(); const schemas = dictionaryValidate.getSchemas();
await dictionaryValidate.validateDictionary(archive, schemas); await dictionaryValidate.validateDictionary(archive, schemas);
} }

View File

@ -26,21 +26,14 @@ function getJSZip() {
return JSZip; return JSZip;
} }
function createTestDictionaryArchive(dictionaryName) { function createTestDictionaryArchive(dictionary, dictionaryName) {
const fileNames = [ const dictionaryDirectory = path.join(__dirname, 'data', 'dictionaries', dictionary);
'index.json', const fileNames = fs.readdirSync(dictionaryDirectory);
'tag_bank_1.json',
'tag_bank_2.json',
'term_bank_1.json',
'kanji_bank_1.json',
'term_meta_bank_1.json',
'kanji_meta_bank_1.json'
];
const archive = new (getJSZip())(); const archive = new (getJSZip())();
for (const fileName of fileNames) { for (const fileName of fileNames) {
const source = fs.readFileSync(path.join(__dirname, 'test-dictionary-data', fileName), {encoding: 'utf8'}); const source = fs.readFileSync(path.join(dictionaryDirectory, fileName), {encoding: 'utf8'});
const json = JSON.parse(source); const json = JSON.parse(source);
if (fileName === 'index.json' && typeof dictionaryName === 'string') { if (fileName === 'index.json' && typeof dictionaryName === 'string') {
json.title = dictionaryName; json.title = dictionaryName;