|
1 | 1 | import { listTestFiles } from "./percy-snapshot-utils/detect-test-files.js"; |
2 | | -import { testFilePathsMap } from "../lib/inmemory-store.js"; |
| 2 | +import { testFilePathsMap, storedPercyResults } from "../lib/inmemory-store.js"; |
| 3 | +import { updateFileAndStep } from "./percy-snapshot-utils/utils.js"; |
| 4 | +import { percyWebSetupInstructions } from "./sdk-utils/percy-web/handler.js"; |
3 | 5 | import crypto from "crypto"; |
4 | 6 | import { CallToolResult } from "@modelcontextprotocol/sdk/types.js"; |
5 | 7 |
|
6 | | -export async function addListTestFiles(args: any): Promise<CallToolResult> { |
7 | | - const { dirs, language, framework } = args; |
8 | | - let testFiles: string[] = []; |
9 | | - |
10 | | - if (!dirs || dirs.length === 0) { |
| 8 | +export async function addListTestFiles(): Promise<CallToolResult> { |
| 9 | + const storedResults = storedPercyResults.get(); |
| 10 | + if (!storedResults) { |
11 | 11 | throw new Error( |
12 | | - "No directories provided to add the test files. Please provide test directories to add percy snapshot commands.", |
| 12 | + "No Framework details found. Please call expandPercyVisualTesting first to fetch the framework details.", |
13 | 13 | ); |
14 | 14 | } |
15 | 15 |
|
16 | | - for (const dir of dirs) { |
17 | | - const files = await listTestFiles({ |
18 | | - language, |
19 | | - framework, |
20 | | - baseDir: dir, |
21 | | - }); |
| 16 | + const language = storedResults.detectedLanguage; |
| 17 | + const framework = storedResults.detectedTestingFramework; |
| 18 | + |
| 19 | + // Use stored paths from setUpPercy |
| 20 | + const dirs = storedResults.folderPaths; |
| 21 | + const files = storedResults.filePaths; |
| 22 | + |
| 23 | + let testFiles: string[] = []; |
| 24 | + |
| 25 | + if (files && files.length > 0) { |
22 | 26 | testFiles = testFiles.concat(files); |
23 | 27 | } |
24 | 28 |
|
| 29 | + if (dirs && dirs.length > 0) { |
| 30 | + for (const dir of dirs) { |
| 31 | + const discoveredFiles = await listTestFiles({ |
| 32 | + language, |
| 33 | + framework, |
| 34 | + baseDir: dir, |
| 35 | + }); |
| 36 | + testFiles = testFiles.concat(discoveredFiles); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + // Validate that we have at least one test file |
25 | 41 | if (testFiles.length === 0) { |
26 | | - throw new Error("No test files found"); |
| 42 | + throw new Error( |
| 43 | + "No test files found. Please provide either specific file paths (files) or directory paths (dirs) containing test files.", |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + if (testFiles.length === 1) { |
| 48 | + const result = await updateFileAndStep(testFiles[0],0,1,percyWebSetupInstructions); |
| 49 | + return { |
| 50 | + content: result, |
| 51 | + }; |
27 | 52 | } |
28 | 53 |
|
29 | | - // Generate a UUID and store the test files in memory |
| 54 | + // For multiple files, use the UUID workflow |
30 | 55 | const uuid = crypto.randomUUID(); |
31 | 56 | testFilePathsMap.set(uuid, testFiles); |
32 | 57 |
|
|
0 commit comments