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
3 changes: 3 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,9 @@ components:
items:
$ref: "#/components/schemas/EnvironmentSimpleResponse"
description: The environments of the test target
required:
- id
- app
TestTargetUpdateRequest:
type: object
properties:
Expand Down
51 changes: 46 additions & 5 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { promptUser, resolveTestTargetId } from "./helpers";
import { runDebugtopus } from "./debugtopus";

import { startPrivateLocationWorker, stopPLW } from "./plw";
import { getTestTargets, listTestTargets } from "./tools/test-targets";

const createCommandWithCommonOptions = (command: string): Command => {
return program
Expand All @@ -30,6 +31,26 @@ const createCommandWithCommonOptions = (command: string): Command => {
const splitter = (value: string): string[] => value.split(/,| |\|/);
const toJSON = (value: string): object => JSON.parse(value);

const selectTestTarget = async (): Promise<string> => {
const testTargets = await getTestTargets();
await listTestTargets({});

if (testTargets.length === 1) {
console.log(`Only one test target found, using it: ${testTargets[0].app} (${testTargets[0].id})`);
return testTargets[0].id;
}

const testTargetIndex = await promptUser(
"Enter number of the test target you want to use (optional, press Enter to skip): "
);
const testTargetId = testTargets[Number.parseInt(testTargetIndex) - 1].id;
if (!testTargetId) {
console.log("❌ could not find a test target with the index you provided");
process.exit(1);
}

return testTargetId;
}
const testTargetIdOption = new Option("-t, --test-target-id [id]",
"Test target ID, if not provided will use the test target id from the config");

Expand Down Expand Up @@ -83,12 +104,14 @@ export const buildCmd = (): Command => {
process.exit(1);
}
}
let testTargetId;
if (!options.testTargetId) {
testTargetId = await promptUser(
"Enter test target id (optional, press Enter to skip): "
);
// saving here to be able to use the api key for the test targets
const newApiKeyConfig = {
...existingConfig,
apiKey: options.apiKey ?? apiKey,
}
await saveConfig(newApiKeyConfig);

const testTargetId = await selectTestTarget();

const newConfig: Config = {
...existingConfig,
Expand All @@ -109,6 +132,20 @@ export const buildCmd = (): Command => {
}
);

program
.command("switch-test-target")
.description("Switch to a different test target")
.action(async () => {
const testTargetId = await selectTestTarget();
const existingConfig = await loadConfig();
const newConfig: Config = {
...existingConfig,
testTargetId,
};
await saveConfig(newConfig);
console.log(`✨ Switched to test target: ${testTargetId}`);
});

createCommandWithCommonOptions("debug")
.description("run test cases against local build")
.requiredOption("-u, --url <url>", "url the tests should run against")
Expand Down Expand Up @@ -322,5 +359,9 @@ export const buildCmd = (): Command => {
void listTestCases({ ...options, status: "ENABLED" });
});

createCommandWithCommonOptions("list-test-targets")
.description("List all test targets")
.action(listTestTargets);

return program;
};
32 changes: 32 additions & 0 deletions src/tools/test-targets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { client, handleError, ListOptions, logJson } from "./client";

export const getTestTargets = async () => {
const { data, error } = await client.GET("/apiKey/v2/test-targets");

handleError(error);

if (!data) {
throw Error("No test targets found");
}

return data;
};

export const listTestTargets = async (options: ListOptions): Promise<void> => {
const testTargets = await getTestTargets();

if (options.json) {
logJson(testTargets);
return;
}

console.log("Test Targets:");
testTargets.forEach((testTarget, idx) => {
const idxString = `${idx + 1}. `.padEnd(
testTargets.length.toString().length + 2,
);
const paddingString = " ".repeat(idxString.length);
console.log(`${idxString}ID: ${testTarget.id}`);
console.log(`${paddingString}App: ${testTarget.app}`);
});
};