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
9 changes: 5 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const createCommandWithCommonOptions = (command: string): Command => {
.option("-j, --json", "Output raw JSON response");
};

export const run = (): void => {
const splitter = (value: string): string[] => value.split(/,| /);

export const buildCmd = (): Command => {
program
.name("octomind-cli")
.description(
Expand All @@ -38,7 +40,7 @@ export const run = (): void => {
.requiredOption("-u, --url <url>", "URL to test")
.option("-e, --environment <name>", "Environment name", "default")
.option("-d, --description <text>", "Test description")
.option("-g, --tags <tags>", "comma separated list of tags")
.option("-g, --tags <tags>", "comma separated list of tags", splitter)
.action(executeTests);

createCommandWithCommonOptions("report")
Expand Down Expand Up @@ -109,6 +111,5 @@ export const run = (): void => {
.requiredOption("-t, --test-target-id <id>", "Test target ID")
.requiredOption("-e, --environment-id <id>", "Environment ID")
.action(deleteEnvironment);

program.parse();
return program;
};
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env node
import { run } from "./cli";
run();
import { buildCmd } from "./cli";
const cmd = buildCmd();
cmd.parse();
75 changes: 75 additions & 0 deletions tests/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { program } from "commander";
import { buildCmd } from "../src/cli";
import { executeTests } from "../src/api";

jest.mock("../src/api");

describe("CLI Commands parsing options", () => {
const stdArgs = [
"node",
"cli.js",
"execute",
"--api-key",
"test-api-key",
"--test-target-id",
"test-target-id",
"--url",
"https://example.com",
];

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

it("should parse executeTests tags option with comma", () => {
program.exitOverride((err) => {
throw err;
});
program.parse([...stdArgs, "--tags", "tag1,tags2"]);
expect(executeTests).toHaveBeenCalledWith(
expect.objectContaining({
tags: ["tag1", "tags2"],
}),
expect.anything(),
);
});

it("should parse executeTests tags option with space", () => {
program.exitOverride((err) => {
throw err;
});
program.parse([...stdArgs, "--tags", "tag1 tags2"]);
expect(executeTests).toHaveBeenCalledWith(
expect.objectContaining({
tags: ["tag1", "tags2"],
}),
expect.anything(),
);
});

it("should parse executeTests tags option with |", () => {
program.exitOverride((err) => {
throw err;
});
program.parse([...stdArgs, "--tags", "tag1|tags2"]);
expect(executeTests).toHaveBeenCalledWith(
expect.objectContaining({
tags: ["tag1", "tags2"],
}),
expect.anything(),
);
});

it("should parse executeTests tags option always as array", () => {
program.exitOverride((err) => {
throw err;
});
program.parse([...stdArgs, "--tags", "tag1"]);
expect(executeTests).toHaveBeenCalledWith(
expect.objectContaining({
tags: ["tag1"],
}),
expect.anything(),
);
});
});