summaryrefslogtreecommitdiff
path: root/test/yomichan-test.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2020-03-14 13:14:03 -0700
committerAlex Yatskov <alex@foosoft.net>2020-03-14 13:14:03 -0700
commitb77e2afe3a8ef9e96a53dd8ca97d8b913941244b (patch)
tree818a2f25169845a72b3424b7400b5b07f0f7cacf /test/yomichan-test.js
parentd32f4def0eeed1599857bc04c973337a2a13dd8b (diff)
parent98afe7adae80c6bc9de0c4b996e6f6cb0a5df49d (diff)
Merge branch 'master' into testing
Diffstat (limited to 'test/yomichan-test.js')
-rw-r--r--test/yomichan-test.js34
1 files changed, 21 insertions, 13 deletions
diff --git a/test/yomichan-test.js b/test/yomichan-test.js
index 78bfb9c6..5fa7730b 100644
--- a/test/yomichan-test.js
+++ b/test/yomichan-test.js
@@ -22,18 +22,6 @@ const path = require('path');
let JSZip = null;
-function requireScript(fileName, exportNames, variables) {
- const absoluteFileName = path.join(__dirname, '..', fileName);
- const source = fs.readFileSync(absoluteFileName, {encoding: 'utf8'});
- const exportNamesString = Array.isArray(exportNames) ? exportNames.join(',') : '';
- const variablesArgumentName = '__variables__';
- let variableString = '';
- if (typeof variables === 'object' && variables !== null) {
- variableString = Object.keys(variables).join(',');
- variableString = `const {${variableString}} = ${variablesArgumentName};`;
- }
- return Function(variablesArgumentName, `'use strict';${variableString}${source}\n;return {${exportNamesString}};`)(variables);
-}
function getJSZip() {
if (JSZip === null) {
@@ -62,9 +50,29 @@ 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 = {
- requireScript,
createTestDictionaryArchive,
+ getAllFiles,
get JSZip() { return getJSZip(); }
};