qat-cli 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cli.js +85 -12
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +80 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +128 -120
- package/dist/index.d.ts +128 -120
- package/dist/index.js +80 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1047,12 +1047,36 @@ import_handlebars.default.registerHelper("propTestValue", (prop) => {
|
|
|
1047
1047
|
};
|
|
1048
1048
|
return map[prop.type] || "'test-value'";
|
|
1049
1049
|
});
|
|
1050
|
+
function resolveImportPath(testType, targetPath) {
|
|
1051
|
+
if (!targetPath) return targetPath;
|
|
1052
|
+
const testDirMap = {
|
|
1053
|
+
unit: "tests/unit",
|
|
1054
|
+
component: "tests/component",
|
|
1055
|
+
e2e: "tests/e2e",
|
|
1056
|
+
api: "tests/api",
|
|
1057
|
+
visual: "tests/visual",
|
|
1058
|
+
performance: "tests/e2e"
|
|
1059
|
+
};
|
|
1060
|
+
const testDir = testDirMap[testType];
|
|
1061
|
+
if (!testDir) return targetPath;
|
|
1062
|
+
if (targetPath.startsWith("../") || targetPath.startsWith("./../")) {
|
|
1063
|
+
return targetPath;
|
|
1064
|
+
}
|
|
1065
|
+
const depth = testDir.split("/").length;
|
|
1066
|
+
const prefix = "../".repeat(depth);
|
|
1067
|
+
let cleanPath = targetPath.replace(/^\.\//, "");
|
|
1068
|
+
if (!cleanPath.endsWith(".vue")) {
|
|
1069
|
+
cleanPath = cleanPath.replace(/\.(ts|js|tsx|jsx)$/, "");
|
|
1070
|
+
}
|
|
1071
|
+
return `${prefix}${cleanPath}`;
|
|
1072
|
+
}
|
|
1050
1073
|
function registerTemplate(type, templateContent) {
|
|
1051
1074
|
customTemplates.set(type, templateContent);
|
|
1052
1075
|
}
|
|
1053
1076
|
function renderTemplate(type, context) {
|
|
1054
1077
|
const templateContent = loadTemplate(type);
|
|
1055
1078
|
const template = import_handlebars.default.compile(templateContent);
|
|
1079
|
+
const resolvedTarget = resolveImportPath(type, context.target);
|
|
1056
1080
|
const fullContext = {
|
|
1057
1081
|
vueVersion: 3,
|
|
1058
1082
|
typescript: true,
|
|
@@ -1073,6 +1097,8 @@ function renderTemplate(type, context) {
|
|
|
1073
1097
|
requiredProps: [],
|
|
1074
1098
|
optionalProps: [],
|
|
1075
1099
|
...context,
|
|
1100
|
+
// 使用计算后的正确路径
|
|
1101
|
+
target: resolvedTarget,
|
|
1076
1102
|
framework: context.framework || "vue",
|
|
1077
1103
|
camelName: context.camelName || toCamelCase(context.name),
|
|
1078
1104
|
pascalName: context.pascalName || toPascalCase(context.name)
|
|
@@ -1774,14 +1800,14 @@ function buildVitestArgs(options) {
|
|
|
1774
1800
|
if (options.files && options.files.length > 0) {
|
|
1775
1801
|
args.push(...options.files);
|
|
1776
1802
|
} else {
|
|
1777
|
-
const
|
|
1778
|
-
unit:
|
|
1779
|
-
component:
|
|
1780
|
-
api:
|
|
1803
|
+
const pathMap = {
|
|
1804
|
+
unit: "tests/unit/**/*.test.ts",
|
|
1805
|
+
component: "tests/component/**/*.test.ts",
|
|
1806
|
+
api: "tests/api/**/*.test.ts"
|
|
1781
1807
|
};
|
|
1782
|
-
const
|
|
1783
|
-
if (
|
|
1784
|
-
args.push(
|
|
1808
|
+
const testPattern = pathMap[options.type];
|
|
1809
|
+
if (testPattern) {
|
|
1810
|
+
args.push(testPattern);
|
|
1785
1811
|
}
|
|
1786
1812
|
}
|
|
1787
1813
|
if (options.coverage) {
|
|
@@ -2764,8 +2790,13 @@ ${error.actual ? `\u5B9E\u9645\u503C: ${error.actual}` : ""}`;
|
|
|
2764
2790
|
6. \u5982\u679C\u6709 props/emits \u4FE1\u606F\uFF0C\u52A1\u5FC5\u9488\u5BF9\u6BCF\u4E2A prop \u548C emit \u751F\u6210\u6D4B\u8BD5`;
|
|
2765
2791
|
}
|
|
2766
2792
|
buildGenerateTestUserPrompt(req) {
|
|
2793
|
+
const importPath = this.computeTestImportPath(req.type, req.target);
|
|
2767
2794
|
let prompt = `\u8BF7\u4E3A\u4EE5\u4E0B\u6587\u4EF6\u751F\u6210${req.type}\u6D4B\u8BD5\u4EE3\u7801:
|
|
2768
2795
|
\u76EE\u6807\u6587\u4EF6: ${req.target}
|
|
2796
|
+
\u6D4B\u8BD5\u6587\u4EF6\u5C06\u653E\u5728: ${this.getTestOutputDir(req.type)}/
|
|
2797
|
+
\u6B63\u786E\u7684 import \u8DEF\u5F84: ${importPath}
|
|
2798
|
+
|
|
2799
|
+
\u91CD\u8981\uFF1Aimport \u8BED\u53E5\u4E2D\u5FC5\u987B\u4F7F\u7528\u4E0A\u8FF0\u6B63\u786E\u7684\u76F8\u5BF9\u8DEF\u5F84 ${importPath}\uFF0C\u4E0D\u8981\u4F7F\u7528 ${req.target} \u6216\u5176\u4ED6\u8DEF\u5F84\uFF01
|
|
2769
2800
|
`;
|
|
2770
2801
|
if (req.analysis) {
|
|
2771
2802
|
prompt += "\n\u6E90\u7801\u5206\u6790\u7ED3\u679C:\n";
|
|
@@ -2815,6 +2846,46 @@ ${req.context}
|
|
|
2815
2846
|
}
|
|
2816
2847
|
return prompt;
|
|
2817
2848
|
}
|
|
2849
|
+
/**
|
|
2850
|
+
* 根据测试类型和源文件路径,计算从测试文件到源文件的正确相对导入路径
|
|
2851
|
+
*/
|
|
2852
|
+
computeTestImportPath(testType, targetPath) {
|
|
2853
|
+
if (!targetPath) return targetPath;
|
|
2854
|
+
const testDirMap = {
|
|
2855
|
+
unit: "tests/unit",
|
|
2856
|
+
component: "tests/component",
|
|
2857
|
+
e2e: "tests/e2e",
|
|
2858
|
+
api: "tests/api",
|
|
2859
|
+
visual: "tests/visual",
|
|
2860
|
+
performance: "tests/e2e"
|
|
2861
|
+
};
|
|
2862
|
+
const testDir = testDirMap[testType];
|
|
2863
|
+
if (!testDir) return targetPath;
|
|
2864
|
+
if (targetPath.startsWith("../") || targetPath.startsWith("./../")) {
|
|
2865
|
+
return targetPath;
|
|
2866
|
+
}
|
|
2867
|
+
const depth = testDir.split("/").length;
|
|
2868
|
+
const prefix = "../".repeat(depth);
|
|
2869
|
+
let cleanPath = targetPath.replace(/^\.\//, "");
|
|
2870
|
+
if (!cleanPath.endsWith(".vue")) {
|
|
2871
|
+
cleanPath = cleanPath.replace(/\.(ts|js|tsx|jsx)$/, "");
|
|
2872
|
+
}
|
|
2873
|
+
return `${prefix}${cleanPath}`;
|
|
2874
|
+
}
|
|
2875
|
+
/**
|
|
2876
|
+
* 获取测试输出目录
|
|
2877
|
+
*/
|
|
2878
|
+
getTestOutputDir(testType) {
|
|
2879
|
+
const dirMap = {
|
|
2880
|
+
unit: "tests/unit",
|
|
2881
|
+
component: "tests/component",
|
|
2882
|
+
e2e: "tests/e2e",
|
|
2883
|
+
api: "tests/api",
|
|
2884
|
+
visual: "tests/visual",
|
|
2885
|
+
performance: "tests/e2e"
|
|
2886
|
+
};
|
|
2887
|
+
return dirMap[testType] || "tests/unit";
|
|
2888
|
+
}
|
|
2818
2889
|
parseGenerateTestResponse(content) {
|
|
2819
2890
|
const codeBlockMatch = content.match(/```(?:typescript|ts|javascript|js)?\s*\n([\s\S]*?)```/);
|
|
2820
2891
|
const code = codeBlockMatch ? codeBlockMatch[1].trim() : content.replace(/^(?:```[\s\S]*?\n)?/, "").replace(/\n?```$/, "").trim();
|
|
@@ -2843,10 +2914,12 @@ ISSUES: \u95EE\u9898\u5217\u8868\uFF08\u6BCF\u884C\u4E00\u4E2A\uFF0C\u683C\u5F0F
|
|
|
2843
2914
|
SUGGESTIONS: \u6539\u8FDB\u5EFA\u8BAE\u5217\u8868\uFF08\u6BCF\u884C\u4E00\u4E2A\uFF0C\u683C\u5F0F "- \u5EFA\u8BAE\u63CF\u8FF0"\uFF09`;
|
|
2844
2915
|
}
|
|
2845
2916
|
buildReviewTestUserPrompt(req) {
|
|
2917
|
+
const importPath = this.computeTestImportPath(req.testType, req.target);
|
|
2846
2918
|
let prompt = `\u8BF7\u5BA1\u67E5\u4EE5\u4E0B\u6D4B\u8BD5\u7528\u4F8B\u662F\u5426\u4E0E\u6E90\u7801\u8D34\u5207\u4E14\u51C6\u786E\u3002
|
|
2847
2919
|
|
|
2848
2920
|
\u88AB\u6D4B\u6587\u4EF6: ${req.target}
|
|
2849
2921
|
\u6D4B\u8BD5\u7C7B\u578B: ${req.testType}
|
|
2922
|
+
\u6B63\u786E\u7684 import \u8DEF\u5F84\u5E94\u4E3A: ${importPath}\uFF08\u6D4B\u8BD5\u6587\u4EF6\u4F4D\u4E8E ${this.getTestOutputDir(req.testType)}/\uFF09
|
|
2850
2923
|
|
|
2851
2924
|
--- \u6E90\u7801\u5185\u5BB9 ---
|
|
2852
2925
|
\`\`\`typescript
|