aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/dictionary-validate.js2
-rw-r--r--test/lint/global-declarations.js4
-rw-r--r--test/test-database.js11
-rw-r--r--test/test-dictionary.js4
-rw-r--r--test/test-manifest.js4
-rw-r--r--test/yomichan-test.js39
6 files changed, 16 insertions, 48 deletions
diff --git a/test/dictionary-validate.js b/test/dictionary-validate.js
index 716e8df4..d01d74eb 100644
--- a/test/dictionary-validate.js
+++ b/test/dictionary-validate.js
@@ -17,7 +17,7 @@
const fs = require('fs');
const path = require('path');
-const {JSZip} = require('./yomichan-test');
+const {JSZip} = require('../dev/yomichan-util');
const {VM} = require('./yomichan-vm');
const vm = new VM();
diff --git a/test/lint/global-declarations.js b/test/lint/global-declarations.js
index 2fc9a5e2..355cb64a 100644
--- a/test/lint/global-declarations.js
+++ b/test/lint/global-declarations.js
@@ -19,7 +19,7 @@
const fs = require('fs');
const path = require('path');
const assert = require('assert');
-const {getAllFiles} = require('../yomichan-test');
+const {getAllFiles} = require('../../dev/yomichan-util');
function countOccurences(string, pattern) {
@@ -116,7 +116,7 @@ function main() {
const directory = path.resolve(__dirname, '..', '..', 'ext');
const pattern = /\.js$/;
const ignorePattern = /[\\/]ext[\\/]mixed[\\/]lib[\\/]/;
- const fileNames = getAllFiles(directory, (f) => pattern.test(f) && !ignorePattern.test(f));
+ const fileNames = getAllFiles(directory, null, (f) => pattern.test(f) && !ignorePattern.test(f));
for (const fileName of fileNames) {
if (!validateGlobals(fileName, fix)) {
process.exit(-1);
diff --git a/test/test-database.js b/test/test-database.js
index e8fb07b3..84fa8afb 100644
--- a/test/test-database.js
+++ b/test/test-database.js
@@ -19,7 +19,8 @@ const fs = require('fs');
const url = require('url');
const path = require('path');
const assert = require('assert');
-const yomichanTest = require('./yomichan-test');
+const {JSZip} = require('../dev/yomichan-util');
+const {createTestDictionaryArchive} = require('./yomichan-test');
const {VM} = require('./yomichan-vm');
require('fake-indexeddb/auto');
@@ -104,7 +105,7 @@ const vm = new VM({
fetch,
indexedDB: global.indexedDB,
IDBKeyRange: global.IDBKeyRange,
- JSZip: yomichanTest.JSZip,
+ JSZip,
addEventListener() {
// NOP
}
@@ -169,7 +170,7 @@ function clearDatabase(timeout) {
async function testDatabase1() {
// Load dictionary data
- const testDictionary = yomichanTest.createTestDictionaryArchive('valid-dictionary1');
+ const testDictionary = createTestDictionaryArchive('valid-dictionary1');
const testDictionarySource = await testDictionary.generateAsync({type: 'string'});
const testDictionaryIndex = JSON.parse(await testDictionary.files['index.json'].async('string'));
@@ -853,7 +854,7 @@ async function testFindTagForTitle1(database, title) {
async function testDatabase2() {
// Load dictionary data
- const testDictionary = yomichanTest.createTestDictionaryArchive('valid-dictionary1');
+ const testDictionary = createTestDictionaryArchive('valid-dictionary1');
const testDictionarySource = await testDictionary.generateAsync({type: 'string'});
const testDictionaryIndex = JSON.parse(await testDictionary.files['index.json'].async('string'));
@@ -910,7 +911,7 @@ async function testDatabase3() {
await dictionaryDatabase.prepare();
for (const invalidDictionary of invalidDictionaries) {
- const testDictionary = yomichanTest.createTestDictionaryArchive(invalidDictionary);
+ const testDictionary = createTestDictionaryArchive(invalidDictionary);
const testDictionarySource = await testDictionary.generateAsync({type: 'string'});
let error = null;
diff --git a/test/test-dictionary.js b/test/test-dictionary.js
index 27cc90df..2ca0c652 100644
--- a/test/test-dictionary.js
+++ b/test/test-dictionary.js
@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-const yomichanTest = require('./yomichan-test');
+const {createTestDictionaryArchive} = require('./yomichan-test');
const dictionaryValidate = require('./dictionary-validate');
@@ -33,7 +33,7 @@ async function main() {
const schemas = dictionaryValidate.getSchemas();
for (const {name, valid} of dictionaries) {
- const archive = yomichanTest.createTestDictionaryArchive(name);
+ const archive = createTestDictionaryArchive(name);
let error = null;
try {
diff --git a/test/test-manifest.js b/test/test-manifest.js
index cb86ce7b..07889105 100644
--- a/test/test-manifest.js
+++ b/test/test-manifest.js
@@ -18,7 +18,7 @@
const fs = require('fs');
const path = require('path');
const assert = require('assert');
-const {loadDefaultManifest, createManifestString} = require('../dev/build');
+const {getDefaultManifest, createManifestString} = require('../dev/yomichan-util');
function loadManifestString() {
@@ -28,7 +28,7 @@ function loadManifestString() {
function validateManifest() {
const manifest1 = loadManifestString();
- const manifest2 = createManifestString(loadDefaultManifest());
+ const manifest2 = createManifestString(getDefaultManifest());
assert.strictEqual(manifest1, manifest2, 'Manifest data does not match.');
}
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
};