Skip to content
This repository was archived by the owner on Jul 14, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import {
createEnvironment,
deleteEnvironment,
executeTests,
getNotifications,
getTestCase,
getTestReport,
listNotifications,
listTestCase,
listTestReport,
listEnvironments,
listPrivateLocations,
registerLocation,
unregisterLocation,
updateEnvironment,
listTestCases,
} from "./tools";
import { Config, loadConfig, saveConfig } from "./config";
import { promptUser, resolveTestTargetId } from "./helpers";
Expand Down Expand Up @@ -163,7 +164,7 @@ export const buildCmd = (): Command => {
.option("-t, --test-target-id <id>", "Test target ID")
.action(async (options) => {
const testTargetId = await resolveTestTargetId(options.testTargetId);
await getTestReport({
await listTestReport({
...options,
testTargetId,
});
Expand Down Expand Up @@ -255,7 +256,7 @@ export const buildCmd = (): Command => {
.option(
"-l, --host-network",
"Use host network (default: false). If set you can use localhost directly",
false
false,
)
.action(startPrivateLocationWorker);

Expand All @@ -272,7 +273,7 @@ export const buildCmd = (): Command => {
options.testTargetId
);
command.setOptionValue("testTargetId", resolvedTestTargetId);
void getNotifications(options);
void listNotifications(options);
});

createCommandWithCommonOptions("test-case")
Expand All @@ -284,7 +285,7 @@ export const buildCmd = (): Command => {
options.testTargetId
);
command.setOptionValue("testTargetId", resolvedTestTargetId);
void getTestCase(options);
void listTestCase(options);
});

createCommandWithCommonOptions("create-discovery")
Expand All @@ -309,5 +310,16 @@ export const buildCmd = (): Command => {
void createDiscovery(options);
});

createCommandWithCommonOptions("list-test-cases")
.description("List all test cases")
.option("-t, --test-target-id <id>", "Test target ID")
.action(async (options, command) => {
const resolvedTestTargetId = await resolveTestTargetId(
options.testTargetId,
);
command.setOptionValue("testTargetId", resolvedTestTargetId);
void listTestCases({...options, status: "ENABLED"});
});

return program;
};
5 changes: 4 additions & 1 deletion src/tools/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export const handleError = (error: ErrorResponse) => {
}
};

export const outputResult = (result: unknown): void => {
export type ListOptions = {
json?: boolean;
};
export const logJson = (result: unknown): void => {
console.log(JSON.stringify(result, null, 2));
};
8 changes: 4 additions & 4 deletions src/tools/discoveries.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { components } from "../api"; // generated by openapi-typescript
import { client, handleError, outputResult } from "./client";
import { client, handleError, ListOptions, logJson } from "./client";

export type createDiscoveryBody =
export type CreateDiscoveryBody =
components["schemas"]["ExternalDiscoveryBody"];
export type DiscoveryResponse = components["schemas"]["DiscoveryResponse"];

export const createDiscovery = async (
options: createDiscoveryBody & { json?: boolean; testTargetId: string },
options: CreateDiscoveryBody & { testTargetId: string } & ListOptions,
): Promise<void> => {
const requestBody = {
name: options.name,
Expand Down Expand Up @@ -39,7 +39,7 @@ export const createDiscovery = async (

const response = data as DiscoveryResponse;
if (options.json) {
outputResult(response);
logJson(response);
return;
}

Expand Down
62 changes: 23 additions & 39 deletions src/tools/environments.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { paths, components } from "../api"; // generated by openapi-typescript
import { client, handleError, outputResult } from "./client";
import { client, handleError, ListOptions, logJson } from "./client";

export type listEnvironmentsOptions =
export type GetEnvironmentsOptions =
paths["/apiKey/v2/test-targets/{testTargetId}/environments"]["get"]["parameters"]["path"];
export type PostEnvironmentOptions =
paths["/apiKey/v2/test-targets/{testTargetId}/environments"]["post"]["requestBody"]["content"]["application/json"] & {
Expand All @@ -12,37 +12,26 @@ export type UpdateEnvironmentOptions =
export type EnvironmentResponse = components["schemas"]["EnvironmentResponse"];

export const listEnvironments = async (
options: listEnvironmentsOptions & { json?: boolean },
options: GetEnvironmentsOptions & ListOptions,
Comment thread
mxlnk marked this conversation as resolved.
): Promise<void> => {
const { data, error } = await client.GET(
"/apiKey/v2/test-targets/{testTargetId}/environments",
{
params: {
path: { testTargetId: options.testTargetId },
},
},
);

handleError(error);
const environments = await getEnvironments(options);

if (options.json) {
outputResult(data);
logJson(environments);
return;
}

console.log("Environments:");
if (data) {
data.forEach((environment) => {
console.log(`- Name: ${environment.name}`);
console.log(` ID: ${environment.id}`);
console.log(` Discovery URL: ${environment.discoveryUrl}`);
console.log(` Updated At: ${environment.updatedAt}`);
});
}
environments.forEach((environment) => {
console.log(`- Name: ${environment.name}`);
console.log(` ID: ${environment.id}`);
console.log(` Discovery URL: ${environment.discoveryUrl}`);
console.log(` Updated At: ${environment.updatedAt}`);
});
};

export const getEnvironments = async (
options: listEnvironmentsOptions & { json?: boolean },
options: GetEnvironmentsOptions,
): Promise<EnvironmentResponse[]> => {
const { data, error } = await client.GET(
"/apiKey/v2/test-targets/{testTargetId}/environments",
Expand All @@ -59,23 +48,18 @@ export const getEnvironments = async (
throw new Error("no environments found");
}

if (options.json) {
outputResult(data);
}

return data;
};

export const createEnvironment = async (
options: PostEnvironmentOptions & {
json?: boolean;
testAccountUsername?: string;
testAccountPassword?: string;
basicAuthUsername?: string;
basicAuthPassword?: string;
privateLocationName?: string;
testAccountOtpInitializerKey?: string;
},
} & ListOptions,
): Promise<void> => {
const { data, error } = await client.POST(
"/apiKey/v2/test-targets/{testTargetId}/environments",
Expand Down Expand Up @@ -106,7 +90,7 @@ export const createEnvironment = async (
const response = data as EnvironmentResponse;

if (options.json) {
outputResult(response);
logJson(response);
return;
}

Expand All @@ -121,14 +105,13 @@ export const updateEnvironment = async (
options: UpdateEnvironmentOptions & {
testTargetId: string;
environmentId: string;
json?: boolean;
testAccountUsername?: string;
testAccountPassword?: string;
basicAuthUsername?: string;
basicAuthPassword?: string;
privateLocationName?: string;
testAccountOtpInitializerKey?: string;
},
} & ListOptions,
): Promise<void> => {
const { data, error } = await client.PATCH(
"/apiKey/v2/test-targets/{testTargetId}/environments/{environmentId}",
Expand Down Expand Up @@ -161,7 +144,7 @@ export const updateEnvironment = async (
const response = data as EnvironmentResponse;

if (options.json) {
outputResult(response);
logJson(response);
return;
}

Expand All @@ -172,11 +155,12 @@ export const updateEnvironment = async (
console.log(` Updated At: ${response.updatedAt}`);
};

export const deleteEnvironment = async (options: {
testTargetId: string;
environmentId: string;
json?: boolean;
}): Promise<void> => {
export const deleteEnvironment = async (
options: {
testTargetId: string;
environmentId: string;
} & ListOptions,
Comment thread
mxlnk marked this conversation as resolved.
): Promise<void> => {
const { error } = await client.DELETE(
"/apiKey/v2/test-targets/{testTargetId}/environments/{environmentId}",
{
Expand All @@ -192,7 +176,7 @@ export const deleteEnvironment = async (options: {
handleError(error);

if (options.json) {
outputResult({ success: true });
logJson({ success: true });
return;
}

Expand Down
10 changes: 5 additions & 5 deletions src/tools/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { paths, components } from "../api"; // generated by openapi-typescript
import { client, handleError, outputResult } from "./client";
import { client, handleError, ListOptions, logJson } from "./client";

export type getNotificationsParams =
export type GetNotificationsParams =
paths["/apiKey/v2/test-targets/{testTargetId}/notifications"]["get"]["parameters"]["path"];
export type Notification = components["schemas"]["Notification"];

export const getNotifications = async (
options: getNotificationsParams & { json?: boolean },
export const listNotifications = async (
options: GetNotificationsParams & ListOptions,
): Promise<void> => {
const { data, error } = await client.GET(
"/apiKey/v2/test-targets/{testTargetId}/notifications",
Expand All @@ -22,7 +22,7 @@ export const getNotifications = async (
handleError(error);
const response = data as Notification[];
if (options.json) {
outputResult(response);
logJson(response);
return;
}

Expand Down
13 changes: 1 addition & 12 deletions src/tools/playwright.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { client, handleError, outputResult } from "./client";
import { client, handleError } from "./client";

export const getPlaywrightConfig = async (options: {
testTargetId: string;
environmentId?: string;
url: string;
outputDir: string;
headless?: boolean;
json?: boolean;
}): Promise<string> => {
const { data, error } = await client.GET(
"/apiKey/v2/test-targets/{testTargetId}/config",
Expand All @@ -32,10 +31,6 @@ export const getPlaywrightConfig = async (options: {
throw new Error("no config found");
}

if (options.json) {
outputResult(data);
}

return data;
};

Expand All @@ -44,7 +39,6 @@ export const getPlaywrightCode = async (options: {
testCaseId: string;
environmentId?: string;
executionUrl: string;
json?: boolean;
}): Promise<string> => {
const { data, error } = await client.GET(
"/apiKey/v2/test-targets/{testTargetId}/test-cases/{testCaseId}/code",
Expand All @@ -65,13 +59,8 @@ export const getPlaywrightCode = async (options: {
handleError(error);

if (!data) {
console.log({ data, error });
throw new Error("no test code found");
}

if (options.json) {
outputResult(data);
}

return data.testCode;
};
Loading