Add tests
This commit is contained in:
parent
ac603d54a3
commit
5f49f0fed2
BIN
test/data/dictionaries/valid-dictionary1/image.gif
Normal file
BIN
test/data/dictionaries/valid-dictionary1/image.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 45 B |
@ -30,5 +30,6 @@
|
||||
["打ち込む", "ぶちこむ", "tag1 tag2", "v5", 29, ["definition1a (打ち込む, ぶちこむ)", "definition1b (打ち込む, ぶちこむ)"], 6, "tag3 tag4 tag5"],
|
||||
["打ち込む", "ぶちこむ", "tag1 tag2", "v5", 30, ["definition2a (打ち込む, ぶちこむ)", "definition2b (打ち込む, ぶちこむ)"], 6, "tag3 tag4 tag5"],
|
||||
["打ち込む", "ぶちこむ", "tag1 tag2", "v5", 31, ["definition3a (打ち込む, ぶちこむ)", "definition3b (打ち込む, ぶちこむ)"], 6, "tag3 tag4 tag5"],
|
||||
["打ち込む", "ぶちこむ", "tag1 tag2", "v5", 32, ["definition4a (打ち込む, ぶちこむ)", "definition4b (打ち込む, ぶちこむ)"], 6, "tag3 tag4 tag5"]
|
||||
["打ち込む", "ぶちこむ", "tag1 tag2", "v5", 32, ["definition4a (打ち込む, ぶちこむ)", "definition4b (打ち込む, ぶちこむ)"], 6, "tag3 tag4 tag5"],
|
||||
["画像", "がぞう", "tag1 tag2", "", 33, ["definition1a (画像, がぞう)", {"type": "image", "path": "image.gif", "width": 350, "height": 350, "description": "An image", "pixelated": true}], 7, "tag3 tag4 tag5"]
|
||||
]
|
@ -92,9 +92,56 @@ class XMLHttpRequest {
|
||||
}
|
||||
}
|
||||
|
||||
class Image {
|
||||
constructor() {
|
||||
this._src = '';
|
||||
this._loadCallbacks = [];
|
||||
}
|
||||
|
||||
get src() {
|
||||
return this._src;
|
||||
}
|
||||
|
||||
set src(value) {
|
||||
this._src = value;
|
||||
this._delayTriggerLoad();
|
||||
}
|
||||
|
||||
get naturalWidth() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
get naturalHeight() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
addEventListener(eventName, callback) {
|
||||
if (eventName === 'load') {
|
||||
this._loadCallbacks.push(callback);
|
||||
}
|
||||
}
|
||||
|
||||
removeEventListener(eventName, callback) {
|
||||
if (eventName === 'load') {
|
||||
const index = this._loadCallbacks.indexOf(callback);
|
||||
if (index >= 0) {
|
||||
this._loadCallbacks.splice(index, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async _delayTriggerLoad() {
|
||||
await Promise.resolve();
|
||||
for (const callback of this._loadCallbacks) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const vm = new VM({
|
||||
chrome,
|
||||
Image,
|
||||
XMLHttpRequest,
|
||||
indexedDB: global.indexedDB,
|
||||
IDBKeyRange: global.IDBKeyRange,
|
||||
@ -106,6 +153,7 @@ vm.execute([
|
||||
'bg/js/json-schema.js',
|
||||
'bg/js/dictionary.js',
|
||||
'mixed/js/core.js',
|
||||
'bg/js/media-utility.js',
|
||||
'bg/js/request.js',
|
||||
'bg/js/dictionary-importer.js',
|
||||
'bg/js/database.js'
|
||||
@ -235,8 +283,8 @@ async function testDatabase1() {
|
||||
true
|
||||
);
|
||||
vm.assert.deepStrictEqual(counts, {
|
||||
counts: [{kanji: 2, kanjiMeta: 2, terms: 32, termMeta: 12, tagMeta: 14}],
|
||||
total: {kanji: 2, kanjiMeta: 2, terms: 32, termMeta: 12, tagMeta: 14}
|
||||
counts: [{kanji: 2, kanjiMeta: 2, terms: 33, termMeta: 12, tagMeta: 14}],
|
||||
total: {kanji: 2, kanjiMeta: 2, terms: 33, termMeta: 12, tagMeta: 14}
|
||||
});
|
||||
|
||||
// Test find* functions
|
||||
|
@ -38,12 +38,17 @@ function createTestDictionaryArchive(dictionary, dictionaryName) {
|
||||
const archive = new (getJSZip())();
|
||||
|
||||
for (const fileName of fileNames) {
|
||||
if (/\.json$/.test(fileName)) {
|
||||
const source = fs.readFileSync(path.join(dictionaryDirectory, 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));
|
||||
} else {
|
||||
const source = fs.readFileSync(path.join(dictionaryDirectory, fileName), {encoding: null});
|
||||
archive.file(fileName, source);
|
||||
}
|
||||
}
|
||||
|
||||
return archive;
|
||||
|
Loading…
Reference in New Issue
Block a user