diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2023-12-19 00:33:38 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-19 05:33:38 +0000 |
commit | 1ced9aafc00c10992bab8bd3f1b6b1397f05b7b9 (patch) | |
tree | 305bb2b3bfc7fc3b051ee1cd3d1c35f442af0de4 /test/translator.test.js | |
parent | 5f96276fda93dcad39f2165fd3c8d890aa5f9be5 (diff) |
Make JSON.parse usage safer (#373)
* Make JSON.parse usage safer
* Fix any type
* Add readResponseJson
* Use readResponseJson
* Additional updates
* Rename files
* Add types
Diffstat (limited to 'test/translator.test.js')
-rw-r--r-- | test/translator.test.js | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/test/translator.test.js b/test/translator.test.js index 59887d7e..42a9076e 100644 --- a/test/translator.test.js +++ b/test/translator.test.js @@ -20,6 +20,7 @@ import {readFileSync} from 'fs'; import {fileURLToPath} from 'node:url'; import path from 'path'; import {describe} from 'vitest'; +import {parseJson} from '../dev/json.js'; import {createTranslatorTest} from './fixtures/translator-test.js'; import {createTestAnkiNoteData} from './utilities/anki.js'; import {createFindOptions} from './utilities/translator.js'; @@ -27,14 +28,16 @@ import {createFindOptions} from './utilities/translator.js'; const dirname = path.dirname(fileURLToPath(import.meta.url)); const testInputsFilePath = path.join(dirname, 'data/translator-test-inputs.json'); -/** @type {import('test/anki-note-builder').TranslatorTestInputs} */ -const {optionsPresets, tests} = JSON.parse(readFileSync(testInputsFilePath, {encoding: 'utf8'})); +/** @type {import('test/translator').TranslatorTestInputs} */ +const {optionsPresets, tests} = parseJson(readFileSync(testInputsFilePath, {encoding: 'utf8'})); const testResults1FilePath = path.join(dirname, 'data/translator-test-results.json'); -const expectedResults1 = JSON.parse(readFileSync(testResults1FilePath, {encoding: 'utf8'})); +/** @type {import('test/translator').TranslatorTestResults} */ +const expectedResults1 = parseJson(readFileSync(testResults1FilePath, {encoding: 'utf8'})); const testResults2FilePath = path.join(dirname, 'data/translator-test-results-note-data1.json'); -const expectedResults2 = JSON.parse(readFileSync(testResults2FilePath, {encoding: 'utf8'})); +/** @type {import('test/translator').TranslatorTestNoteDataResults} */ +const expectedResults2 = parseJson(readFileSync(testResults2FilePath, {encoding: 'utf8'})); const dictionaryName = 'Test Dictionary 2'; const test = await createTranslatorTest(void 0, path.join(dirname, 'data/dictionaries/valid-dictionary1'), dictionaryName); |