From 918d7e19e3abee830edfbad06377a7750f1be49b Mon Sep 17 00:00:00 2001 From: Zabil Cheriya Maliackal Date: Thu, 10 Oct 2024 15:12:46 +0100 Subject: [PATCH 1/4] Check number before parsing Signed-off-by: Zabil Cheriya Maliackal --- e2e/specs/parameters.spec | 1 + e2e/tests/parameter.ts | 6 ++++++ gauge-ts/src/processors/params/PrimitiveParser.ts | 8 ++++++-- package-lock.json | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/e2e/specs/parameters.spec b/e2e/specs/parameters.spec index 64bf018..a748d97 100644 --- a/e2e/specs/parameters.spec +++ b/e2e/specs/parameters.spec @@ -7,3 +7,4 @@ ## Custom Parameters in steps * This step uses a custom parameter of type Person and value "{\"name\":\"John\",\"age\":30}" +* This step checks if strings with numbers for example "3 % 4" is correct diff --git a/e2e/tests/parameter.ts b/e2e/tests/parameter.ts index 6f32925..4c7f1b2 100644 --- a/e2e/tests/parameter.ts +++ b/e2e/tests/parameter.ts @@ -14,4 +14,10 @@ export default class Parameter { assert.strictEqual(person.age, 30); assert.ok(person.isAdult()); } + @Step( + "This step checks if strings with numbers for example is correct", + ) + async setFilter(value: string) { + assert.strictEqual(value, "3 % 4"); + } } diff --git a/gauge-ts/src/processors/params/PrimitiveParser.ts b/gauge-ts/src/processors/params/PrimitiveParser.ts index 2bd4727..fee797e 100644 --- a/gauge-ts/src/processors/params/PrimitiveParser.ts +++ b/gauge-ts/src/processors/params/PrimitiveParser.ts @@ -27,8 +27,12 @@ export class PrimitiveParser implements ParameterParser { } private convertToNumber(value: string): number | undefined { - const num = Number.parseFloat(value); - return Number.isNaN(num) ? undefined : num; + const trimmedValue = value.trim(); + if (/^-?\d+(\.\d+)?$/.test(trimmedValue)) { + const num = Number.parseFloat(trimmedValue); + return Number.isFinite(num) ? num : undefined; + } + return undefined; } private convertToBoolean(value: string): boolean | undefined { diff --git a/package-lock.json b/package-lock.json index 485f36f..d123285 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,7 @@ } }, "gauge-ts": { - "version": "0.3.3", + "version": "0.3.4", "license": "MIT", "dependencies": { "@grpc/grpc-js": "^1.10.9", From 910e6144d577e29a70ce982a64f37636ece7b429 Mon Sep 17 00:00:00 2001 From: Zabil Cheriya Maliackal Date: Thu, 10 Oct 2024 17:39:06 +0100 Subject: [PATCH 2/4] Simplify logic to exclude empty strings Signed-off-by: Zabil Cheriya Maliackal --- e2e/specs/parameters.spec | 4 ++-- e2e/tests/parameter.ts | 8 +++----- gauge-ts/src/processors/params/PrimitiveParser.ts | 9 ++++----- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/e2e/specs/parameters.spec b/e2e/specs/parameters.spec index a748d97..f20f0f2 100644 --- a/e2e/specs/parameters.spec +++ b/e2e/specs/parameters.spec @@ -6,5 +6,5 @@ ## Custom Parameters in steps -* This step uses a custom parameter of type Person and value "{\"name\":\"John\",\"age\":30}" -* This step checks if strings with numbers for example "3 % 4" is correct +* Convert custom parameter of type Person and value "{\"name\":\"John\",\"age\":30}" +* Check strings with numbers for example "3 % 4" is correct diff --git a/e2e/tests/parameter.ts b/e2e/tests/parameter.ts index 4c7f1b2..924d28e 100644 --- a/e2e/tests/parameter.ts +++ b/e2e/tests/parameter.ts @@ -8,16 +8,14 @@ export default class Parameter { assert.strictEqual(original.trim(), expected); } - @Step("This step uses a custom parameter of type Person and value ") + @Step("Convert 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()); } - @Step( - "This step checks if strings with numbers for example is correct", - ) - async setFilter(value: string) { + @Step("Check strings with numbers for example is correct") + async checkStringConversion(value: string) { assert.strictEqual(value, "3 % 4"); } } diff --git a/gauge-ts/src/processors/params/PrimitiveParser.ts b/gauge-ts/src/processors/params/PrimitiveParser.ts index fee797e..cc19c71 100644 --- a/gauge-ts/src/processors/params/PrimitiveParser.ts +++ b/gauge-ts/src/processors/params/PrimitiveParser.ts @@ -27,12 +27,11 @@ export class PrimitiveParser implements ParameterParser { } private convertToNumber(value: string): number | undefined { - const trimmedValue = value.trim(); - if (/^-?\d+(\.\d+)?$/.test(trimmedValue)) { - const num = Number.parseFloat(trimmedValue); - return Number.isFinite(num) ? num : undefined; + if (value.trim() === "") { + return undefined; } - return undefined; + const num = Number(value); + return Number.isFinite(num) ? num : undefined; } private convertToBoolean(value: string): boolean | undefined { From c880f1a32093c31d9cbb3f91033f4338a511e1ac Mon Sep 17 00:00:00 2001 From: Chad Wilson Date: Fri, 11 Oct 2024 11:08:56 +0800 Subject: [PATCH 3/4] Migrate to upload/download artifact v4 Signed-off-by: Chad Wilson --- .github/workflows/nodejs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index ffd160e..d30f86e 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -68,7 +68,7 @@ jobs: mv ./gauge-ts-*.tgz ./gauge-ts/artifacts - name: Upload artifacts for local - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v4 with: name: gauge-ts path: ./gauge-ts/artifacts @@ -93,7 +93,7 @@ jobs: npm ci npm run build - - uses: actions/download-artifact@v1 + - uses: actions/download-artifact@v4 with: name: gauge-ts path: ./artifacts From bc8872ffcfd03f3cd513bb6de436cfb59a2fb9aa Mon Sep 17 00:00:00 2001 From: Chad Wilson Date: Fri, 11 Oct 2024 11:22:36 +0800 Subject: [PATCH 4/4] Bump version Signed-off-by: Chad Wilson --- gauge-ts/package.json | 2 +- gauge-ts/ts.json | 2 +- package-lock.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gauge-ts/package.json b/gauge-ts/package.json index 3da2026..03d05be 100644 --- a/gauge-ts/package.json +++ b/gauge-ts/package.json @@ -1,6 +1,6 @@ { "name": "gauge-ts", - "version": "0.3.4", + "version": "0.3.5", "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 7d45387..48c7282 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.4", + "version": "0.3.5", "gRPCSupport": true } diff --git a/package-lock.json b/package-lock.json index d123285..d7e4580 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,7 @@ } }, "gauge-ts": { - "version": "0.3.4", + "version": "0.3.5", "license": "MIT", "dependencies": { "@grpc/grpc-js": "^1.10.9",