diff options
-rw-r--r-- | dev/dictionary-validate.js | 5 | ||||
-rw-r--r-- | dev/generate-css-json.js | 15 | ||||
-rw-r--r-- | test/anki-note-builder.test.js | 6 | ||||
-rw-r--r-- | test/database.test.js | 5 | ||||
-rw-r--r-- | test/deinflector.test.js | 5 | ||||
-rw-r--r-- | test/dom-text-scanner.test.js | 4 |
6 files changed, 27 insertions, 13 deletions
diff --git a/dev/dictionary-validate.js b/dev/dictionary-validate.js index b3654e75..a6948bfe 100644 --- a/dev/dictionary-validate.js +++ b/dev/dictionary-validate.js @@ -20,14 +20,17 @@ import fs from 'fs'; import JSZip from 'jszip'; import path from 'path'; import {performance} from 'perf_hooks'; +import {fileURLToPath} from 'url'; import {createJsonSchema} from './schema-validate.js'; +const dirname = path.dirname(fileURLToPath(import.meta.url)); + /** * @param {string} relativeFileName * @returns {import('dev/dictionary-validate').Schema} */ function readSchema(relativeFileName) { - const fileName = path.join(__dirname, relativeFileName); + const fileName = path.join(dirname, relativeFileName); const source = fs.readFileSync(fileName, {encoding: 'utf8'}); return JSON.parse(source); } diff --git a/dev/generate-css-json.js b/dev/generate-css-json.js index 02e54530..e5d4d7f0 100644 --- a/dev/generate-css-json.js +++ b/dev/generate-css-json.js @@ -19,6 +19,9 @@ import css from 'css'; import fs from 'fs'; import path from 'path'; +import {fileURLToPath} from 'url'; + +const dirname = path.dirname(fileURLToPath(import.meta.url)); /** * @returns {{cssFile: string, overridesCssFile: string, outputPath: string}[]} @@ -26,14 +29,14 @@ import path from 'path'; export function getTargets() { return [ { - cssFile: path.join(__dirname, '..', 'ext/css/structured-content.css'), - overridesCssFile: path.join(__dirname, 'data/structured-content-overrides.css'), - outputPath: path.join(__dirname, '..', 'ext/data/structured-content-style.json') + cssFile: path.join(dirname, '..', 'ext/css/structured-content.css'), + overridesCssFile: path.join(dirname, 'data/structured-content-overrides.css'), + outputPath: path.join(dirname, '..', 'ext/data/structured-content-style.json') }, { - cssFile: path.join(__dirname, '..', 'ext/css/display-pronunciation.css'), - overridesCssFile: path.join(__dirname, 'data/display-pronunciation-overrides.css'), - outputPath: path.join(__dirname, '..', 'ext/data/pronunciation-style.json') + cssFile: path.join(dirname, '..', 'ext/css/display-pronunciation.css'), + overridesCssFile: path.join(dirname, 'data/display-pronunciation-overrides.css'), + outputPath: path.join(dirname, '..', 'ext/data/pronunciation-style.json') } ]; } diff --git a/test/anki-note-builder.test.js b/test/anki-note-builder.test.js index e4af7943..96dacab6 100644 --- a/test/anki-note-builder.test.js +++ b/test/anki-note-builder.test.js @@ -26,12 +26,14 @@ import {TranslatorVM} from '../dev/translator-vm.js'; import {AnkiNoteBuilder} from '../ext/js/data/anki-note-builder.js'; import {JapaneseUtil} from '../ext/js/language/sandbox/japanese-util.js'; +const dirname = path.dirname(fileURLToPath(import.meta.url)); + /** * @param {string} url2 * @returns {Promise<import('dev/vm').PseudoFetchResponse>} */ async function fetch(url2) { - const extDir = path.join(__dirname, '..', 'ext'); + const extDir = path.join(dirname, '..', 'ext'); let filePath; try { filePath = url.fileURLToPath(url2); @@ -51,8 +53,6 @@ async function fetch(url2) { vi.stubGlobal('fetch', fetch); vi.mock('../ext/js/templates/template-renderer-proxy.js'); -const dirname = path.dirname(fileURLToPath(import.meta.url)); - /** * @returns {Promise<TranslatorVM>} */ diff --git a/test/database.test.js b/test/database.test.js index ee818467..30854d55 100644 --- a/test/database.test.js +++ b/test/database.test.js @@ -18,12 +18,15 @@ import {IDBFactory, IDBKeyRange} from 'fake-indexeddb'; import path from 'path'; +import {fileURLToPath} from 'node:url'; import {beforeEach, describe, expect, test, vi} from 'vitest'; import {createDictionaryArchive} from '../dev/util.js'; import {DictionaryDatabase} from '../ext/js/language/dictionary-database.js'; import {DictionaryImporterMediaLoader} from '../ext/js/language/dictionary-importer-media-loader.js'; import {DictionaryImporter} from '../ext/js/language/dictionary-importer.js'; +const dirname = path.dirname(fileURLToPath(import.meta.url)); + vi.stubGlobal('IDBKeyRange', IDBKeyRange); vi.mock('../ext/js/language/dictionary-importer-media-loader.js'); @@ -34,7 +37,7 @@ vi.mock('../ext/js/language/dictionary-importer-media-loader.js'); * @returns {import('jszip')} */ function createTestDictionaryArchive(dictionary, dictionaryName) { - const dictionaryDirectory = path.join(__dirname, 'data', 'dictionaries', dictionary); + const dictionaryDirectory = path.join(dirname, 'data', 'dictionaries', dictionary); return createDictionaryArchive(dictionaryDirectory, dictionaryName); } diff --git a/test/deinflector.test.js b/test/deinflector.test.js index 77184799..a69f8e56 100644 --- a/test/deinflector.test.js +++ b/test/deinflector.test.js @@ -20,6 +20,9 @@ import fs from 'fs'; import path from 'path'; import {describe, expect, test} from 'vitest'; import {Deinflector} from '../ext/js/language/deinflector.js'; +import {fileURLToPath} from 'node:url'; + +const dirname = path.dirname(fileURLToPath(import.meta.url)); /** * @param {Deinflector} deinflector @@ -924,7 +927,7 @@ function testDeinflections() { } ]; - const deinflectionReasons = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'ext', 'data/deinflect.json'), {encoding: 'utf8'})); + const deinflectionReasons = JSON.parse(fs.readFileSync(path.join(dirname, '..', 'ext', 'data/deinflect.json'), {encoding: 'utf8'})); const deinflector = new Deinflector(deinflectionReasons); describe('deinflections', () => { diff --git a/test/dom-text-scanner.test.js b/test/dom-text-scanner.test.js index 6d0c047b..30aec33e 100644 --- a/test/dom-text-scanner.test.js +++ b/test/dom-text-scanner.test.js @@ -19,9 +19,11 @@ import fs from 'fs'; import {JSDOM} from 'jsdom'; import path from 'path'; +import {fileURLToPath} from 'node:url'; import {expect, test} from 'vitest'; import {DOMTextScanner} from '../ext/js/dom/dom-text-scanner.js'; +const dirname = path.dirname(fileURLToPath(import.meta.url)); /** * @param {string} fileName @@ -188,7 +190,7 @@ async function testDomTextScanner(dom) { /** */ async function testDocument1() { - const dom = createJSDOM(path.join(__dirname, 'data', 'html', 'test-dom-text-scanner.html')); + const dom = createJSDOM(path.join(dirname, 'data', 'html', 'test-dom-text-scanner.html')); const window = dom.window; try { window.getComputedStyle = createAbsoluteGetComputedStyle(window); |