From ea389a565539413d3ab4fd584190f6939b3fe089 Mon Sep 17 00:00:00 2001 From: Zabil Cheriya Maliackal Date: Fri, 14 Jun 2024 15:55:29 +0100 Subject: [PATCH] Fix tsconfig-paths loading issue (#181) * Fix tsconfig path loading bug and add tests Signed-off-by: Zabil Cheriya Maliackal * Bump version Signed-off-by: Zabil Cheriya Maliackal --------- Signed-off-by: Zabil Cheriya Maliackal --- e2e/package.json | 3 ++- e2e/src/VowelCounter.ts | 17 +++++++++++++++++ e2e/tests/implementation.ts | 14 +++++++++----- e2e/tsconfig.json | 5 ++++- gauge-ts/launcher.mjs | 3 +++ gauge-ts/package.json | 2 +- gauge-ts/ts.json | 2 +- package-lock.json | 30 +++++++++++++++++++++++++++--- 8 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 e2e/src/VowelCounter.ts diff --git a/e2e/package.json b/e2e/package.json index 532eb86..e5c1a66 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -12,6 +12,7 @@ "devDependencies": { "@getgauge/cli": "latest", "@types/node": "latest", - "taiko": "^1.4.0" + "taiko": "^1.4.0", + "tsconfig-paths": "^4.2.0" } } diff --git a/e2e/src/VowelCounter.ts b/e2e/src/VowelCounter.ts new file mode 100644 index 0000000..308fafe --- /dev/null +++ b/e2e/src/VowelCounter.ts @@ -0,0 +1,17 @@ +export default class VowelCounter { + private vowels: string[]; + + constructor(vowels: string[]) { + this.vowels = vowels; + } + + countVowels(word: string): number { + let count = 0; + for (const char of word) { + if (this.vowels.includes(char.toLowerCase())) { + count++; + } + } + return count; + } +} diff --git a/e2e/tests/implementation.ts b/e2e/tests/implementation.ts index 6b7dac1..139debe 100644 --- a/e2e/tests/implementation.ts +++ b/e2e/tests/implementation.ts @@ -1,17 +1,21 @@ import * as assert from "node:assert"; +import VowelCounter from "@lib/VowelCounter"; import { DataStoreFactory, Step, type Table } from "gauge-ts"; class Implementation { static vowelsCount = (word: string): number => { - const vowels = DataStoreFactory.getSpecDataStore().get( - "vowels", - ) as string[]; - return word.split("").filter((c) => vowels.includes(c)).length; + const counter = DataStoreFactory.getSpecDataStore().get( + "counter", + ) as VowelCounter; + return counter.countVowels(word); }; @Step("Vowels in English language are .") public async listVowels(vowels: string) { - DataStoreFactory.getSpecDataStore().put("vowels", vowels.split("")); + DataStoreFactory.getSpecDataStore().put( + "counter", + new VowelCounter(vowels.split("")), + ); } @Step("The word has <3> vowels.") diff --git a/e2e/tsconfig.json b/e2e/tsconfig.json index 0e534a9..7bfb7c6 100644 --- a/e2e/tsconfig.json +++ b/e2e/tsconfig.json @@ -7,7 +7,10 @@ "strict": true, "moduleResolution": "node", "experimentalDecorators": true, - "emitDecoratorMetadata": true + "emitDecoratorMetadata": true, + "paths": { + "@lib/*": ["./src/*"] + } }, "include": ["tests/**/*", "gen/**/*"], "exclude": ["node_modules/"] diff --git a/gauge-ts/launcher.mjs b/gauge-ts/launcher.mjs index 852fc38..234e07f 100755 --- a/gauge-ts/launcher.mjs +++ b/gauge-ts/launcher.mjs @@ -1,5 +1,8 @@ #!/usr/bin/env node +import { createRequire } from "node:module"; +const require = createRequire(import.meta.url); + const version = process.versions.node.split("."); if (Number.parseInt(version[0]) < 20) { throw new Error( diff --git a/gauge-ts/package.json b/gauge-ts/package.json index 1692ee6..7a413ec 100644 --- a/gauge-ts/package.json +++ b/gauge-ts/package.json @@ -1,6 +1,6 @@ { "name": "gauge-ts", - "version": "0.3.1", + "version": "0.3.2", "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 9ee8798..56631e8 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.1", + "version": "0.3.2", "gRPCSupport": true } diff --git a/package-lock.json b/package-lock.json index 46b11ed..0d937dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,9 +22,10 @@ "typescript": "^5.4.5" }, "devDependencies": { - "@getgauge/cli": "*", - "@types/node": "*", - "taiko": "^1.4.0" + "@getgauge/cli": "latest", + "@types/node": "latest", + "taiko": "^1.4.0", + "tsconfig-paths": "^4.2.0" } }, "gauge-ts": { @@ -8097,6 +8098,29 @@ } } }, + "node_modules/tsconfig-paths": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.2.0.tgz", + "integrity": "sha512-NoZ4roiN7LnbKn9QqE1amc9DJfzvZXxF4xDavcOWt1BPkdx+m+0gJuPM+S0vCe7zTJMYUP0R8pO2XMr+Y8oLIg==", + "dev": true, + "dependencies": { + "json5": "^2.2.2", + "minimist": "^1.2.6", + "strip-bom": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/tsconfig-paths/node_modules/strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/tslib": { "version": "2.6.3", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.3.tgz",