Skip to content

Commit bc7a9be

Browse files
authored
Merge pull request #191 from getgauge/fix-paramater-conversion
Check if parameter is number before Number.parse
2 parents a34fb72 + bc8872f commit bc7a9be

File tree

7 files changed

+17
-9
lines changed

7 files changed

+17
-9
lines changed

.github/workflows/nodejs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
mv ./gauge-ts-*.tgz ./gauge-ts/artifacts
6969
7070
- name: Upload artifacts for local
71-
uses: actions/upload-artifact@v1
71+
uses: actions/upload-artifact@v4
7272
with:
7373
name: gauge-ts
7474
path: ./gauge-ts/artifacts
@@ -93,7 +93,7 @@ jobs:
9393
npm ci
9494
npm run build
9595
96-
- uses: actions/download-artifact@v1
96+
- uses: actions/download-artifact@v4
9797
with:
9898
name: gauge-ts
9999
path: ./artifacts

e2e/specs/parameters.spec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66

77
## Custom Parameters in steps
88

9-
* This step uses a custom parameter of type Person and value "{\"name\":\"John\",\"age\":30}"
9+
* Convert custom parameter of type Person and value "{\"name\":\"John\",\"age\":30}"
10+
* Check strings with numbers for example "3 % 4" is correct

e2e/tests/parameter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ export default class Parameter {
88
assert.strictEqual(original.trim(), expected);
99
}
1010

11-
@Step("This step uses a custom parameter of type Person and value <person>")
11+
@Step("Convert custom parameter of type Person and value <person>")
1212
public async validatePerson(person: Person) {
1313
assert.strictEqual(person.name, "John");
1414
assert.strictEqual(person.age, 30);
1515
assert.ok(person.isAdult());
1616
}
17+
@Step("Check strings with numbers for example <value> is correct")
18+
async checkStringConversion(value: string) {
19+
assert.strictEqual(value, "3 % 4");
20+
}
1721
}

gauge-ts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gauge-ts",
3-
"version": "0.3.4",
3+
"version": "0.3.5",
44
"description": "Typescript runner for Gauge",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

gauge-ts/src/processors/params/PrimitiveParser.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ export class PrimitiveParser implements ParameterParser {
2727
}
2828

2929
private convertToNumber(value: string): number | undefined {
30-
const num = Number.parseFloat(value);
31-
return Number.isNaN(num) ? undefined : num;
30+
if (value.trim() === "") {
31+
return undefined;
32+
}
33+
const num = Number(value);
34+
return Number.isFinite(num) ? num : undefined;
3235
}
3336

3437
private convertToBoolean(value: string): boolean | undefined {

gauge-ts/ts.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
"linux": ["./launcher.mjs", "--start"],
1717
"windows": ["launcher.bat", "--start"]
1818
},
19-
"version": "0.3.4",
19+
"version": "0.3.5",
2020
"gRPCSupport": true
2121
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)