diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-03-04 21:24:39 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-04 21:24:39 -0500 |
commit | 421b60db0f6f132cbc5993488041846055a76d11 (patch) | |
tree | b2b28efc8ed7651c63ca2e728096ab79c6e6ab06 /test/test-database.js | |
parent | 6e47b4e241594d68384f62b1faa34c86f85addbf (diff) | |
parent | 7a51a0fbde445e346a83982dd6a16ce164521e26 (diff) |
Merge pull request #387 from toasted-nutbread/yomichan-vm
Abstract Yomichan extension script execution
Diffstat (limited to 'test/test-database.js')
-rw-r--r-- | test/test-database.js | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/test/test-database.js b/test/test-database.js index 9a24a393..833aa75d 100644 --- a/test/test-database.js +++ b/test/test-database.js @@ -21,6 +21,7 @@ const url = require('url'); const path = require('path'); const assert = require('assert'); const yomichanTest = require('./yomichan-test'); +const {VM} = require('./yomichan-vm'); require('fake-indexeddb/auto'); const chrome = { @@ -91,23 +92,24 @@ class XMLHttpRequest { } } -const {JsonSchema} = yomichanTest.requireScript('ext/bg/js/json-schema.js', ['JsonSchema']); -const {dictFieldSplit, dictTagSanitize} = yomichanTest.requireScript('ext/bg/js/dictionary.js', ['dictFieldSplit', 'dictTagSanitize']); -const {stringReverse} = yomichanTest.requireScript('ext/mixed/js/core.js', ['stringReverse'], {chrome}); -const {requestJson} = yomichanTest.requireScript('ext/bg/js/request.js', ['requestJson'], {XMLHttpRequest}); -const databaseGlobals = { +const vm = new VM({ chrome, - JsonSchema, - requestJson, - stringReverse, - dictFieldSplit, - dictTagSanitize, + XMLHttpRequest, indexedDB: global.indexedDB, + IDBKeyRange: global.IDBKeyRange, JSZip: yomichanTest.JSZip -}; -databaseGlobals.window = databaseGlobals; -const {Database} = yomichanTest.requireScript('ext/bg/js/database.js', ['Database'], databaseGlobals); +}); +vm.context.window = vm.context; + +vm.execute([ + 'bg/js/json-schema.js', + 'bg/js/dictionary.js', + 'mixed/js/core.js', + 'bg/js/request.js', + 'bg/js/database.js' +]); +const Database = vm.get('Database'); function countTermsWithExpression(terms, expression) { @@ -215,20 +217,20 @@ async function testDatabase1() { }, {prefixWildcardsSupported: true} ); - assert.deepStrictEqual(errors, []); - assert.deepStrictEqual(result, expectedSummary); + vm.assert.deepStrictEqual(errors, []); + vm.assert.deepStrictEqual(result, expectedSummary); assert.ok(progressEvent); // Get info summary const info = await database.getDictionaryInfo(); - assert.deepStrictEqual(info, [expectedSummary]); + vm.assert.deepStrictEqual(info, [expectedSummary]); // Get counts const counts = await database.getDictionaryCounts( info.map((v) => v.title), true ); - assert.deepStrictEqual(counts, { + vm.assert.deepStrictEqual(counts, { counts: [{kanji: 2, kanjiMeta: 2, terms: 32, termMeta: 3, tagMeta: 12}], total: {kanji: 2, kanjiMeta: 2, terms: 32, termMeta: 3, tagMeta: 12} }); @@ -251,10 +253,10 @@ async function testDatabase1() { async function testDatabaseEmpty1(database) { const info = await database.getDictionaryInfo(); - assert.deepStrictEqual(info, []); + vm.assert.deepStrictEqual(info, []); const counts = await database.getDictionaryCounts([], true); - assert.deepStrictEqual(counts, { + vm.assert.deepStrictEqual(counts, { counts: [], total: {kanji: 0, kanjiMeta: 0, terms: 0, termMeta: 0, tagMeta: 0} }); @@ -827,7 +829,7 @@ async function testFindTagForTitle1(database, title) { for (const {inputs, expectedResults} of data) { for (const {name} of inputs) { const result = await database.findTagForTitle(name, title); - assert.deepStrictEqual(result, expectedResults.value); + vm.assert.deepStrictEqual(result, expectedResults.value); } } } |