Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if parameter is number before Number.parse #191

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading