summaryrefslogtreecommitdiff
path: root/test/fixtures
diff options
context:
space:
mode:
Diffstat (limited to 'test/fixtures')
-rw-r--r--test/fixtures/translator-test.js17
1 files changed, 11 insertions, 6 deletions
diff --git a/test/fixtures/translator-test.js b/test/fixtures/translator-test.js
index 5c024472..857e8a98 100644
--- a/test/fixtures/translator-test.js
+++ b/test/fixtures/translator-test.js
@@ -34,7 +34,7 @@ vi.stubGlobal('chrome', chrome);
/**
* @param {string} dictionaryDirectory
* @param {string} dictionaryName
- * @returns {Promise<Translator>}
+ * @returns {Promise<{translator: Translator, styles: string}>}
*/
export async function createTranslatorContext(dictionaryDirectory, dictionaryName) {
// Dictionary
@@ -46,36 +46,41 @@ export async function createTranslatorContext(dictionaryDirectory, dictionaryNam
const dictionaryDatabase = new DictionaryDatabase();
await dictionaryDatabase.prepare();
- const {errors} = await dictionaryImporter.importDictionary(
+ const {errors, result} = await dictionaryImporter.importDictionary(
dictionaryDatabase,
testDictionaryData,
{prefixWildcardsSupported: true},
);
expect(errors.length).toEqual(0);
+ expect(result).not.toBeNull();
+
+ const styles = result?.styles ?? '';
// Setup translator
const translator = new Translator(dictionaryDatabase);
translator.prepare();
- return translator;
+ return {translator, styles};
}
/**
* @param {string|undefined} htmlFilePath
* @param {string} dictionaryDirectory
* @param {string} dictionaryName
- * @returns {Promise<import('vitest').TestAPI<{window: import('jsdom').DOMWindow, translator: Translator}>>}
+ * @returns {Promise<import('vitest').TestAPI<{window: import('jsdom').DOMWindow, translator: Translator, styles: string}>>}
*/
export async function createTranslatorTest(htmlFilePath, dictionaryDirectory, dictionaryName) {
const test = createDomTest(htmlFilePath);
- const translator = await createTranslatorContext(dictionaryDirectory, dictionaryName);
- /** @type {import('vitest').TestAPI<{window: import('jsdom').DOMWindow, translator: Translator}>} */
+ const {translator, styles} = await createTranslatorContext(dictionaryDirectory, dictionaryName);
+ /** @type {import('vitest').TestAPI<{window: import('jsdom').DOMWindow, translator: Translator, styles: string}>} */
// eslint-disable-next-line sonarjs/prefer-immediate-return
const result = test.extend({
window: async ({window}, use) => { await use(window); },
// eslint-disable-next-line no-empty-pattern
translator: async ({}, use) => { await use(translator); },
+ // eslint-disable-next-line no-empty-pattern
+ styles: async ({}, use) => { await use(styles); },
});
return result;
}