summaryrefslogtreecommitdiff
path: root/test/yomichan-test.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-18 22:19:08 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-18 22:19:08 -0500
commit09ea007883360589d8b5aeb72ddb75eb126ce595 (patch)
treef9423783937e573c89a4eef0446ed585c74c3ec9 /test/yomichan-test.js
parent03886eb83310d051cc2a8d2ab0bb69412239ddd8 (diff)
Add test dictionary data
Diffstat (limited to 'test/yomichan-test.js')
-rw-r--r--test/yomichan-test.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/yomichan-test.js b/test/yomichan-test.js
index 602b8d78..dd4da919 100644
--- a/test/yomichan-test.js
+++ b/test/yomichan-test.js
@@ -26,8 +26,34 @@ function getJSZip() {
return JSZip;
}
+function createTestDictionaryArchive(dictionaryName) {
+ const fileNames = [
+ 'index.json',
+ '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())();
+
+ for (const fileName of fileNames) {
+ const source = fs.readFileSync(path.join(__dirname, 'test-dictionary-data', fileName), {encoding: 'utf8'});
+ const json = JSON.parse(source);
+ if (fileName === 'index.json' && typeof dictionaryName === 'string') {
+ json.title = dictionaryName;
+ }
+ archive.file(fileName, JSON.stringify(json, null, 0));
+ }
+
+ return archive;
+}
+
module.exports = {
requireScript,
+ createTestDictionaryArchive,
get JSZip() { return getJSZip(); }
};