@ai-dev-tools/test-copilot-core 1.0.19
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 +6 -0
- package/azure-pipelines.yml +51 -0
- package/out/cli/commands/appInsightTelemetry.d.ts +7 -0
- package/out/cli/commands/appInsightTelemetry.d.ts.map +1 -0
- package/out/cli/commands/appInsightTelemetry.js +76 -0
- package/out/cli/commands/appInsightTelemetry.js.map +1 -0
- package/out/cli/commands/cliConfig.d.ts +4 -0
- package/out/cli/commands/cliConfig.d.ts.map +1 -0
- package/out/cli/commands/cliConfig.js +68 -0
- package/out/cli/commands/cliConfig.js.map +1 -0
- package/out/cli/commands/prompt.d.ts +6 -0
- package/out/cli/commands/prompt.d.ts.map +1 -0
- package/out/cli/commands/prompt.js +29 -0
- package/out/cli/commands/prompt.js.map +1 -0
- package/out/cli/commands/ut.d.ts +14 -0
- package/out/cli/commands/ut.d.ts.map +1 -0
- package/out/cli/commands/ut.js +72 -0
- package/out/cli/commands/ut.js.map +1 -0
- package/out/cli/commands/utPipeCmdWrapper.d.ts +18 -0
- package/out/cli/commands/utPipeCmdWrapper.d.ts.map +1 -0
- package/out/cli/commands/utPipeCmdWrapper.js +37 -0
- package/out/cli/commands/utPipeCmdWrapper.js.map +1 -0
- package/out/cli/config/index.d.ts +15 -0
- package/out/cli/config/index.d.ts.map +1 -0
- package/out/cli/config/index.js +10 -0
- package/out/cli/config/index.js.map +1 -0
- package/out/cli/index.d.ts +3 -0
- package/out/cli/index.d.ts.map +1 -0
- package/out/cli/index.js +169 -0
- package/out/cli/index.js.map +1 -0
- package/out/cli/type.d.ts +11 -0
- package/out/cli/type.d.ts.map +1 -0
- package/out/cli/type.js +3 -0
- package/out/cli/type.js.map +1 -0
- package/out/cli/utils/ds.d.ts +3 -0
- package/out/cli/utils/ds.d.ts.map +1 -0
- package/out/cli/utils/ds.js +50 -0
- package/out/cli/utils/ds.js.map +1 -0
- package/out/cli/utils/gpt.d.ts +3 -0
- package/out/cli/utils/gpt.d.ts.map +1 -0
- package/out/cli/utils/gpt.js +63 -0
- package/out/cli/utils/gpt.js.map +1 -0
- package/out/core/analyze/cjs.d.ts +61 -0
- package/out/core/analyze/cjs.d.ts.map +1 -0
- package/out/core/analyze/cjs.js +358 -0
- package/out/core/analyze/cjs.js.map +1 -0
- package/out/core/analyze/class.d.ts +4 -0
- package/out/core/analyze/class.d.ts.map +1 -0
- package/out/core/analyze/class.js +32 -0
- package/out/core/analyze/class.js.map +1 -0
- package/out/core/analyze/declares.d.ts +7 -0
- package/out/core/analyze/declares.d.ts.map +1 -0
- package/out/core/analyze/declares.js +316 -0
- package/out/core/analyze/declares.js.map +1 -0
- package/out/core/analyze/deps.d.ts +8 -0
- package/out/core/analyze/deps.d.ts.map +1 -0
- package/out/core/analyze/deps.js +210 -0
- package/out/core/analyze/deps.js.map +1 -0
- package/out/core/analyze/functionComponent.d.ts +4 -0
- package/out/core/analyze/functionComponent.d.ts.map +1 -0
- package/out/core/analyze/functionComponent.js +77 -0
- package/out/core/analyze/functionComponent.js.map +1 -0
- package/out/core/analyze/functions.d.ts +4 -0
- package/out/core/analyze/functions.d.ts.map +1 -0
- package/out/core/analyze/functions.js +46 -0
- package/out/core/analyze/functions.js.map +1 -0
- package/out/core/analyze/index.d.ts +16 -0
- package/out/core/analyze/index.d.ts.map +1 -0
- package/out/core/analyze/index.js +149 -0
- package/out/core/analyze/index.js.map +1 -0
- package/out/core/analyze/index.type.d.ts +69 -0
- package/out/core/analyze/index.type.d.ts.map +1 -0
- package/out/core/analyze/index.type.js +14 -0
- package/out/core/analyze/index.type.js.map +1 -0
- package/out/core/analyze/utils/global.d.ts +2 -0
- package/out/core/analyze/utils/global.d.ts.map +1 -0
- package/out/core/analyze/utils/global.js +84 -0
- package/out/core/analyze/utils/global.js.map +1 -0
- package/out/core/analyzev2/declare/class.d.ts +4 -0
- package/out/core/analyzev2/declare/class.d.ts.map +1 -0
- package/out/core/analyzev2/declare/class.js +24 -0
- package/out/core/analyzev2/declare/class.js.map +1 -0
- package/out/core/analyzev2/declare/funcLike.d.ts +8 -0
- package/out/core/analyzev2/declare/funcLike.d.ts.map +1 -0
- package/out/core/analyzev2/declare/funcLike.js +71 -0
- package/out/core/analyzev2/declare/funcLike.js.map +1 -0
- package/out/core/analyzev2/declare/variable.d.ts +3 -0
- package/out/core/analyzev2/declare/variable.d.ts.map +1 -0
- package/out/core/analyzev2/declare/variable.js +15 -0
- package/out/core/analyzev2/declare/variable.js.map +1 -0
- package/out/core/analyzev2/file.d.ts +19 -0
- package/out/core/analyzev2/file.d.ts.map +1 -0
- package/out/core/analyzev2/file.js +449 -0
- package/out/core/analyzev2/file.js.map +1 -0
- package/out/core/analyzev2/index.d.ts +5 -0
- package/out/core/analyzev2/index.d.ts.map +1 -0
- package/out/core/analyzev2/index.js +30 -0
- package/out/core/analyzev2/index.js.map +1 -0
- package/out/core/analyzev2/type.d.ts +35 -0
- package/out/core/analyzev2/type.d.ts.map +1 -0
- package/out/core/analyzev2/type.js +3 -0
- package/out/core/analyzev2/type.js.map +1 -0
- package/out/core/config/index.d.ts +25 -0
- package/out/core/config/index.d.ts.map +1 -0
- package/out/core/config/index.js +14 -0
- package/out/core/config/index.js.map +1 -0
- package/out/core/constants.d.ts +9 -0
- package/out/core/constants.d.ts.map +1 -0
- package/out/core/constants.js +12 -0
- package/out/core/constants.js.map +1 -0
- package/out/core/features/common/base.d.ts +20 -0
- package/out/core/features/common/base.d.ts.map +1 -0
- package/out/core/features/common/base.js +77 -0
- package/out/core/features/common/base.js.map +1 -0
- package/out/core/features/common/types.d.ts +16 -0
- package/out/core/features/common/types.d.ts.map +1 -0
- package/out/core/features/common/types.js +12 -0
- package/out/core/features/common/types.js.map +1 -0
- package/out/core/features/generateFile.d.ts +31 -0
- package/out/core/features/generateFile.d.ts.map +1 -0
- package/out/core/features/generateFile.js +148 -0
- package/out/core/features/generateFile.js.map +1 -0
- package/out/core/features/generateSingle.d.ts +28 -0
- package/out/core/features/generateSingle.d.ts.map +1 -0
- package/out/core/features/generateSingle.js +149 -0
- package/out/core/features/generateSingle.js.map +1 -0
- package/out/core/features/index.d.ts +9 -0
- package/out/core/features/index.d.ts.map +1 -0
- package/out/core/features/index.js +16 -0
- package/out/core/features/index.js.map +1 -0
- package/out/core/features/lintFix.d.ts +2 -0
- package/out/core/features/lintFix.d.ts.map +1 -0
- package/out/core/features/lintFix.js +33 -0
- package/out/core/features/lintFix.js.map +1 -0
- package/out/core/features/mergeUTFile.d.ts +19 -0
- package/out/core/features/mergeUTFile.d.ts.map +1 -0
- package/out/core/features/mergeUTFile.js +63 -0
- package/out/core/features/mergeUTFile.js.map +1 -0
- package/out/core/features/removeFailedCases.d.ts +23 -0
- package/out/core/features/removeFailedCases.d.ts.map +1 -0
- package/out/core/features/removeFailedCases.js +81 -0
- package/out/core/features/removeFailedCases.js.map +1 -0
- package/out/core/features/updateSpec.d.ts +20 -0
- package/out/core/features/updateSpec.d.ts.map +1 -0
- package/out/core/features/updateSpec.js +98 -0
- package/out/core/features/updateSpec.js.map +1 -0
- package/out/core/features/validFix.d.ts +29 -0
- package/out/core/features/validFix.d.ts.map +1 -0
- package/out/core/features/validFix.js +219 -0
- package/out/core/features/validFix.js.map +1 -0
- package/out/core/generate/UTGen.d.ts +79 -0
- package/out/core/generate/UTGen.d.ts.map +1 -0
- package/out/core/generate/UTGen.js +795 -0
- package/out/core/generate/UTGen.js.map +1 -0
- package/out/core/llm/index.d.ts +9 -0
- package/out/core/llm/index.d.ts.map +1 -0
- package/out/core/llm/index.js +39 -0
- package/out/core/llm/index.js.map +1 -0
- package/out/core/llm/prompts/config.d.ts +6 -0
- package/out/core/llm/prompts/config.d.ts.map +1 -0
- package/out/core/llm/prompts/config.js +239 -0
- package/out/core/llm/prompts/config.js.map +1 -0
- package/out/core/llm/prompts/templates/common.d.ts +3 -0
- package/out/core/llm/prompts/templates/common.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/common.js +27 -0
- package/out/core/llm/prompts/templates/common.js.map +1 -0
- package/out/core/llm/prompts/templates/fixCase.d.ts +4 -0
- package/out/core/llm/prompts/templates/fixCase.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/fixCase.js +46 -0
- package/out/core/llm/prompts/templates/fixCase.js.map +1 -0
- package/out/core/llm/prompts/templates/fixLint.d.ts +3 -0
- package/out/core/llm/prompts/templates/fixLint.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/fixLint.js +22 -0
- package/out/core/llm/prompts/templates/fixLint.js.map +1 -0
- package/out/core/llm/prompts/templates/genClassMemberUT.d.ts +5 -0
- package/out/core/llm/prompts/templates/genClassMemberUT.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/genClassMemberUT.js +115 -0
- package/out/core/llm/prompts/templates/genClassMemberUT.js.map +1 -0
- package/out/core/llm/prompts/templates/genFuncUT.d.ts +4 -0
- package/out/core/llm/prompts/templates/genFuncUT.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/genFuncUT.js +64 -0
- package/out/core/llm/prompts/templates/genFuncUT.js.map +1 -0
- package/out/core/llm/prompts/templates/mergeUT.d.ts +4 -0
- package/out/core/llm/prompts/templates/mergeUT.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/mergeUT.js +106 -0
- package/out/core/llm/prompts/templates/mergeUT.js.map +1 -0
- package/out/core/llm/prompts/templates/msnStudio.d.ts +3 -0
- package/out/core/llm/prompts/templates/msnStudio.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/msnStudio.js +36 -0
- package/out/core/llm/prompts/templates/msnStudio.js.map +1 -0
- package/out/core/llm/prompts/templates/snapshotUT.d.ts +4 -0
- package/out/core/llm/prompts/templates/snapshotUT.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/snapshotUT.js +68 -0
- package/out/core/llm/prompts/templates/snapshotUT.js.map +1 -0
- package/out/core/llm/prompts/templates/updateSpecBlock.d.ts +3 -0
- package/out/core/llm/prompts/templates/updateSpecBlock.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/updateSpecBlock.js +38 -0
- package/out/core/llm/prompts/templates/updateSpecBlock.js.map +1 -0
- package/out/core/llm/prompts/templates/updateSpecFile.d.ts +3 -0
- package/out/core/llm/prompts/templates/updateSpecFile.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/updateSpecFile.js +30 -0
- package/out/core/llm/prompts/templates/updateSpecFile.js.map +1 -0
- package/out/core/llm/types.d.ts +80 -0
- package/out/core/llm/types.d.ts.map +1 -0
- package/out/core/llm/types.js +5 -0
- package/out/core/llm/types.js.map +1 -0
- package/out/core/quality/validateMockedTest.d.ts +3 -0
- package/out/core/quality/validateMockedTest.d.ts.map +1 -0
- package/out/core/quality/validateMockedTest.js +211 -0
- package/out/core/quality/validateMockedTest.js.map +1 -0
- package/out/core/utils/checkTestIgnore.d.ts +4 -0
- package/out/core/utils/checkTestIgnore.d.ts.map +1 -0
- package/out/core/utils/checkTestIgnore.js +52 -0
- package/out/core/utils/checkTestIgnore.js.map +1 -0
- package/out/core/utils/common.d.ts +4 -0
- package/out/core/utils/common.d.ts.map +1 -0
- package/out/core/utils/common.js +34 -0
- package/out/core/utils/common.js.map +1 -0
- package/out/core/utils/console.d.ts +8 -0
- package/out/core/utils/console.d.ts.map +1 -0
- package/out/core/utils/console.js +24 -0
- package/out/core/utils/console.js.map +1 -0
- package/out/core/utils/deps.d.ts +3 -0
- package/out/core/utils/deps.d.ts.map +1 -0
- package/out/core/utils/deps.js +58 -0
- package/out/core/utils/deps.js.map +1 -0
- package/out/core/utils/eslintRuleHandler.d.ts +3 -0
- package/out/core/utils/eslintRuleHandler.d.ts.map +1 -0
- package/out/core/utils/eslintRuleHandler.js +98 -0
- package/out/core/utils/eslintRuleHandler.js.map +1 -0
- package/out/core/utils/file.d.ts +18 -0
- package/out/core/utils/file.d.ts.map +1 -0
- package/out/core/utils/file.js +142 -0
- package/out/core/utils/file.js.map +1 -0
- package/out/core/utils/lint.d.ts +9 -0
- package/out/core/utils/lint.d.ts.map +1 -0
- package/out/core/utils/lint.js +95 -0
- package/out/core/utils/lint.js.map +1 -0
- package/out/core/utils/lru.d.ts +12 -0
- package/out/core/utils/lru.d.ts.map +1 -0
- package/out/core/utils/lru.js +47 -0
- package/out/core/utils/lru.js.map +1 -0
- package/out/core/utils/move.d.ts +12 -0
- package/out/core/utils/move.d.ts.map +1 -0
- package/out/core/utils/move.js +93 -0
- package/out/core/utils/move.js.map +1 -0
- package/out/core/utils/msnStudio.d.ts +13 -0
- package/out/core/utils/msnStudio.d.ts.map +1 -0
- package/out/core/utils/msnStudio.js +150 -0
- package/out/core/utils/msnStudio.js.map +1 -0
- package/out/core/utils/parseCustomizedCmd.d.ts +2 -0
- package/out/core/utils/parseCustomizedCmd.d.ts.map +1 -0
- package/out/core/utils/parseCustomizedCmd.js +32 -0
- package/out/core/utils/parseCustomizedCmd.js.map +1 -0
- package/out/core/utils/specBlock.d.ts +20 -0
- package/out/core/utils/specBlock.d.ts.map +1 -0
- package/out/core/utils/specBlock.js +231 -0
- package/out/core/utils/specBlock.js.map +1 -0
- package/out/core/utils/system.d.ts +13 -0
- package/out/core/utils/system.d.ts.map +1 -0
- package/out/core/utils/system.js +86 -0
- package/out/core/utils/system.js.map +1 -0
- package/out/core/utils/telemetry.d.ts +9 -0
- package/out/core/utils/telemetry.d.ts.map +1 -0
- package/out/core/utils/telemetry.js +32 -0
- package/out/core/utils/telemetry.js.map +1 -0
- package/out/core/utils/tsMorph.d.ts +13 -0
- package/out/core/utils/tsMorph.d.ts.map +1 -0
- package/out/core/utils/tsMorph.js +76 -0
- package/out/core/utils/tsMorph.js.map +1 -0
- package/out/core/valid/customizedLint.d.ts +2 -0
- package/out/core/valid/customizedLint.d.ts.map +1 -0
- package/out/core/valid/customizedLint.js +64 -0
- package/out/core/valid/customizedLint.js.map +1 -0
- package/out/core/valid/customizedTest.d.ts +3 -0
- package/out/core/valid/customizedTest.d.ts.map +1 -0
- package/out/core/valid/customizedTest.js +58 -0
- package/out/core/valid/customizedTest.js.map +1 -0
- package/out/core/valid/extractVitestConfig.d.ts +5 -0
- package/out/core/valid/extractVitestConfig.d.ts.map +1 -0
- package/out/core/valid/extractVitestConfig.js +97 -0
- package/out/core/valid/extractVitestConfig.js.map +1 -0
- package/out/core/valid/getViteConfig.d.ts +2 -0
- package/out/core/valid/getViteConfig.d.ts.map +1 -0
- package/out/core/valid/getViteConfig.js +65 -0
- package/out/core/valid/getViteConfig.js.map +1 -0
- package/out/core/valid/index.d.ts +15 -0
- package/out/core/valid/index.d.ts.map +1 -0
- package/out/core/valid/index.js +99 -0
- package/out/core/valid/index.js.map +1 -0
- package/out/core/valid/jest.d.ts +4 -0
- package/out/core/valid/jest.d.ts.map +1 -0
- package/out/core/valid/jest.js +121 -0
- package/out/core/valid/jest.js.map +1 -0
- package/out/core/valid/mock.d.ts +2 -0
- package/out/core/valid/mock.d.ts.map +1 -0
- package/out/core/valid/mock.js +149 -0
- package/out/core/valid/mock.js.map +1 -0
- package/out/core/valid/remove.d.ts +5 -0
- package/out/core/valid/remove.d.ts.map +1 -0
- package/out/core/valid/remove.js +109 -0
- package/out/core/valid/remove.js.map +1 -0
- package/out/core/valid/tag.d.ts +3 -0
- package/out/core/valid/tag.d.ts.map +1 -0
- package/out/core/valid/tag.js +91 -0
- package/out/core/valid/tag.js.map +1 -0
- package/out/core/valid/type.d.ts +83 -0
- package/out/core/valid/type.d.ts.map +1 -0
- package/out/core/valid/type.js +3 -0
- package/out/core/valid/type.js.map +1 -0
- package/out/core/valid/vitest.d.ts +3 -0
- package/out/core/valid/vitest.d.ts.map +1 -0
- package/out/core/valid/vitest.js +82 -0
- package/out/core/valid/vitest.js.map +1 -0
- package/out/index.d.ts +20 -0
- package/out/index.d.ts.map +1 -0
- package/out/index.js +60 -0
- package/out/index.js.map +1 -0
- package/out/setup.d.ts +11 -0
- package/out/setup.d.ts.map +1 -0
- package/out/setup.js +14 -0
- package/out/setup.js.map +1 -0
- package/out/types.d.ts +23 -0
- package/out/types.d.ts.map +1 -0
- package/out/types.js +3 -0
- package/out/types.js.map +1 -0
- package/package.json +39 -0
- package/package_devops.json +42 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkMock = checkMock;
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const console_1 = require("../utils/console");
|
|
6
|
+
function checkMock(code) {
|
|
7
|
+
if (!code) {
|
|
8
|
+
(0, console_1.getConsole)().error('Empty code to check mock');
|
|
9
|
+
return code;
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
const project = new ts_morph_1.Project({
|
|
13
|
+
useInMemoryFileSystem: true,
|
|
14
|
+
skipAddingFilesFromTsConfig: true,
|
|
15
|
+
skipFileDependencyResolution: true,
|
|
16
|
+
compilerOptions: {
|
|
17
|
+
allowJs: true,
|
|
18
|
+
checkJs: false
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
const sourceFile = project.createSourceFile('tmp.tsx', code);
|
|
22
|
+
const statements = sourceFile.getStatements();
|
|
23
|
+
let hasUpdate = false;
|
|
24
|
+
for (const statement of statements) {
|
|
25
|
+
hasUpdate = updateStatement(statement) || hasUpdate;
|
|
26
|
+
}
|
|
27
|
+
hasUpdate = sortImports(sourceFile) || hasUpdate;
|
|
28
|
+
if (hasUpdate) {
|
|
29
|
+
sourceFile.saveSync();
|
|
30
|
+
const res = sourceFile.getFullText();
|
|
31
|
+
if (!res) {
|
|
32
|
+
(0, console_1.getConsole)().error('Failed to update mock', res);
|
|
33
|
+
return code;
|
|
34
|
+
}
|
|
35
|
+
return res;
|
|
36
|
+
}
|
|
37
|
+
return code;
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
(0, console_1.getConsole)().error('Failed to check mock statments', e);
|
|
41
|
+
return code;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function updateStatement(statement) {
|
|
45
|
+
if (statement.getKind() !== ts_morph_1.SyntaxKind.ExpressionStatement) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const expression = statement.getFirstChild();
|
|
49
|
+
if (expression.getKind() !== ts_morph_1.SyntaxKind.CallExpression) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const caller = expression.getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAccessExpression)[0];
|
|
53
|
+
if (!caller) {
|
|
54
|
+
console.log('No caller found', expression.getText());
|
|
55
|
+
}
|
|
56
|
+
const callerName = caller.getText();
|
|
57
|
+
if (callerName === 'jest.mock') {
|
|
58
|
+
return updateJestMock(expression);
|
|
59
|
+
}
|
|
60
|
+
if (callerName === 'vi.mock') {
|
|
61
|
+
return updateViMock(expression);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function updateJestMock(expression) {
|
|
65
|
+
const packageName = expression.getArguments()[0]?.getText();
|
|
66
|
+
const mock = expression.getArguments()[1];
|
|
67
|
+
if (!mock) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// skip other cases for now
|
|
71
|
+
if (mock.getKind() !== ts_morph_1.SyntaxKind.ArrowFunction) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const mockText = mock.getText();
|
|
75
|
+
if (mockText.includes('jest.requireActual')) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const literal = mock.getFirstDescendantByKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
|
|
79
|
+
if (!literal) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
literal.insertSpreadAssignment(0, { expression: `jest.requireActual(${packageName})` });
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
function updateViMock(expression) {
|
|
86
|
+
const packageName = expression.getArguments()[0]?.getText();
|
|
87
|
+
const mock = expression.getArguments()[1];
|
|
88
|
+
if (!mock) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
// skip other cases for now
|
|
92
|
+
if (mock.getKind() !== ts_morph_1.SyntaxKind.ArrowFunction) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const mockText = mock.getText();
|
|
96
|
+
if (mockText.includes('vi.importActual')) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const literal = mock.getFirstDescendantByKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
|
|
100
|
+
if (!literal) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const arrowFunction = mock.asKindOrThrow(ts_morph_1.SyntaxKind.ArrowFunction);
|
|
104
|
+
if (!arrowFunction.isAsync()) {
|
|
105
|
+
arrowFunction.setIsAsync(true);
|
|
106
|
+
}
|
|
107
|
+
literal.insertSpreadAssignment(0, { expression: `await vi.importActual(${packageName})` });
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
function sortImports(sourceFile) {
|
|
111
|
+
let hasOtherStatements = false;
|
|
112
|
+
const statements = sourceFile.getStatementsWithComments();
|
|
113
|
+
const spreadImports = [];
|
|
114
|
+
let insertImportIndex = -1;
|
|
115
|
+
let firstCommentIndex = -1;
|
|
116
|
+
statements.forEach((statement, index) => {
|
|
117
|
+
const kind = statement.getKind();
|
|
118
|
+
if (kind === ts_morph_1.SyntaxKind.SingleLineCommentTrivia || kind === ts_morph_1.SyntaxKind.MultiLineCommentTrivia) {
|
|
119
|
+
if (firstCommentIndex < 0) {
|
|
120
|
+
firstCommentIndex = index;
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (kind === ts_morph_1.SyntaxKind.ImportDeclaration) {
|
|
125
|
+
if (hasOtherStatements) {
|
|
126
|
+
spreadImports.push(statement);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
insertImportIndex = index;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
hasOtherStatements = true;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
if (!spreadImports.length) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
if (insertImportIndex < 0) {
|
|
140
|
+
insertImportIndex = firstCommentIndex;
|
|
141
|
+
}
|
|
142
|
+
spreadImports.forEach(statement => {
|
|
143
|
+
const text = statement.getText();
|
|
144
|
+
statement.remove();
|
|
145
|
+
sourceFile.insertStatements(insertImportIndex + 1, text);
|
|
146
|
+
});
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=mock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock.js","sourceRoot":"","sources":["../../../src/core/valid/mock.ts"],"names":[],"mappings":";;AAGA,8BAoCC;AAvCD,uCAA+G;AAC/G,8CAA8C;AAE9C,SAAgB,SAAS,CAAC,IAAY;IAClC,IAAI,CAAC,IAAI,EAAE,CAAC;QACR,IAAA,oBAAU,GAAE,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,IAAI,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,kBAAO,CAAC;YACxB,qBAAqB,EAAE,IAAI;YAC3B,2BAA2B,EAAE,IAAI;YACjC,4BAA4B,EAAE,IAAI;YAClC,eAAe,EAAE;gBACb,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,KAAK;aACjB;SACJ,CAAC,CAAC;QACH,MAAM,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAC7D,MAAM,UAAU,GAAG,UAAU,CAAC,aAAa,EAAE,CAAC;QAC9C,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACjC,SAAS,GAAG,eAAe,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC;QACxD,CAAC;QACD,SAAS,GAAG,WAAW,CAAC,UAAU,CAAC,IAAI,SAAS,CAAC;QACjD,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C;gBACrB,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAClC,CAAC;iBAAM,CAAC;gBACJ,iBAAiB,GAAG,KAAK,CAAC;YAC9B,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,kBAAkB,GAAG,IAAI,CAAC;QAC9B,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC;QACxB,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,IAAI,iBAAiB,GAAG,CAAC,EAAE,CAAC;QACxB,iBAAiB,GAAG,iBAAiB,CAAC;IAC1C,CAAC;IAED,aAAa,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;QAC9B,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC;QACjC,SAAS,CAAC,MAAM,EAAE,CAAC;QACnB,UAAU,CAAC,gBAAgB,CAAC,iBAAiB,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove.d.ts","sourceRoot":"","sources":["../../../src/core/valid/remove.ts"],"names":[],"mappings":"AAGA,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,eAAe,UAG5F;AAED,MAAM,WAAW,eAAe;IAC5B,YAAY,CAAC,EAAE,OAAO,CAAC;CAC1B"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeTestCases = removeTestCases;
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const console_1 = require("../utils/console");
|
|
6
|
+
function removeTestCases(code, targets, options) {
|
|
7
|
+
const removeIt = new RemoveIt(code, targets, options);
|
|
8
|
+
return removeIt.result;
|
|
9
|
+
}
|
|
10
|
+
class RemoveIt {
|
|
11
|
+
targets;
|
|
12
|
+
options;
|
|
13
|
+
project;
|
|
14
|
+
name = `tmp.ts`;
|
|
15
|
+
sourceFile;
|
|
16
|
+
constructor(code, targets, options) {
|
|
17
|
+
this.targets = targets;
|
|
18
|
+
this.options = options;
|
|
19
|
+
this.project = new ts_morph_1.Project({
|
|
20
|
+
useInMemoryFileSystem: true,
|
|
21
|
+
skipAddingFilesFromTsConfig: true,
|
|
22
|
+
skipFileDependencyResolution: true,
|
|
23
|
+
compilerOptions: {
|
|
24
|
+
allowJs: true,
|
|
25
|
+
checkJs: false
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
this.sourceFile = this.project.createSourceFile(this.name, code);
|
|
29
|
+
const statements = this.sourceFile.getStatements();
|
|
30
|
+
const hasRemove = this.scanStatement(statements);
|
|
31
|
+
this.sourceFile.saveSync();
|
|
32
|
+
if (hasRemove) {
|
|
33
|
+
this.sourceFile.fixUnusedIdentifiers();
|
|
34
|
+
this.sourceFile.saveSync();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
get result() {
|
|
38
|
+
return this.project.getSourceFile(this.name).getText();
|
|
39
|
+
}
|
|
40
|
+
scanStatement(statements, parentPath = '') {
|
|
41
|
+
let hasRemove = false;
|
|
42
|
+
for (const statement of statements) {
|
|
43
|
+
if (statement.getKind() !== ts_morph_1.SyntaxKind.ExpressionStatement) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const expression = statement.getFirstDescendantByKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
47
|
+
const id = expression?.getFirstDescendantByKind(ts_morph_1.SyntaxKind.Identifier)?.getText();
|
|
48
|
+
if (id === "describe") {
|
|
49
|
+
this.checkDescribe(expression, parentPath);
|
|
50
|
+
}
|
|
51
|
+
else if (id === "it") {
|
|
52
|
+
const needRemove = this.checkIt(expression, parentPath);
|
|
53
|
+
if (!needRemove) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
hasRemove = true;
|
|
57
|
+
if (!this.options?.deleteFailed) {
|
|
58
|
+
statement.replaceWithText(`/* ${statement.getText().replaceAll('*/', '*\\/')} */`);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
statement.remove();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return hasRemove;
|
|
66
|
+
}
|
|
67
|
+
checkDescribe(expression, parentPath = '') {
|
|
68
|
+
try {
|
|
69
|
+
const args = expression.getArguments();
|
|
70
|
+
if (!isValidExpression(args)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const title = args[0].asKind(ts_morph_1.SyntaxKind.StringLiteral).getLiteralValue();
|
|
74
|
+
const currPath = parentPath ? `${parentPath}>${title}` : title;
|
|
75
|
+
const statements = args[1].getFirstDescendantByKind(ts_morph_1.SyntaxKind.Block)?.getStatements() || [];
|
|
76
|
+
this.scanStatement(statements, currPath);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
(0, console_1.getConsole)().error(`Error in checkDescribe: ${error}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
checkIt(expression, parentPath = '') {
|
|
83
|
+
try {
|
|
84
|
+
const args = expression.getArguments();
|
|
85
|
+
if (!isValidExpression(args)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const title = args[0].asKind(ts_morph_1.SyntaxKind.StringLiteral).getLiteralValue();
|
|
89
|
+
const currPath = parentPath ? `${parentPath}>${title}` : title;
|
|
90
|
+
if (this.targets.has(currPath)) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
(0, console_1.getConsole)().error(`Error in checkIt: ${error}`);
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function isValidExpression(args) {
|
|
101
|
+
if (args.length < 2) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (args[0].getKind() !== ts_morph_1.SyntaxKind.StringLiteral || (args[1].getKind() !== ts_morph_1.SyntaxKind.ArrowFunction && args[1].getKind() !== ts_morph_1.SyntaxKind.FunctionExpression)) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=remove.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove.js","sourceRoot":"","sources":["../../../src/core/valid/remove.ts"],"names":[],"mappings":";;AAGA,0CAGC;AAND,uCAA4F;AAC5F,8CAA8C;AAE9C,SAAgB,eAAe,CAAC,IAAY,EAAE,OAAoB,EAAE,OAAyB;IACzF,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACtD,OAAO,QAAQ,CAAC,MAAM,CAAC;AAC3B,CAAC;AAMD,MAAM,QAAQ;IAKwB;IAA8B;IAJxD,OAAO,CAAU;IACjB,IAAI,GAAG,QAAQ,CAAC;IAChB,UAAU,CAAa;IAE/B,YAAY,IAAY,EAAU,OAAoB,EAAU,OAAyB;QAAvD,YAAO,GAAP,OAAO,CAAa;QAAU,YAAO,GAAP,OAAO,CAAkB;QACrF,IAAI,CAAC,OAAO,GAAG,IAAI,kBAAO,CAAC;YACvB,qBAAqB,EAAE,IAAI;YAC3B,2BAA2B,EAAE,IAAI;YACjC,4BAA4B,EAAE,IAAI;YAClC,eAAe,EAAE;gBACb,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,KAAK;aACjB;SACJ,CAAC,CAAC;QACH,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACjE,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC;Q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AAC,CAAC,MAAM,CAAC,qBAAU,CAAC,aAAa,CAAC,CAAC,eAAe,EAAE,CAAC;YACzE,MAAM,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;YAC/D,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC7B,OAAO,IAAI,CAAC;YAChB,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAA,oBAAU,GAAE,CAAC,KAAK,CAAC,qBAAqB,KAAK,EAAE,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AAED,SAAS,iBAAiB,CAAC,IAAY;IACnC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClB,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,qBAAU,CAAC,aAAa,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,qBAAU,CAAC,aAAa,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,qBAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAC5J,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag.d.ts","sourceRoot":"","sources":["../../../src/core/valid/tag.ts"],"names":[],"mappings":"AAWA,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,UAgClC;AA6CD,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAK7C"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addTag = addTag;
|
|
4
|
+
exports.formatDate = formatDate;
|
|
5
|
+
const ts_morph_1 = require("ts-morph");
|
|
6
|
+
const console_1 = require("../utils/console");
|
|
7
|
+
const TestBlocks = new Set([
|
|
8
|
+
'describe',
|
|
9
|
+
'it',
|
|
10
|
+
'test',
|
|
11
|
+
'suite',
|
|
12
|
+
]);
|
|
13
|
+
function addTag(code) {
|
|
14
|
+
if (!code) {
|
|
15
|
+
(0, console_1.getConsole)().error('Empty code to check test mock');
|
|
16
|
+
return code;
|
|
17
|
+
}
|
|
18
|
+
let hasUpdate = false;
|
|
19
|
+
try {
|
|
20
|
+
const project = new ts_morph_1.Project({
|
|
21
|
+
useInMemoryFileSystem: true,
|
|
22
|
+
skipAddingFilesFromTsConfig: true,
|
|
23
|
+
skipFileDependencyResolution: true,
|
|
24
|
+
compilerOptions: {
|
|
25
|
+
allowJs: true,
|
|
26
|
+
checkJs: false
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const sourceFile = project.createSourceFile('tmp.tsx', code);
|
|
30
|
+
const statements = sourceFile.getStatements();
|
|
31
|
+
for (const statement of statements) {
|
|
32
|
+
if (addTagOnCase(statement)) {
|
|
33
|
+
hasUpdate = true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (hasUpdate) {
|
|
37
|
+
sourceFile.saveSync();
|
|
38
|
+
return sourceFile.getFullText();
|
|
39
|
+
}
|
|
40
|
+
return code;
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
(0, console_1.getConsole)().error('Failed to check mock statments', e);
|
|
44
|
+
return code;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const oldAiTag = '@aiGenerated';
|
|
48
|
+
const aiTag = '@aiContributed';
|
|
49
|
+
function addTagOnCase(statement) {
|
|
50
|
+
if (statement.getKind() !== ts_morph_1.SyntaxKind.ExpressionStatement) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const expStat = statement;
|
|
54
|
+
const callExpression = expStat.getExpressionIfKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
55
|
+
if (!callExpression) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const exp = callExpression.getExpressionIfKind(ts_morph_1.SyntaxKind.Identifier);
|
|
59
|
+
const text = exp?.getText();
|
|
60
|
+
if (!TestBlocks.has(text)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
let hasUpdate = false;
|
|
64
|
+
const jsDoc = expStat.getJsDocs();
|
|
65
|
+
const aiTagWithDate = `${aiTag}-${formatDate(new Date())}`;
|
|
66
|
+
// Remove all old @aiContributed tags
|
|
67
|
+
const oldTags = jsDoc.filter(doc => doc.getInnerText().includes(aiTag) || doc.getInnerText().includes(oldAiTag));
|
|
68
|
+
if (oldTags.length > 0) {
|
|
69
|
+
oldTags.forEach(doc => doc.remove());
|
|
70
|
+
hasUpdate = true;
|
|
71
|
+
}
|
|
72
|
+
// Add the new tag with current date
|
|
73
|
+
expStat.addJsDoc(aiTagWithDate);
|
|
74
|
+
hasUpdate = true;
|
|
75
|
+
if (text === 'it') {
|
|
76
|
+
return hasUpdate;
|
|
77
|
+
}
|
|
78
|
+
const subStatements = callExpression.getDescendantsOfKind(ts_morph_1.SyntaxKind.ExpressionStatement);
|
|
79
|
+
for (const subStatement of subStatements) {
|
|
80
|
+
hasUpdate = addTagOnCase(subStatement) || hasUpdate;
|
|
81
|
+
}
|
|
82
|
+
return hasUpdate;
|
|
83
|
+
}
|
|
84
|
+
// format data to YYYY-MM-DD
|
|
85
|
+
function formatDate(date) {
|
|
86
|
+
const year = date.getFullYear();
|
|
87
|
+
const month = String(date.getMonth() + 1).padStart(2, "0"); // 月份从 0 开始
|
|
88
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
89
|
+
return `${year}-${month}-${day}`;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=tag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;IAChC,SAAS,GAAG,IAAI,CAAC;IACjB,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAChB,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,MAAM,aAAa,GAAG,cAAc,CAAC,oBAAoB,CAAC,qBAAU,CAAC,mBAAmB,CAAC,CAAC;IAC1F,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE,CAAC;QACvC,SAAS,GAAG,YAAY,CAAC,YAAY,CAAC,IAAI,SAAS,CAAC;IACxD,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAED,4BAA4B;AAC5B,SAAgB,UAAU,CAAC,IAAU;IACnC,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAChC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,WAAW;IACvE,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACpD,OAAO,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export interface TestOutput {
|
|
2
|
+
numFailedTestSuites: number;
|
|
3
|
+
numFailedTests: number;
|
|
4
|
+
numPassedTestSuites: number;
|
|
5
|
+
numPassedTests: number;
|
|
6
|
+
numPendingTestSuites: number;
|
|
7
|
+
numPendingTests: number;
|
|
8
|
+
numRuntimeErrorTestSuites: number;
|
|
9
|
+
numTodoTests: number;
|
|
10
|
+
numTotalTestSuites: number;
|
|
11
|
+
numTotalTests: number;
|
|
12
|
+
openHandles: any[];
|
|
13
|
+
snapshot: Snapshot;
|
|
14
|
+
startTime: number;
|
|
15
|
+
success: boolean;
|
|
16
|
+
testResults: TestResult[];
|
|
17
|
+
wasInterrupted: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface Snapshot {
|
|
20
|
+
added: number;
|
|
21
|
+
didUpdate: boolean;
|
|
22
|
+
failure: boolean;
|
|
23
|
+
filesAdded: number;
|
|
24
|
+
filesRemoved: number;
|
|
25
|
+
filesRemovedList: any[];
|
|
26
|
+
filesUnmatched: number;
|
|
27
|
+
filesUpdated: number;
|
|
28
|
+
matched: number;
|
|
29
|
+
total: number;
|
|
30
|
+
unchecked: number;
|
|
31
|
+
uncheckedKeysByFile: any[];
|
|
32
|
+
unmatched: number;
|
|
33
|
+
updated: number;
|
|
34
|
+
}
|
|
35
|
+
export interface TestResult {
|
|
36
|
+
assertionResults: AssertionResult[];
|
|
37
|
+
endTime: number;
|
|
38
|
+
message: string;
|
|
39
|
+
name: string;
|
|
40
|
+
startTime: number;
|
|
41
|
+
status: string;
|
|
42
|
+
summary: string;
|
|
43
|
+
}
|
|
44
|
+
export interface AssertionResult {
|
|
45
|
+
ancestorTitles: string[];
|
|
46
|
+
duration: number;
|
|
47
|
+
failureDetails: FailureDetail[];
|
|
48
|
+
failureMessages: string[];
|
|
49
|
+
fullName: string;
|
|
50
|
+
invocations: number;
|
|
51
|
+
location: any;
|
|
52
|
+
numPassingAsserts: number;
|
|
53
|
+
retryReasons: any[];
|
|
54
|
+
status: string;
|
|
55
|
+
title: string;
|
|
56
|
+
}
|
|
57
|
+
export interface FailureDetail {
|
|
58
|
+
matcherResult: MatcherResult;
|
|
59
|
+
}
|
|
60
|
+
export interface MatcherResult {
|
|
61
|
+
actual: string;
|
|
62
|
+
expected: string;
|
|
63
|
+
message: string;
|
|
64
|
+
name: string;
|
|
65
|
+
pass: boolean;
|
|
66
|
+
}
|
|
67
|
+
export interface FailedCaseDetails {
|
|
68
|
+
casePath: string;
|
|
69
|
+
errorMessage: string;
|
|
70
|
+
codeLocation?: {
|
|
71
|
+
line: number;
|
|
72
|
+
column: number;
|
|
73
|
+
};
|
|
74
|
+
expected?: string;
|
|
75
|
+
actual?: string;
|
|
76
|
+
}
|
|
77
|
+
export interface TestOptions {
|
|
78
|
+
projectFolder?: string;
|
|
79
|
+
enableCoverage?: boolean;
|
|
80
|
+
noStackTrace?: boolean;
|
|
81
|
+
abortSignal?: AbortSignal;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../src/core/valid/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACvB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;IACxB,yBAAyB,EAAE,MAAM,CAAC;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,GAAG,EAAE,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,cAAc,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,QAAQ;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,GAAG,EAAE,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd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AAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAGD,MAAM,WAAW,WAAW;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/core/valid/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitest.d.ts","sourceRoot":"","sources":["../../../src/core/valid/vitest.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AA8CjD,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CA4BzG"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runVitestAsync = runVitestAsync;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const file_1 = require("../utils/file");
|
|
10
|
+
const system_1 = require("../utils/system");
|
|
11
|
+
const console_1 = require("../utils/console");
|
|
12
|
+
const config_1 = require("../config");
|
|
13
|
+
function getCommand(file, options = {}) {
|
|
14
|
+
const { enableCoverage = false, projectFolder } = options;
|
|
15
|
+
const filePath = (0, file_1.toUnixStyle)(file);
|
|
16
|
+
const projectFolderPath = projectFolder ? (0, file_1.toUnixStyle)(projectFolder) : (0, file_1.findProjectRoot)(filePath);
|
|
17
|
+
let config = '';
|
|
18
|
+
if (projectFolderPath) {
|
|
19
|
+
const testConfigPath = (0, file_1.toUnixStyle)(path_1.default.resolve(projectFolderPath, 'vitest.config'));
|
|
20
|
+
if (fs_1.default.existsSync(testConfigPath)) {
|
|
21
|
+
config = `--config="${testConfigPath}"`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const cwd = projectFolderPath || path_1.default.dirname(filePath);
|
|
25
|
+
const randomNum = Math.floor(Math.random() * 10000);
|
|
26
|
+
const randomJsonName = `${randomNum}-vitest-result.json`;
|
|
27
|
+
const outputJsonPath = path_1.default.join(cwd, randomJsonName);
|
|
28
|
+
const params = [
|
|
29
|
+
'vitest',
|
|
30
|
+
'run',
|
|
31
|
+
'--bail=999',
|
|
32
|
+
'--reporter=json',
|
|
33
|
+
'--passWithNoTests',
|
|
34
|
+
'--silent',
|
|
35
|
+
'-u',
|
|
36
|
+
`--outputFile=${outputJsonPath}`,
|
|
37
|
+
];
|
|
38
|
+
if (enableCoverage) {
|
|
39
|
+
params.push('--coverage');
|
|
40
|
+
}
|
|
41
|
+
if (config) {
|
|
42
|
+
params.push(config);
|
|
43
|
+
}
|
|
44
|
+
params.push(filePath);
|
|
45
|
+
return {
|
|
46
|
+
params,
|
|
47
|
+
cwd,
|
|
48
|
+
outputJsonPath
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
async function runVitestAsync(file, options) {
|
|
52
|
+
const { params, cwd, outputJsonPath } = getCommand(file, options);
|
|
53
|
+
try {
|
|
54
|
+
(0, console_1.getConsole)().log(`Running Vitest\ncwd: ${cwd}\nparams: ${params.join(' ')}`);
|
|
55
|
+
const env = (0, config_1.getConfig)().common.testEnv;
|
|
56
|
+
const res = await (0, system_1.execAsync)('npx', params, {
|
|
57
|
+
cwd,
|
|
58
|
+
abortSignal: options?.abortSignal,
|
|
59
|
+
env
|
|
60
|
+
});
|
|
61
|
+
// DO NOT check res.error here, as Vitest returns is non-zero exit code even if tests pass.
|
|
62
|
+
// if (res.error) {
|
|
63
|
+
// throw new Error(`Vitest execution failed: ${res.error}`);
|
|
64
|
+
// }
|
|
65
|
+
if (!fs_1.default.existsSync(outputJsonPath)) {
|
|
66
|
+
throw new Error(`Vitest output file not found: ${outputJsonPath}`);
|
|
67
|
+
}
|
|
68
|
+
const outputContent = fs_1.default.readFileSync(outputJsonPath, 'utf8');
|
|
69
|
+
if (!outputContent) {
|
|
70
|
+
throw new Error(`Vitest output file is empty: ${outputJsonPath}`);
|
|
71
|
+
}
|
|
72
|
+
return JSON.parse(outputContent);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.error(`Error running Vitest for file ${file}:`, error);
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
(0, system_1.removeFile)(outputJsonPath);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=vitest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitest.js","sourceRoot":"","sources":["../../../src/core/valid/vitest.ts"],"names":[],"mappings":";;;;;AAiDA,wCA4BC;AA7ED,4CAAoB;AACpB,gDAAwB;AACxB,wCAA6D;AAE7D,4CAAwD;AACxD,8CAA8C;AAC9C,sCAAsC;AAEtC,SAAS,UAAU,CAAC,IAAY,EAAE,UAAuB,EAAE;IACvD,MAAM,EAAE,cAAc,GAAG,KAAK,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAC1D,MAAM,QAAQ,GAAG,IAAA,kBAAW,EAAC,IAAI,CAAC,CAAC;IACnC,MAAM,iBAAiB,GAAG,aAAa,CAAC,CAAC,CAAC,IAAA,kBAAW,EAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAA,sBAAe,EAAC,QAAQ,CAAC,CAAC;IACjG,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,iBAAiB,EAAE,CAAC;QACpB,MAAM,cAAc,GAAG,IAAA,kBAAW,EAAC,cAAI,CAA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,GAAG,IAAA,kBAAS,GAAE,CAAC,MAAM,CAAC,OAAO,CAAC;QACvC,MAAM,GAAG,GAAG,MAAM,IAAA,kBAAS,EAAC,KAAK,EAAE,MAAM,EAAE;YACvC,GAAG;YACH,WAAW,EAAE,OAAO,EAAE,WAAW;YACjC,GAAG;SACN,CAAC,CAAC;QACH,2FAA2F;QAC3F,mBAAmB;QACnB,gEAAgE;QAChE,IAAI;QACJ,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,iCAAiC,cAAc,EAAE,CAAC,CAAC;QACvE,CAAC;QACD,MAAM,aAAa,GAAG,YAAE,CAAC,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;QAC9D,IAAI,CAAC,aAAa,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,gCAAgC,cAAc,EAAE,CAAC,CAAC;QACtE,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAe,CAAC;IACnD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,iCAAiC,IAAI,GAAG,EAAE,KAAK,CAAC,CAAC;QAC/D,MAAM,KAAK,CAAC;IAChB,CAAC;YAAS,CAAC;QACP,IAAA,mBAAU,EAAC,cAAc,CAAC,CAAC;IAC/B,CAAC;AACL,CAAC"}
|
package/out/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { setup } from './setup';
|
|
2
|
+
export * from './types';
|
|
3
|
+
export { CoreConfig } from './core/config';
|
|
4
|
+
export { UTGen, UTGenOptions, GenerateResult } from './core/generate/UTGen';
|
|
5
|
+
export { LLMMessage, IGetResponse, AIResponse, Role, PromptKey, PromptPlaceholder, getPrompt, getCustomizePrompt, promptsToFiles, readPromptConfigFile } from './core/llm';
|
|
6
|
+
export { CodeType } from './core/analyze/index.type';
|
|
7
|
+
export { extractCodeFromResponse } from './core/utils/common';
|
|
8
|
+
export { findProjectRoot, toUnixStyle, getPackagesFrom, getFilesInDir } from './core/utils/file';
|
|
9
|
+
export { getConsole } from './core/utils/console';
|
|
10
|
+
export { execAsync, removeFile, sleep, getMachineId } from './core/utils/system';
|
|
11
|
+
export { getProject } from './core/utils/tsMorph';
|
|
12
|
+
export { runLint } from './core/utils/lint';
|
|
13
|
+
export { getSpecBlocks } from './core/utils/specBlock';
|
|
14
|
+
export { formatEventProps } from './core/utils/telemetry';
|
|
15
|
+
export { initializeDoc, getPackageDocInitParams } from './core/utils/msnStudio';
|
|
16
|
+
export { runTest, getFailedCase } from './core/valid';
|
|
17
|
+
export { TestOutput, FailedCaseDetails } from './core/valid/type';
|
|
18
|
+
export * from './core/constants';
|
|
19
|
+
export * from './core/features';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,cAAc,SAAS,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5E,OAAO,EACH,UAAU,EACV,YAAY,EACZ,UAAU,EACV,IAAI,EACJ,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACvB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACjG,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,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