summaryrefslogtreecommitdiff
path: root/test/yomichan-test.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-08-09 21:00:37 -0400
committerGitHub <noreply@github.com>2020-08-09 21:00:37 -0400
commit7b1838a282f4ac5c50e0ea36122751c3454266aa (patch)
tree1fb73929e4ce6ae23842027f45d305335632c351 /test/yomichan-test.js
parent486d44f7197a2dedc5ea487345e598c668d47638 (diff)
Create dev utility class for some shared functionality (#724)
Diffstat (limited to 'test/yomichan-test.js')
-rw-r--r--test/yomichan-test.js39
1 files changed, 3 insertions, 36 deletions
diff --git a/test/yomichan-test.js b/test/yomichan-test.js
index b4f5ac7c..af1ea2e3 100644
--- a/test/yomichan-test.js
+++ b/test/yomichan-test.js
@@ -19,23 +19,12 @@ const fs = require('fs');
const path = require('path');
-let JSZip = null;
-
-
-function getJSZip() {
- if (JSZip === null) {
- process.noDeprecation = true; // Suppress a warning about JSZip
- JSZip = require(path.join(__dirname, '../ext/mixed/lib/jszip.min.js'));
- process.noDeprecation = false;
- }
- return JSZip;
-}
-
function createTestDictionaryArchive(dictionary, dictionaryName) {
const dictionaryDirectory = path.join(__dirname, 'data', 'dictionaries', dictionary);
const fileNames = fs.readdirSync(dictionaryDirectory);
- const archive = new (getJSZip())();
+ const {JSZip} = require('../dev/yomichan-util');
+ const archive = new JSZip();
for (const fileName of fileNames) {
if (/\.json$/.test(fileName)) {
@@ -54,29 +43,7 @@ function createTestDictionaryArchive(dictionary, dictionaryName) {
return archive;
}
-function getAllFiles(baseDirectory, predicate=null) {
- const results = [];
- const directories = [path.resolve(baseDirectory)];
- while (directories.length > 0) {
- const directory = directories.shift();
- for (const fileName of fs.readdirSync(directory)) {
- const fullFileName = path.resolve(directory, fileName);
- const stats = fs.statSync(fullFileName);
- if (stats.isFile()) {
- if (typeof predicate !== 'function' || predicate(fullFileName, directory, baseDirectory)) {
- results.push(fullFileName);
- }
- } else if (stats.isDirectory()) {
- directories.push(fullFileName);
- }
- }
- }
- return results;
-}
-
module.exports = {
- createTestDictionaryArchive,
- getAllFiles,
- get JSZip() { return getJSZip(); }
+ createTestDictionaryArchive
};