From dcb26a8ef5c62bf6acbf8130895c37f56e8a9d3f Mon Sep 17 00:00:00 2001 From: Cashew <52880648+Scrub1492@users.noreply.github.com> Date: Sun, 14 Jan 2024 10:51:00 +0700 Subject: more test updates (#510) * test updates * remove duplicate * fix indentation * fix --- test/options-util.test.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'test/options-util.test.js') diff --git a/test/options-util.test.js b/test/options-util.test.js index 41743b9f..a34cc93a 100644 --- a/test/options-util.test.js +++ b/test/options-util.test.js @@ -21,7 +21,7 @@ import fs from 'fs'; import {fileURLToPath} from 'node:url'; import path from 'path'; -import {expect, test, vi} from 'vitest'; +import {expect, test, describe, vi} from 'vitest'; import {OptionsUtil} from '../ext/js/data/options-util.js'; import {TemplatePatcher} from '../ext/js/templates/template-patcher.js'; import {chrome, fetch} from './mocks/common.js'; @@ -628,7 +628,7 @@ async function testUpdate() { /** */ async function testDefault() { - test('Default', async () => { + describe('Default', () => { /** @type {((options: import('options-util').IntermediateOptions) => void)[]} */ const data = [ (options) => options, @@ -640,27 +640,22 @@ async function testDefault() { } ]; - const optionsUtil = new OptionsUtil(); - await optionsUtil.prepare(); + test.each(data)('default-test-%#', async (modify) => { + const optionsUtil = new OptionsUtil(); + await optionsUtil.prepare(); - for (const modify of data) { const options = optionsUtil.getDefault(); - const optionsModified = structuredClone(options); modify(optionsModified); - const optionsUpdated = await optionsUtil.update(structuredClone(optionsModified)); expect(structuredClone(optionsUpdated)).toStrictEqual(structuredClone(options)); - } + }); }); } /** */ async function testFieldTemplatesUpdate() { - test('FieldTemplatesUpdate', async () => { - const optionsUtil = new OptionsUtil(); - await optionsUtil.prepare(); - + describe('FieldTemplatesUpdate', () => { const templatePatcher = new TemplatePatcher(); /** * @param {string} fileName @@ -1577,7 +1572,11 @@ async function testFieldTemplatesUpdate() { ]; const updatesPattern = /<<>>/g; - for (const {old, expected, oldVersion, newVersion} of data) { + + test.each(data)('field-templates-update-test-%#', async ({old, expected, oldVersion, newVersion}) => { + const optionsUtil = new OptionsUtil(); + await optionsUtil.prepare(); + const options = /** @type {import('core').SafeAny} */ (createOptionsTestData1()); options.profiles[0].options.anki.fieldTemplates = old; options.version = oldVersion; @@ -1587,7 +1586,7 @@ async function testFieldTemplatesUpdate() { const optionsUpdated = structuredClone(await optionsUtil.update(options, newVersion)); const fieldTemplatesActual = optionsUpdated.profiles[0].options.anki.fieldTemplates; expect(fieldTemplatesActual).toStrictEqual(expected2); - } + }); }); } -- cgit v1.2.3