diff options
-rw-r--r-- | test/test-anki-note-builder.js | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/test/test-anki-note-builder.js b/test/test-anki-note-builder.js index d3ea0b6a..d7045254 100644 --- a/test/test-anki-note-builder.js +++ b/test/test-anki-note-builder.js @@ -56,8 +56,9 @@ async function createVM() { const ankiNoteDataCreator = vm.ankiNoteDataCreator; class TemplateRendererProxy { constructor() { - const japaneseUtil = new JapaneseUtil(null); - this._templateRenderer = new TemplateRenderer(japaneseUtil); + this._preparePromise = null; + this._japaneseUtil = new JapaneseUtil(null); + this._templateRenderer = new TemplateRenderer(this._japaneseUtil); this._templateRenderer.registerDataType('ankiNote', { modifier: ({marker, commonData}) => ankiNoteDataCreator.create(marker, commonData), composeData: (marker, commonData) => ({marker, commonData}) @@ -65,11 +66,24 @@ async function createVM() { } async render(template, data, type) { - return this._templateRenderer.render(template, data, type); + await this._prepare(); + return await this._templateRenderer.render(template, data, type); } async renderMulti(items) { - return this._serializeMulti(this._templateRenderer.renderMulti(items)); + await this._prepare(); + return await this._serializeMulti(this._templateRenderer.renderMulti(items)); + } + + _prepare() { + if (this._preparePromise === null) { + this._preparePromise = this._prepareInternal(); + } + return this._preparePromise; + } + + async _prepareInternal() { + // Empty } _serializeError(error) { |