From 47013a350cfaa6e57bcc382a6b678e6d797c6d3d Mon Sep 17 00:00:00 2001 From: Stefan Rinke Date: Sat, 1 Mar 2025 00:13:51 +0100 Subject: [PATCH 1/3] add vars --- README.md | 4 ++++ src/cli.ts | 5 +++++ src/types.ts | 2 ++ 3 files changed, 11 insertions(+) diff --git a/README.md b/README.md index d61e048..5ddce84 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ tsx src/index.ts execute \ --test-target-id \ --url \ [--environment ] \ + [--tags ] \ + [-v, --variables-to-overwrite ] \ [--description ] \ [--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 ### Get Test Report diff --git a/src/cli.ts b/src/cli.ts index 37eb966..dba686d 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -83,6 +83,7 @@ export async function executeTests(options: ExecuteTestsOptions) { }, environmentName: options.environment, tags: options.tags, + variablesToOverwrite: options.variablesToOverwrite, }; const response = await apiCall( @@ -373,6 +374,10 @@ export function run() { .option("-e, --environment ", "Environment name", "default") .option("-d, --description ", "Test description") .option("-g --tags ", "comma separated list of tags") + .option( + "-v, --variables-to-overwrite ", + "JSON object of variables to overwrite", + ) .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 { From 1d791d5d9690a6382441d27faa4497a68f13680f Mon Sep 17 00:00:00 2001 From: Stefan Rinke Date: Sat, 1 Mar 2025 12:30:59 +0100 Subject: [PATCH 2/3] lint --- src/cli.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cli.ts b/src/cli.ts index 5a145bd..20a451b 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -14,7 +14,8 @@ import { const apiKeyOption = new Option( "-k, --api-key ", "the api key for authentication", -).env("APIKEY") +) + .env("APIKEY") .makeOptionMandatory(); const createCommandWithCommonOptions = (command: string): Command => { From 4580de7c579542eb502f990b7ee2b47bd2e0224a Mon Sep 17 00:00:00 2001 From: Stefan Rinke Date: Tue, 4 Mar 2025 11:57:59 +0100 Subject: [PATCH 3/3] json splitter test --- src/cli.ts | 2 ++ tests/cli.spec.ts | 29 +++++++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 04f6f1d..1669f8e 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -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 @@ -44,6 +45,7 @@ export const buildCmd = (): Command => { .option( "-v, --variables-to-overwrite ", "JSON object of variables to overwrite", + toJSON, ) .action(executeTests); 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(), + ); + }); });