Skip to content
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ npx @octomind/cli execute \
--test-target-id <id> \
--url <url> \
[--environment <name>] \
[--tags <list of tags>] \
[-v, --variables-to-overwrite <variables>] \
[--description <text>] \
[--tags <tags> ] \
[--json]
Expand All @@ -34,6 +36,8 @@ Options:
- `-u, --url` (required): URL to test
- `-e, --environment`: Environment name (default: "default")
- `-d, --description`: Test description
- `-g, --tags`: comma separated list of tags for tests to execute
- `-v, --variables-to-overwrite`: JSON object for variables to override for this run e.g. `{ "key": ["v1", "v2"]}`
- `-j, --json`: Output raw JSON response
- `-g, --tags <tags>`: comma separated list of tags

Expand Down
8 changes: 7 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const apiKeyOption = new Option(
"-k, --api-key <key>",
"the api key for authentication",
)
.env("API_KEY")
.env("APIKEY")
.makeOptionMandatory();

const createCommandWithCommonOptions = (command: string): Command => {
Expand All @@ -26,6 +26,7 @@ const createCommandWithCommonOptions = (command: string): Command => {
};

const splitter = (value: string): string[] => value.split(/,| /);
const toJSON = (value: string): object => JSON.parse(value);

export const buildCmd = (): Command => {
program
Expand All @@ -41,6 +42,11 @@ export const buildCmd = (): Command => {
.option("-e, --environment <name>", "Environment name", "default")
.option("-d, --description <text>", "Test description")
.option("-g, --tags <tags>", "comma separated list of tags", splitter)
.option(
"-v, --variables-to-overwrite <variables>",
"JSON object of variables to overwrite",
toJSON,
)
.action(executeTests);

createCommandWithCommonOptions("report")
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface TestTargetExecutionRequest {
context: ExecutionContext;
environmentName?: string;
tags?: string[];
variablesToOverwrite?: Record<string, string[]>;
}

export interface TestResult {
Expand Down Expand Up @@ -68,6 +69,7 @@ export interface ExecuteTestsOptions {
description?: string;
json?: boolean;
tags?: string[];
variablesToOverwrite?: Record<string, string[]>;
}

export interface GetTestReportOptions {
Expand Down
29 changes: 17 additions & 12 deletions tests/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ describe("CLI Commands parsing options", () => {

beforeAll(() => {
buildCmd();
});

it("should parse executeTests tags option with comma", () => {
program.exitOverride((err) => {
throw err;
});
});

it("should parse executeTests tags option with comma", () => {
program.parse([...stdArgs, "--tags", "tag1,tags2"]);
expect(executeTests).toHaveBeenCalledWith(
expect.objectContaining({
Expand All @@ -35,9 +35,6 @@ describe("CLI Commands parsing options", () => {
});

it("should parse executeTests tags option with space", () => {
program.exitOverride((err) => {
throw err;
});
program.parse([...stdArgs, "--tags", "tag1 tags2"]);
expect(executeTests).toHaveBeenCalledWith(
expect.objectContaining({
Expand All @@ -48,9 +45,6 @@ describe("CLI Commands parsing options", () => {
});

it("should parse executeTests tags option with |", () => {
program.exitOverride((err) => {
throw err;
});
program.parse([...stdArgs, "--tags", "tag1|tags2"]);
expect(executeTests).toHaveBeenCalledWith(
expect.objectContaining({
Expand All @@ -61,9 +55,6 @@ describe("CLI Commands parsing options", () => {
});

it("should parse executeTests tags option always as array", () => {
program.exitOverride((err) => {
throw err;
});
program.parse([...stdArgs, "--tags", "tag1"]);
expect(executeTests).toHaveBeenCalledWith(
expect.objectContaining({
Expand All @@ -72,4 +63,18 @@ describe("CLI Commands parsing options", () => {
expect.anything(),
);
});

it("should parse executeTests vars option as JSON", () => {
program.parse([
...stdArgs,
"--variables-to-overwrite",
'{ "foo": ["bar"] }',
]);
expect(executeTests).toHaveBeenCalledWith(
expect.objectContaining({
variablesToOverwrite: { foo: ["bar"] },
}),
expect.anything(),
);
});
});