aboutsummaryrefslogtreecommitdiff
path: root/test/fixtures/translator-test.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-12-20 00:47:15 -0500
committerGitHub <noreply@github.com>2023-12-20 05:47:15 +0000
commit8b943cc97fab890085448122e7c13dd035d0e238 (patch)
treea7a749a44771c6a82b1b72bb35cc0c81d57ddb54 /test/fixtures/translator-test.js
parentb13fbd47941fc20cf623871396e34a6dfe9b4dba (diff)
JSON validation (#394)
* Set up JSON testing * Add schema validation * Use parseJson * Finish types * Disambiguate ext/json-schema from node dependency with the same name * Add support for specifying the jsconfig file * Don't expose types * Update types * Use dictionary map type * Fix types * Fix AJV warnings * Move types * Move anb rename file * Move common mocks * Simplify types
Diffstat (limited to 'test/fixtures/translator-test.js')
-rw-r--r--test/fixtures/translator-test.js36
1 files changed, 3 insertions, 33 deletions
diff --git a/test/fixtures/translator-test.js b/test/fixtures/translator-test.js
index cb1a3ef5..3304c587 100644
--- a/test/fixtures/translator-test.js
+++ b/test/fixtures/translator-test.js
@@ -18,8 +18,8 @@
import {IDBKeyRange, indexedDB} from 'fake-indexeddb';
import {readFileSync} from 'fs';
-import {fileURLToPath, pathToFileURL} from 'node:url';
-import {dirname, join, resolve} from 'path';
+import {fileURLToPath} from 'node:url';
+import {dirname, join} from 'path';
import {expect, vi} from 'vitest';
import {parseJson} from '../../dev/json.js';
import {createDictionaryArchive} from '../../dev/util.js';
@@ -28,43 +28,13 @@ import {DictionaryDatabase} from '../../ext/js/language/dictionary-database.js';
import {DictionaryImporter} from '../../ext/js/language/dictionary-importer.js';
import {JapaneseUtil} from '../../ext/js/language/sandbox/japanese-util.js';
import {Translator} from '../../ext/js/language/translator.js';
+import {chrome, fetch} from '../mocks/common.js';
import {DictionaryImporterMediaLoader} from '../mocks/dictionary-importer-media-loader.js';
import {createDomTest} from './dom-test.js';
const extDir = join(dirname(fileURLToPath(import.meta.url)), '../../ext');
const deinflectionReasonsPath = join(extDir, 'data/deinflect.json');
-/** @type {import('dev/vm').PseudoChrome} */
-const chrome = {
- runtime: {
- getURL: (path) => {
- return pathToFileURL(join(extDir, path.replace(/^\//, ''))).href;
- }
- }
-};
-
-/**
- * @param {string} url
- * @returns {Promise<import('dev/vm').PseudoFetchResponse>}
- */
-async function fetch(url) {
- let filePath;
- try {
- filePath = fileURLToPath(url);
- } catch (e) {
- filePath = resolve(extDir, url.replace(/^[/\\]/, ''));
- }
- await Promise.resolve();
- const content = readFileSync(filePath, {encoding: null});
- return {
- ok: true,
- status: 200,
- statusText: 'OK',
- text: async () => content.toString('utf8'),
- json: async () => parseJson(content.toString('utf8'))
- };
-}
-
vi.stubGlobal('indexedDB', indexedDB);
vi.stubGlobal('IDBKeyRange', IDBKeyRange);
vi.stubGlobal('fetch', fetch);