From f9c747f55639ea3dec890a88f2219e1ab5c0c01e Mon Sep 17 00:00:00 2001 From: Zabil Cheriya Maliackal Date: Mon, 1 Jul 2024 14:33:05 +0100 Subject: [PATCH 1/7] Handle empty parameter conversion Signed-off-by: Zabil Cheriya Maliackal --- e2e/specs/parameters.spec | 5 +++++ e2e/tests/parameter.ts | 9 +++++++++ gauge-ts/src/processors/params/PrimitiveParser.ts | 1 + package-lock.json | 4 ++-- 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 e2e/specs/parameters.spec create mode 100644 e2e/tests/parameter.ts diff --git a/e2e/specs/parameters.spec b/e2e/specs/parameters.spec new file mode 100644 index 0000000..53dc922 --- /dev/null +++ b/e2e/specs/parameters.spec @@ -0,0 +1,5 @@ +# Paramters + +## Check parameter conversion + +* Trimmed " " is the same as "" diff --git a/e2e/tests/parameter.ts b/e2e/tests/parameter.ts new file mode 100644 index 0000000..1bdb48f --- /dev/null +++ b/e2e/tests/parameter.ts @@ -0,0 +1,9 @@ +import * as assert from "node:assert"; +import { Step } from "gauge-ts"; + +export default class Parameter { + @Step("Trimmed is the same as ") + public async checkTrimmeWord(original: string, expected: string) { + assert.strictEqual(original.trim(), expected); + } +} diff --git a/gauge-ts/src/processors/params/PrimitiveParser.ts b/gauge-ts/src/processors/params/PrimitiveParser.ts index 958a176..d6de84c 100644 --- a/gauge-ts/src/processors/params/PrimitiveParser.ts +++ b/gauge-ts/src/processors/params/PrimitiveParser.ts @@ -27,6 +27,7 @@ export class PrimitiveParser implements ParameterParser { } private convertToNumber(value: string): number | undefined { + if (value.trim() === "") return undefined; const num = Number(value); return Number.isNaN(num) ? undefined : num; } diff --git a/package-lock.json b/package-lock.json index 5e3bbef..485f36f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,8 +22,8 @@ "typescript": "^5.4.5" }, "devDependencies": { - "@getgauge/cli": "*", - "@types/node": "*", + "@getgauge/cli": "latest", + "@types/node": "latest", "taiko": "^1.4.0", "tsconfig-paths": "^4.2.0" } From 89e36aae0d7bd8e529240a9c30fe4e80ef62824e Mon Sep 17 00:00:00 2001 From: Zabil Cheriya Maliackal Date: Mon, 1 Jul 2024 14:49:20 +0100 Subject: [PATCH 2/7] Fix typo Signed-off-by: Zabil Cheriya Maliackal --- e2e/specs/parameters.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/specs/parameters.spec b/e2e/specs/parameters.spec index 53dc922..f036a96 100644 --- a/e2e/specs/parameters.spec +++ b/e2e/specs/parameters.spec @@ -1,4 +1,4 @@ -# Paramters +# Parameters ## Check parameter conversion From c5a717e2db6682bfc75bf7918939ddff7b0341ff Mon Sep 17 00:00:00 2001 From: Zabil Cheriya Maliackal Date: Mon, 1 Jul 2024 14:50:10 +0100 Subject: [PATCH 3/7] Fix function name typo Signed-off-by: Zabil Cheriya Maliackal --- e2e/tests/parameter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/tests/parameter.ts b/e2e/tests/parameter.ts index 1bdb48f..54be19d 100644 --- a/e2e/tests/parameter.ts +++ b/e2e/tests/parameter.ts @@ -3,7 +3,7 @@ import { Step } from "gauge-ts"; export default class Parameter { @Step("Trimmed is the same as ") - public async checkTrimmeWord(original: string, expected: string) { + public async checkTrimmedWord(original: string, expected: string) { assert.strictEqual(original.trim(), expected); } } From 7901702f39e13b3b577122f9ae887da4230d3fac Mon Sep 17 00:00:00 2001 From: Zabil Cheriya Maliackal Date: Mon, 1 Jul 2024 14:57:31 +0100 Subject: [PATCH 4/7] Use parse float directly Signed-off-by: Zabil Cheriya Maliackal --- gauge-ts/src/processors/params/PrimitiveParser.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gauge-ts/src/processors/params/PrimitiveParser.ts b/gauge-ts/src/processors/params/PrimitiveParser.ts index d6de84c..2bd4727 100644 --- a/gauge-ts/src/processors/params/PrimitiveParser.ts +++ b/gauge-ts/src/processors/params/PrimitiveParser.ts @@ -27,8 +27,7 @@ export class PrimitiveParser implements ParameterParser { } private convertToNumber(value: string): number | undefined { - if (value.trim() === "") return undefined; - const num = Number(value); + const num = Number.parseFloat(value); return Number.isNaN(num) ? undefined : num; } From b670f3b1ff007fbfbbe0ef8ef8cfe42224ca7625 Mon Sep 17 00:00:00 2001 From: Zabil Cheriya Maliackal Date: Mon, 1 Jul 2024 16:02:57 +0100 Subject: [PATCH 5/7] Bump version Signed-off-by: Zabil Cheriya Maliackal --- gauge-ts/package.json | 2 +- gauge-ts/ts.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gauge-ts/package.json b/gauge-ts/package.json index a0ade89..3da2026 100644 --- a/gauge-ts/package.json +++ b/gauge-ts/package.json @@ -1,6 +1,6 @@ { "name": "gauge-ts", - "version": "0.3.3", + "version": "0.3.4", "description": "Typescript runner for Gauge", "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/gauge-ts/ts.json b/gauge-ts/ts.json index 966149d..7d45387 100644 --- a/gauge-ts/ts.json +++ b/gauge-ts/ts.json @@ -16,6 +16,6 @@ "linux": ["./launcher.mjs", "--start"], "windows": ["launcher.bat", "--start"] }, - "version": "0.3.3", + "version": "0.3.4", "gRPCSupport": true } From fc99cce397ac864c21ed49c7f2c413e226722781 Mon Sep 17 00:00:00 2001 From: Zabil Cheriya Maliackal Date: Mon, 1 Jul 2024 16:18:23 +0100 Subject: [PATCH 6/7] Move all paramter tests to one spec Signed-off-by: Zabil Cheriya Maliackal --- e2e/specs/example.spec | 4 ---- e2e/specs/parameters.spec | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/e2e/specs/example.spec b/e2e/specs/example.spec index 724ac13..dd2ccc4 100644 --- a/e2e/specs/example.spec +++ b/e2e/specs/example.spec @@ -30,7 +30,3 @@ Here's a step that takes a table |Snap |1 | |GoCD |1 | |Rhythm|0 | - -## Custom Parameters in steps - -* This step uses a custom parameter of type Person and value "{\"name\":\"John\",\"age\":30}" diff --git a/e2e/specs/parameters.spec b/e2e/specs/parameters.spec index f036a96..64bf018 100644 --- a/e2e/specs/parameters.spec +++ b/e2e/specs/parameters.spec @@ -3,3 +3,7 @@ ## Check parameter conversion * Trimmed " " is the same as "" + +## Custom Parameters in steps + +* This step uses a custom parameter of type Person and value "{\"name\":\"John\",\"age\":30}" From 5c752a1360d42f41a440274dab3046dee499132e Mon Sep 17 00:00:00 2001 From: Zabil Cheriya Maliackal Date: Mon, 1 Jul 2024 16:21:14 +0100 Subject: [PATCH 7/7] Move parameter spec implementation Signed-off-by: Zabil Cheriya Maliackal --- e2e/tests/implementation.ts | 8 -------- e2e/tests/parameter.ts | 8 ++++++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/e2e/tests/implementation.ts b/e2e/tests/implementation.ts index c978761..5664481 100644 --- a/e2e/tests/implementation.ts +++ b/e2e/tests/implementation.ts @@ -2,8 +2,6 @@ import * as assert from "node:assert"; import VowelCounter from "@lib/VowelCounter"; import { DataStoreFactory, Step, type Table } from "gauge-ts"; -import type { Person } from "@lib/Person"; - export default class Implementation { static vowelsCount = (word: string): number => { const counter = DataStoreFactory.getSpecDataStore().get( @@ -36,10 +34,4 @@ export default class Implementation { ); } } - @Step("This step uses a custom parameter of type Person and value ") - public async validatePerson(person: Person) { - assert.strictEqual(person.name, "John"); - assert.strictEqual(person.age, 30); - assert.ok(person.isAdult()); - } } diff --git a/e2e/tests/parameter.ts b/e2e/tests/parameter.ts index 54be19d..6f32925 100644 --- a/e2e/tests/parameter.ts +++ b/e2e/tests/parameter.ts @@ -1,4 +1,5 @@ import * as assert from "node:assert"; +import type { Person } from "@lib/Person"; import { Step } from "gauge-ts"; export default class Parameter { @@ -6,4 +7,11 @@ export default class Parameter { public async checkTrimmedWord(original: string, expected: string) { assert.strictEqual(original.trim(), expected); } + + @Step("This step uses a custom parameter of type Person and value ") + public async validatePerson(person: Person) { + assert.strictEqual(person.name, "John"); + assert.strictEqual(person.age, 30); + assert.ok(person.isAdult()); + } }