From efde65279403435c467957f4e20f4c301cda5201 Mon Sep 17 00:00:00 2001 From: Zhengqbbb <1074059947@qq.com> Date: Fri, 29 Apr 2022 01:10:27 +0800 Subject: [PATCH 01/10] feat(plugin-inquirer): add fuzzy match str util funtion link #22 --- .../plugin-inquirer/src/shared/utils/fuzzy.ts | 139 ++++-------------- 1 file changed, 29 insertions(+), 110 deletions(-) diff --git a/packages/@cz-git/plugin-inquirer/src/shared/utils/fuzzy.ts b/packages/@cz-git/plugin-inquirer/src/shared/utils/fuzzy.ts index 6f1baee05..8d723daa3 100644 --- a/packages/@cz-git/plugin-inquirer/src/shared/utils/fuzzy.ts +++ b/packages/@cz-git/plugin-inquirer/src/shared/utils/fuzzy.ts @@ -1,127 +1,46 @@ /** - * Powered by Fuzzy - * https://github.com/myork/fuzzy - * - * Copyright (c) 2012 Matt York - * Licensed under the MIT license. - * - * @description: A standalone fuzzy search / fuzzy filter. provide inquirer usage + * @description: provide list and checkBox fuzzy search * @author: @Zhengqbbb (zhengqbbb@gmail.com) * @license: MIT */ -import { FilterFucType, MatchOptions, MatchResult } from "../types"; - /** - * @description: If `pattern` matches `inputString`, wrap each matching character in `opts.pre` - * and `opts.post`. If no match, return null. - * @param {string} pattern inputString - * @param {string} str targetString + * @description: inputString match targetString return match score + * @param {string} input input string + * @param {string} target target string + * @param {boolean} caseSensitive isCaseSensitive, default: false + * @return {number | null} match score. if not match return null */ export const fuzzyMatch = ( - pattern: string, - str: string, - opts?: MatchOptions -): MatchResult | null => { - opts = opts || {}; - const result = []; - const len = str.length; - // prefix - const pre = opts.pre || ""; - // suffix - const post = opts.post || ""; - // String to compare against. This might be a lowercase version of the - // raw string - const compareString = (opts.caseSensitive && str) || str.toLowerCase(); - let patternIdx = 0, + input: string, + target: string, + caseSensitive?: boolean +): number | null => { + if (typeof input !== "string" || typeof target !== "string") return null; + const matchResult = []; + const len = target.length; + const shimTarget = (caseSensitive && target) || target.toLowerCase(); + input = (caseSensitive && input) || input.toLowerCase(); + let inputIndex = 0, totalScore = 0, - currScore = 0, - ch; - - pattern = (opts.caseSensitive && pattern) || pattern.toLowerCase(); - - // For each character in the string, either add it to the result - // or wrap in template if it's the next string in the pattern + currentScore = 0, + currentChar; for (let idx = 0; idx < len; idx++) { - ch = str[idx]; - if (compareString[idx] === pattern[patternIdx]) { - ch = pre + ch + post; - patternIdx += 1; - - // consecutive characters should increase the score more than linearly - currScore += 1 + currScore; + currentChar = input[idx]; + if (shimTarget[idx] === input[inputIndex]) { + // consecutive matches will score higher + inputIndex += 1; + currentScore += 1 + currentScore; } else { - currScore = 0; + currentScore = 0; } - totalScore += currScore; - result[result.length] = ch; + totalScore += currentScore; + matchResult[matchResult.length] = currentChar; } - - // return rendered string if we have a match for every char - if (patternIdx === pattern.length) { - // if the string is an exact match with pattern, totalScore should be maxed - totalScore = compareString === pattern ? Infinity : totalScore; - return { rendered: result.join(""), score: totalScore }; + if (inputIndex === input.length) { + totalScore = shimTarget === input ? Infinity : totalScore; + return totalScore; } return null; }; - -/** - * @description: Does `pattern` fuzzy match `inputString`? - * @param {string} pattern inputString - * @param {string} str targetString - * @return {boolean} isMatch - */ -export const fuzzyTest = (pattern: string, str: string): boolean => { - return fuzzyMatch(pattern, str) !== null; -}; - -/** - * @description: The normal entry point. Filters `arr` for matches against `pattern`. - * @param {*} pattern inputString - * @param {*} arr targetArray - * @param {*} opts FilterOptions - */ -export const fuzzyFilter: FilterFucType = (pattern, arr, opts?) => { - if (!arr || arr.length === 0) { - return []; - } - if (typeof pattern !== "string") { - return arr; - } - opts = opts || {}; - return arr - .reduce(function (prev, element, idx) { - let str = element; - if (opts?.extract) { - str = opts?.extract(element); - } - const rendered = fuzzyMatch(pattern, str, opts); - if (rendered != null) { - prev[prev.length] = { - string: rendered.rendered, - score: rendered.score, - index: idx, - original: element - }; - } - return prev; - }, []) - .sort(function (a: any, b: any) { - const compare = b.score - a.score; - if (compare) return compare; - return a.index - b.index; - }); -}; - -/** - * @description: Return all elements of `array` that have a fuzzy match against `pattern`. - * @param {string} pattern inputString - * @param {Array} array targetArray - */ -export const fuzzySimpleFilter = (pattern: string, array: string[]): string[] => { - return array.filter(function (str) { - return fuzzyTest(pattern, str); - }); -}; From a27f856d23fbc9d1422f5876a50424ae9222f2eb Mon Sep 17 00:00:00 2001 From: Zhengqbbb <1074059947@qq.com> Date: Fri, 29 Apr 2022 01:11:14 +0800 Subject: [PATCH 02/10] test(plugin-inquirer): add test for fuzzy match str util funtion link #22 --- .../plugin-inquirer/__tests__/utils.test.ts | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 packages/@cz-git/plugin-inquirer/__tests__/utils.test.ts diff --git a/packages/@cz-git/plugin-inquirer/__tests__/utils.test.ts b/packages/@cz-git/plugin-inquirer/__tests__/utils.test.ts new file mode 100644 index 000000000..2ffb9efa0 --- /dev/null +++ b/packages/@cz-git/plugin-inquirer/__tests__/utils.test.ts @@ -0,0 +1,48 @@ +import { test, expect, describe } from "vitest"; +import { fuzzyMatch } from "../src"; + +/** + * @description: fuzzyMatch Test + */ +describe("fuzzyMatch", () => { + test("function should be check param fit", () => { + expect(fuzzyMatch(null, null)).toBe(null); + expect(fuzzyMatch(undefined, null)).toBe(null); + expect(fuzzyMatch(undefined, undefined)).toBe(null); + // @ts-ignore + expect(fuzzyMatch([], [])).toBe(null); + // @ts-ignore + expect(fuzzyMatch({}, {})).toBe(null); + }); + + test("match char should be return right score", () => { + expect(fuzzyMatch("a", "Apple")).toEqual(1); + expect(fuzzyMatch("ae", "Apple")).toEqual(2); + expect(fuzzyMatch("ap", "Apple")).toEqual(4); + expect(fuzzyMatch("app", "Apple")).toEqual(11); + expect(fuzzyMatch("ban", "banana")).toEqual(11); + expect(fuzzyMatch("bna", "banana")).toEqual(5); + expect(fuzzyMatch("baaa", "banana")).toEqual(6); + }); + + test("consistent case should be return same score", () => { + expect(fuzzyMatch("sz", "shenzhen")).toEqual(fuzzyMatch("sz", "ShenZhen")); + }); + + test("case sensitive should be return diff score", () => { + expect(fuzzyMatch("sz", "shenzhen", true)).toEqual(2); + expect(fuzzyMatch("sz", "ShenZhen", true)).toEqual(null); + }); + + test("not match char should be return null", () => { + expect(fuzzyMatch("k", "banana")).toEqual(null); + expect(fuzzyMatch("kkkkkk", "banana")).toEqual(null); + expect(fuzzyMatch("bne", "banana")).toEqual(null); + expect(fuzzyMatch("bnae", "banana")).toEqual(null); + }); + + test("all match should be return Infinity", () => { + expect(fuzzyMatch("apple", "Apple")).toEqual(Infinity); + expect(fuzzyMatch("Apple", "Apple")).toEqual(Infinity); + }); +}); From 51393a8ab70f929b915edf1a7f859f6d7a89e0f4 Mon Sep 17 00:00:00 2001 From: Zhengqbbb <1074059947@qq.com> Date: Fri, 29 Apr 2022 01:12:10 +0800 Subject: [PATCH 03/10] style(cz-git): update code format --- packages/cz-git/src/shared/utils/util.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/cz-git/src/shared/utils/util.ts b/packages/cz-git/src/shared/utils/util.ts index bf76b6065..c8702c82a 100644 --- a/packages/cz-git/src/shared/utils/util.ts +++ b/packages/cz-git/src/shared/utils/util.ts @@ -95,12 +95,15 @@ export const handleCustomTemplate = ( ...target.slice(targetIndex + 1) ]; } + // prettier-ignore switch (align) { case "top": - result = result.concat(target); + result = result + .concat(target); break; case "bottom": - result = target.concat(result.reverse()); + result = target + .concat(result.reverse()); break; case "top-bottom": result = [{ name: emptyAlias, value: false }, new cz.Separator()] @@ -113,7 +116,8 @@ export const handleCustomTemplate = ( .concat([new cz.Separator(), { name: emptyAlias, value: false }]); break; default: - result = result.concat(target); + result = result + .concat(target); break; } return filterCustomEmptyByOption(result, allowCustom, allowEmpty); From c9313edfd6071f4386ba19397fef118eea6bc692 Mon Sep 17 00:00:00 2001 From: Zhengqbbb <1074059947@qq.com> Date: Sat, 30 Apr 2022 14:58:44 +0800 Subject: [PATCH 04/10] chore: update config --- tsconfig.base.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tsconfig.base.json b/tsconfig.base.json index 935e0a51a..a49d200ef 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1,23 +1,23 @@ { "compilerOptions": { + "target": "es2017", + "module": "esnext", + "moduleResolution": "node", + "lib": ["esnext"], + "types": ["node", "vitest/globals"], + "removeComments": false, + "sourceMap": true, "composite": true, "esModuleInterop": true, "declaration": true, "downlevelIteration": true, "forceConsistentCasingInFileNames": true, - "types": ["node", "vitest/globals"], - "lib": ["esnext"], - "module": "CommonJS", - "moduleResolution": "node", "noEmitOnError": true, "noUnusedParameters": true, "noUnusedLocals": true, "noImplicitAny": true, - "removeComments": false, "resolveJsonModule": true, "skipLibCheck": true, - "sourceMap": true, "strict": true, - "target": "es5" } } From 9991aa699af003404347e20c8d8e9a7669249a17 Mon Sep 17 00:00:00 2001 From: Zhengqbbb <1074059947@qq.com> Date: Sat, 30 Apr 2022 15:01:36 +0800 Subject: [PATCH 05/10] ci: :wrench: add check for node v18 --- .github/workflows/nodejs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 09c8b1f08..3d3731bdb 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] - node: ['14', '16'] + node: ['14', '16', '18'] runs-on: ${{ matrix.os }} From d78ce33c32811be6ff54160537d2b4e4e85a0f84 Mon Sep 17 00:00:00 2001 From: Zhengqbbb <1074059947@qq.com> Date: Sat, 30 Apr 2022 15:05:47 +0800 Subject: [PATCH 06/10] style: update code format --- .../@cz-git/plugin-inquirer/src/list/index.ts | 1 - .../plugin-inquirer/src/shared/types/fuzzy.ts | 41 ------------------- 2 files changed, 42 deletions(-) delete mode 100644 packages/@cz-git/plugin-inquirer/src/shared/types/fuzzy.ts diff --git a/packages/@cz-git/plugin-inquirer/src/list/index.ts b/packages/@cz-git/plugin-inquirer/src/list/index.ts index cb89eb731..a2202c8ad 100644 --- a/packages/@cz-git/plugin-inquirer/src/list/index.ts +++ b/packages/@cz-git/plugin-inquirer/src/list/index.ts @@ -4,5 +4,4 @@ * @license: MIT */ -console.log("hello world"); export const hello = "hello world"; diff --git a/packages/@cz-git/plugin-inquirer/src/shared/types/fuzzy.ts b/packages/@cz-git/plugin-inquirer/src/shared/types/fuzzy.ts deleted file mode 100644 index 4f39b3731..000000000 --- a/packages/@cz-git/plugin-inquirer/src/shared/types/fuzzy.ts +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Powered by Fuzzy - * https://github.com/myork/fuzzy - * - * Copyright (c) 2012 Matt York - * Licensed under the MIT license. - * - * @description: A standalone fuzzy search / fuzzy filter. provide inquirer usage - * @author: @Zhengqbbb (zhengqbbb@gmail.com) - * @license: MIT - */ - -export interface MatchOptions { - pre?: string; - post?: string; - caseSensitive?: boolean; -} - -export interface MatchResult { - rendered: string; - score: number; -} - -export interface FilterOptions { - pre?: string; - post?: string; - extract?(input: T): string; -} - -export interface FilterResult { - string: string; - score: number; - index: number; - original: T; -} - -export type FilterFucType = ( - pattern: string, - arr: T[], - opts?: FilterOptions -) => FilterResult[]; From 83f773ed7561494d8f98fcb2cc316146ae90a29a Mon Sep 17 00:00:00 2001 From: Zhengqbbb <1074059947@qq.com> Date: Sat, 30 Apr 2022 15:08:04 +0800 Subject: [PATCH 07/10] feat(plugin-inquirer): add fuzzyFilter util Fuc provide cz-git link #22 --- .../plugin-inquirer/src/shared/types/index.ts | 2 +- .../plugin-inquirer/src/shared/types/util.ts | 7 ++++ .../plugin-inquirer/src/shared/utils/fuzzy.ts | 42 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 packages/@cz-git/plugin-inquirer/src/shared/types/util.ts diff --git a/packages/@cz-git/plugin-inquirer/src/shared/types/index.ts b/packages/@cz-git/plugin-inquirer/src/shared/types/index.ts index c2fbd7637..1392fb6b3 100644 --- a/packages/@cz-git/plugin-inquirer/src/shared/types/index.ts +++ b/packages/@cz-git/plugin-inquirer/src/shared/types/index.ts @@ -1,2 +1,2 @@ -export * from "./fuzzy"; +export * from "./util"; export * from "./checkbox"; diff --git a/packages/@cz-git/plugin-inquirer/src/shared/types/util.ts b/packages/@cz-git/plugin-inquirer/src/shared/types/util.ts new file mode 100644 index 000000000..be2abf6b1 --- /dev/null +++ b/packages/@cz-git/plugin-inquirer/src/shared/types/util.ts @@ -0,0 +1,7 @@ +export interface FilterArrayItemType { + value: string; + name: string; + emoji?: string; + index?: number; + score?: number; +} diff --git a/packages/@cz-git/plugin-inquirer/src/shared/utils/fuzzy.ts b/packages/@cz-git/plugin-inquirer/src/shared/utils/fuzzy.ts index 8d723daa3..b7c2a167d 100644 --- a/packages/@cz-git/plugin-inquirer/src/shared/utils/fuzzy.ts +++ b/packages/@cz-git/plugin-inquirer/src/shared/utils/fuzzy.ts @@ -4,6 +4,8 @@ * @license: MIT */ +import type { FilterArrayItemType } from "../types"; + /** * @description: inputString match targetString return match score * @param {string} input input string @@ -44,3 +46,43 @@ export const fuzzyMatch = ( return null; }; + +/** + * @description: Array fuzzy filter + * @param {string} input input string + * @param {Array} arr target Array + * @return {Array} filtered array + */ +export const fuzzyFilter = ( + input: string, + arr: Array, + targetKey: "name" | "value" = "name" +): Array => { + if (!arr || !Array.isArray(arr) || arr.length === 0) { + return []; + } else if (typeof input !== "string" || input === "") { + return arr; + } + + return arr + .reduce((preVal: Array, curItem: FilterArrayItemType, index) => { + if (!curItem || !curItem[targetKey]) return preVal; + const score = fuzzyMatch(input, curItem[targetKey]); + if (score !== null) { + preVal.push({ + score, + index, + ...curItem + }); + } + return preVal; + }, []) + .sort((a: any, b: any) => { + const compare = b.score - a.score; + if (compare) { + return compare; + } else { + return a.index - b.index; + } + }); +}; From f1f5784d0f8f6f3a226109e7129e1d021570991a Mon Sep 17 00:00:00 2001 From: Zhengqbbb <1074059947@qq.com> Date: Sat, 30 Apr 2022 15:08:41 +0800 Subject: [PATCH 08/10] test(plugin-inquirer): add add fuzzyFilter util Fuc testcase link #22 --- .../plugin-inquirer/__tests__/utils.test.ts | 66 ++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/packages/@cz-git/plugin-inquirer/__tests__/utils.test.ts b/packages/@cz-git/plugin-inquirer/__tests__/utils.test.ts index 2ffb9efa0..4fe4281ba 100644 --- a/packages/@cz-git/plugin-inquirer/__tests__/utils.test.ts +++ b/packages/@cz-git/plugin-inquirer/__tests__/utils.test.ts @@ -1,5 +1,5 @@ import { test, expect, describe } from "vitest"; -import { fuzzyMatch } from "../src"; +import { fuzzyFilter, fuzzyMatch } from "../src"; /** * @description: fuzzyMatch Test @@ -46,3 +46,67 @@ describe("fuzzyMatch", () => { expect(fuzzyMatch("Apple", "Apple")).toEqual(Infinity); }); }); + +/** + * @description: fuzzyFilter Test + */ +describe("fuzzyFilter", () => { + const testArr = [ + { name: "cz-git", value: "cz-git" }, + { name: "plugin-inquirer", value: "plugin-inquirer" }, + { name: "plugin-loader", value: "plugin-loader" }, + { type: "separator", line: "\x1B[2m──────────────\x1B[22m" }, + { name: "custom", value: "___CUSTOM__" }, + { name: "empty", value: false } + ]; + + test("function should be check param fit", () => { + expect(fuzzyFilter("", [])).toEqual([]); + expect(fuzzyFilter("", undefined)).toEqual([]); + expect(fuzzyFilter(undefined, undefined)).toEqual([]); + expect(fuzzyFilter("", null)).toEqual([]); + }); + + test("empty input should be return origin array", () => { + expect(fuzzyFilter("", testArr)).toBe(testArr); + }); + + test("normal match should be return right array", () => { + expect(fuzzyFilter("cz-git", testArr)).toEqual([ + { name: "cz-git", value: "cz-git", index: 0, score: Infinity } + ]); + expect(fuzzyFilter("ty", testArr)).toEqual([ + { name: "empty", value: false, index: 5, score: 4 } + ]); + expect(fuzzyFilter("inq", testArr)).toEqual([ + { name: "plugin-inquirer", value: "plugin-inquirer", index: 1, score: 5 } + ]); + expect(fuzzyFilter("ii", testArr)).toEqual([ + { name: "plugin-inquirer", value: "plugin-inquirer", index: 1, score: 2 } + ]); + }); + + test("same score shoule be return sort by index", () => { + expect(fuzzyFilter("plu", testArr)).toEqual([ + { name: "plugin-inquirer", value: "plugin-inquirer", index: 1, score: 11 }, + { name: "plugin-loader", value: "plugin-loader", index: 2, score: 11 } + ]); + }); + + test("diff score shoule be return sort by score", () => { + const testArr = [ + { name: "anapple", value: "apple" }, + { name: "aapple", value: "apple" }, + { name: "apple", value: "apple" } + ]; + expect(fuzzyFilter("ap", testArr)).toEqual([ + { name: "apple", value: "apple", index: 2, score: 4 }, + { name: "anapple", value: "apple", index: 0, score: 2 }, + { name: "aapple", value: "apple", index: 1, score: 2 } + ]); + expect(fuzzyFilter("aap", testArr)).toEqual([ + { name: "aapple", value: "apple", index: 1, score: 11 }, + { name: "anapple", value: "apple", index: 0, score: 5 } + ]); + }); +}); From b82fbf9192190b9c64209c75d13a07f4b4691bbd Mon Sep 17 00:00:00 2001 From: Zhengqbbb <1074059947@qq.com> Date: Sat, 30 Apr 2022 15:17:31 +0800 Subject: [PATCH 09/10] feat(cz-git): use fuzzy search for type, scope and issues list link #22 --- packages/cz-git/src/generator/question.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/cz-git/src/generator/question.ts b/packages/cz-git/src/generator/question.ts index 00e283659..edc4aa0cb 100644 --- a/packages/cz-git/src/generator/question.ts +++ b/packages/cz-git/src/generator/question.ts @@ -15,7 +15,7 @@ import { getCurrentScopes } from "../shared"; import { generateMessage } from "./message"; -// import { fuzzyFilter } from "@cz-git/inquirer"; +import { fuzzyFilter } from "@cz-git/inquirer"; export const generateQuestions = (options: CommitizenGitOptions, cz: any) => { if (!Array.isArray(options.types) || options.types.length === 0) { @@ -29,8 +29,8 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => { name: "type", message: options.messages?.type, source: (_: unknown, input: string) => { - const typesSource = options.types?.concat(options.typesAppend || []) || []; - return typesSource.filter((item) => (input ? item.value.includes(input) : true)) || true; + const typeSource = options.types?.concat(options.typesAppend || []) || []; + return fuzzyFilter(input, typeSource, "value"); } }, { @@ -38,12 +38,12 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => { name: "scope", message: options.messages?.scope, source: (answer: Answers, input: string) => { - let scopes: Option[] = []; - scopes = handleStandardScopes( + let scopeSource: Option[] = []; + scopeSource = handleStandardScopes( getCurrentScopes(options.scopes, options.scopeOverrides, answer.type) ); - scopes = handleCustomTemplate( - scopes, + scopeSource = handleCustomTemplate( + scopeSource, cz, options.customScopesAlign, options.emptyScopesAlias, @@ -52,7 +52,7 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => { options.allowEmptyScopes, options.defaultScope as string ); - return scopes?.filter((item) => (input ? item.name?.includes(input) : true)) || true; + return fuzzyFilter(input, scopeSource); }, when: (answer: Answers) => { return !isSingleItem( @@ -159,7 +159,7 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => { name: "footerPrefix", message: options.messages?.footerPrefixsSelect, source: (_: Answers, input: string) => { - const issues = handleCustomTemplate( + const issuePrefixSource = handleCustomTemplate( options.issuePrefixs as Option[], cz, options.customIssuePrefixsAlign, @@ -168,7 +168,7 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => { options.allowCustomIssuePrefixs, options.allowEmptyIssuePrefixs ); - return issues?.filter((item) => (input ? item.name?.includes(input) : true)) || true; + return fuzzyFilter(input, issuePrefixSource); }, when: () => !isSingleItem( From f15ea5259e223028706e6d8c9c9c6d64699e7d80 Mon Sep 17 00:00:00 2001 From: Zhengqbbb <1074059947@qq.com> Date: Sat, 30 Apr 2022 15:18:36 +0800 Subject: [PATCH 10/10] test(cz-git): adjust test file for fuzzy search link #22 --- .../cz-git/__tests__/generateQuestions.test.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/cz-git/__tests__/generateQuestions.test.ts b/packages/cz-git/__tests__/generateQuestions.test.ts index e6858fc36..07b45ced9 100644 --- a/packages/cz-git/__tests__/generateQuestions.test.ts +++ b/packages/cz-git/__tests__/generateQuestions.test.ts @@ -43,7 +43,9 @@ describe("generateQuestions()", () => { expect(mockTypesSourceFn({}, "f")).toEqual([ { value: "feat", - name: "feat: this is a feature" + name: "feat: this is a feature", + index: 0, + score: 1 } ]); @@ -57,9 +59,15 @@ describe("generateQuestions()", () => { {}, { name: "cz-git", value: "cz-git" } ]); - expect(mockTypesSourceFn({}, "cz")).toEqual([{ name: "cz-git", value: "cz-git" }]); - expect(mockTypesSourceFn({}, "em")).toEqual([{ name: "empty", value: false }]); - expect(mockTypesSourceFn({}, "cu")).toEqual([{ name: "custom", value: "___CUSTOM___" }]); + expect(mockTypesSourceFn({}, "cz")).toEqual([ + { name: "cz-git", value: "cz-git", index: 3, score: 4 } + ]); + expect(mockTypesSourceFn({}, "em")).toEqual([ + { name: "empty", value: false, index: 0, score: 4 } + ]); + expect(mockTypesSourceFn({}, "cu")).toEqual([ + { name: "custom", value: "___CUSTOM___", index: 1, score: 4 } + ]); expect(mockTypesSourceFn({}, "aaa")).toEqual([]); }); });