diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-06-26 17:05:59 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-26 17:05:59 -0400 |
commit | 73caeac0fba13f83a810eab27dbc0aa49b3e9ef3 (patch) | |
tree | 1e82f97d87c3807397a8ffb82e4dcb14178465ca /test/test-anki-note-builder.js | |
parent | f9167c8fddbb757d314e1545c9dc788415a1fbf7 (diff) |
Test updates (#1763)
* Allow passing of globals to custom VMs
* Add _serializeError
* Expose document to VM
Diffstat (limited to 'test/test-anki-note-builder.js')
-rw-r--r-- | test/test-anki-note-builder.js | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/test/test-anki-note-builder.js b/test/test-anki-note-builder.js index aad12aba..d3ea0b6a 100644 --- a/test/test-anki-note-builder.js +++ b/test/test-anki-note-builder.js @@ -18,6 +18,7 @@ const fs = require('fs'); const path = require('path'); const assert = require('assert'); +const {JSDOM} = require('jsdom'); const {testMain} = require('../dev/util'); const {TranslatorVM} = require('../dev/translator-vm'); @@ -27,7 +28,10 @@ function clone(value) { } async function createVM() { - const vm = new TranslatorVM(); + const dom = new JSDOM(); + const {document} = dom.window; + + const vm = new TranslatorVM({document}); const dictionaryDirectory = path.join(__dirname, 'data', 'dictionaries', 'valid-dictionary1'); await vm.prepare(dictionaryDirectory, 'Test Dictionary 2'); @@ -68,6 +72,25 @@ async function createVM() { return this._serializeMulti(this._templateRenderer.renderMulti(items)); } + _serializeError(error) { + try { + if (typeof error === 'object' && error !== null) { + return { + name: error.name, + message: error.message, + stack: error.stack, + data: error.data + }; + } + } catch (e) { + // NOP + } + return { + value: error, + hasValue: true + }; + } + _serializeMulti(array) { for (let i = 0, ii = array.length; i < ii; ++i) { const value = array[i]; |