diff --git a/src/cli.ts b/src/cli.ts index 78519b6..2faa189 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -126,6 +126,7 @@ export const buildCmd = (): Command => { "--persist", "if we should write playwright config and files to current directory, you can then run 'npx playwright test' to run them again", ) + .option("--grep ", "filter test cases by substring") .action(async (options, command) => { const resolvedTestTargetId = await resolveTestTargetId( options.testTargetId, diff --git a/src/debugtopus/index.ts b/src/debugtopus/index.ts index d66c7cb..f5fb77b 100644 --- a/src/debugtopus/index.ts +++ b/src/debugtopus/index.ts @@ -19,6 +19,7 @@ type DebugtopusOptions = { environmentId?: string; headless?: boolean; persist?: boolean; + grep?: string; }; const getPackageRootLevel = (appDir: string): string => { @@ -180,20 +181,31 @@ export const runDebugtopus = async (options: DebugtopusOptions) => { }, ]; } else { - const testCases = await getTestCases(baseApiOptions); + const testCases = await getTestCases({ + ...baseApiOptions, + status: "ENABLED", + }); if (!testCases) { throw new Error("no test cases found"); } testCasesWithCode = await Promise.all( - testCases.map(async (testCase) => ({ - code: await getPlaywrightCode({ - testCaseId: testCase.id, - executionUrl: options.url, - ...baseApiOptions, - }), - ...testCase, - })), + testCases + .filter((testCase) => + options.grep + ? testCase.description + ?.toLowerCase() + .includes(options.grep.toLowerCase()) + : true, + ) + .map(async (testCase) => ({ + code: await getPlaywrightCode({ + testCaseId: testCase.id, + executionUrl: options.url, + ...baseApiOptions, + }), + ...testCase, + })), ); } diff --git a/src/tools.ts b/src/tools.ts index 18fce82..6bfec2d 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -484,7 +484,6 @@ export const getNotifications = async ( export const getTestCase = async ( options: getTestCaseParams & { json?: boolean }, ): Promise => { - console.log(options); const { data, error } = await client.GET( "/apiKey/v2/test-targets/{testTargetId}/test-cases/{testCaseId}", { @@ -662,6 +661,7 @@ export const getPlaywrightCode = async (options: { export const getTestCases = async (options: { testTargetId: string; + status?: string; json?: boolean; }): Promise => { const { data, error } = await client.GET( @@ -671,6 +671,9 @@ export const getTestCases = async (options: { path: { testTargetId: options.testTargetId, }, + query: { + filter: JSON.stringify({ status: options.status }), + }, }, }, );