diff --git a/README.md b/README.md index c180951..0479f8b 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,8 @@ npx @octomind/cli execute \ --test-target-id \ --url \ [--environment ] \ + [--tags ] \ + [-v, --variables-to-overwrite ] \ [--description ] \ [--tags ] \ [--json] @@ -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 `: comma separated list of tags diff --git a/src/cli.ts b/src/cli.ts index bfecf48..1669f8e 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -15,7 +15,7 @@ const apiKeyOption = new Option( "-k, --api-key ", "the api key for authentication", ) - .env("API_KEY") + .env("APIKEY") .makeOptionMandatory(); const createCommandWithCommonOptions = (command: string): Command => { @@ -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 @@ -41,6 +42,11 @@ export const buildCmd = (): Command => { .option("-e, --environment ", "Environment name", "default") .option("-d, --description ", "Test description") .option("-g, --tags ", "comma separated list of tags", splitter) + .option( + "-v, --variables-to-overwrite ", + "JSON object of variables to overwrite", + toJSON, + ) .action(executeTests); createCommandWithCommonOptions("report") diff --git a/src/types.ts b/src/types.ts index 7a5a7ea..cba3100 100644 --- a/src/types.ts +++ b/src/types.ts @@ -19,6 +19,7 @@ export interface TestTargetExecutionRequest { context: ExecutionContext; environmentName?: string; tags?: string[]; + variablesToOverwrite?: Record; } export interface TestResult { @@ -68,6 +69,7 @@ export interface ExecuteTestsOptions { description?: string; json?: boolean; tags?: string[]; + variablesToOverwrite?: Record; } export interface GetTestReportOptions { diff --git a/tests/cli.spec.ts b/tests/cli.spec.ts index ee53a91..31911d4 100644 --- a/tests/cli.spec.ts +++ b/tests/cli.spec.ts @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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(), + ); + }); });