Skip to content

Commit

Permalink
Merge pull request #191 from getgauge/fix-paramater-conversion
Browse files Browse the repository at this point in the history
Check if parameter is number before Number.parse
  • Loading branch information
zabil authored Oct 11, 2024
2 parents a34fb72 + bc8872f commit bc7a9be
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion e2e/specs/parameters.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

## Custom Parameters in steps

* This step uses a custom parameter of type Person and value "{\"name\":\"John\",\"age\":30}"
* Convert custom parameter of type Person and value "{\"name\":\"John\",\"age\":30}"
* Check strings with numbers for example "3 % 4" is correct
6 changes: 5 additions & 1 deletion e2e/tests/parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ export default class Parameter {
assert.strictEqual(original.trim(), expected);
}

@Step("This step uses a custom parameter of type Person and value <person>")
@Step("Convert custom parameter of type Person and value <person>")
public async validatePerson(person: Person) {
assert.strictEqual(person.name, "John");
assert.strictEqual(person.age, 30);
assert.ok(person.isAdult());
}
@Step("Check strings with numbers for example <value> is correct")
async checkStringConversion(value: string) {
assert.strictEqual(value, "3 % 4");
}
}
2 changes: 1 addition & 1 deletion gauge-ts/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 5 additions & 2 deletions gauge-ts/src/processors/params/PrimitiveParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ export class PrimitiveParser implements ParameterParser {
}

private convertToNumber(value: string): number | undefined {
const num = Number.parseFloat(value);
return Number.isNaN(num) ? undefined : num;
if (value.trim() === "") {
return undefined;
}
const num = Number(value);
return Number.isFinite(num) ? num : undefined;
}

private convertToBoolean(value: string): boolean | undefined {
Expand Down
2 changes: 1 addition & 1 deletion gauge-ts/ts.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"linux": ["./launcher.mjs", "--start"],
"windows": ["launcher.bat", "--start"]
},
"version": "0.3.4",
"version": "0.3.5",
"gRPCSupport": true
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bc7a9be

Please sign in to comment.