From 1e1f5095d238c74279b94d0ad823c522c8f72ef2 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Thu, 24 Feb 2022 07:03:06 +0800 Subject: [PATCH] test: update test config --- test/handle-text.spec.ts | 63 +++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/test/handle-text.spec.ts b/test/handle-text.spec.ts index 7ca3a0d48..d84be25e0 100644 --- a/test/handle-text.spec.ts +++ b/test/handle-text.spec.ts @@ -25,12 +25,26 @@ const files_git = [ 'messages/DiffBundle.properties', ] as const; -type ITestInput = [file: string, words: ITSValueOrArrayMaybeReadonly, notMatch?: boolean] | readonly [file: string, words: ITSValueOrArrayMaybeReadonly, notMatch?: boolean]; +type ITestConfig = [words: ITSValueOrArrayMaybeReadonly, notMatch?: boolean]; -const tests: ITSArrayListMaybeReadonly = [ +type ITestInput = [file: string, ...config: ITestConfig] | readonly [file: string, ...config: ITestConfig]; + +type ITestInput2 = + [file: ITSValueOrArrayMaybeReadonly, ...config: ITestConfig] + | readonly [file: string, ...config: ITestConfig]; + +const tests = _handleTestsSetting([ [`inspectionDescriptions/LeakableMapKey.html`, `解除安裝`], - ...files_git.map(file => [file, words_git, true] as const), -]; + [files_git, words_git, true], + [ + [ + `messages/JavaScriptBundle.properties`, + `messages/PhpBundle.properties`, + `messages/InspectionGadgetsBundle.properties`, + ], `縮小`, true, + ], + [`messages/ActionsBundle.properties`, `縮小`], +]); /** * 檢查原始來源的檔案(簡體) @@ -54,18 +68,48 @@ describe(`dev`, () => }) -function _initTests(tests: ITSArrayListMaybeReadonly, cwd: string) +function _handleTestsSetting(tests: ITSArrayListMaybeReadonly): Record +{ + // @ts-ignore + return tests.reduce((data: Record, [file, words, not]) => + { + + [file].flat() + .forEach(file => + { + data[file] ??= []; + + [words].flat() + .forEach(words => + { + data[file].push([words, not]) + }) + ; + + }) + ; + + return data + }, {} as Record); +} + +function _initTests(data: Record, cwd: string) { - tests.forEach((testInput) => _doTests(testInput, cwd)) + Object.keys(data) + .forEach((file) => + { + _doTests(file, data[file], cwd) + }) + ; } -function _doTests([file, words, not]: ITestInput, cwd: string) +function _doTests(file: string, configs: ITestConfig[], cwd: string) { test(file, async () => { let { actual } = await handleFile(file, cwd); - [words].flat().forEach(s => + configs.forEach(([s, not]) => { let t = expect(actual); @@ -75,10 +119,9 @@ function _doTests([file, words, not]: ITestInput, cwd: string) t = t.not } - t.toMatch(textToRegexp(s)); + t.toMatch(textToRegexp(s as string)); }); expect(actual).toMatchSnapshot(); }) } -