@letsrunit/gherkin 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Gherkin Package (`@letsrunit/gherkin`)
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ npm install @letsrunit/gherkin
7
+ # or
8
+ yarn add @letsrunit/gherkin
9
+ ```
10
+
11
+ Utilities for parsing and manipulating Gherkin documents. It provides models and functions to work with features, scenarios, and steps.
12
+
13
+ ## Exported Functions
14
+
15
+ ### `makeFeature(feature)`
16
+
17
+ Generates a formatted Gherkin string from a `Feature` object.
18
+
19
+ - **`feature`**: An object containing `name`, `description`, `comments`, `background`, and `steps`.
20
+
21
+ ### `parseFeature(input)`
22
+
23
+ Parses a Gherkin string (or just a list of steps) into a `Feature` object. It handles full features as well as partial scenarios.
24
+
25
+ ### `deltaSteps(steps, newSteps)`
26
+
27
+ Calculates the difference between two sets of steps, returning only the `newSteps` that are not part of the trailing overlap of the original `steps`. Useful for iterative generation.
28
+
29
+ ### `sanitizeStepDefinition(expression)`
30
+
31
+ Cleans up a step definition expression, removing leading keywords (Given, When, Then, etc.) and normalizing whitespace.
32
+
33
+ ## Exported Types
34
+
35
+ - **`Feature`**: Interface representing a Gherkin feature.
36
+ - **`ParameterTypeDefinition<T>`**: Interface for defining custom Cucumber parameter types.
37
+
38
+ ## Testing
39
+
40
+ Run tests for this package:
41
+
42
+ ```bash
43
+ yarn test
44
+ ```
@@ -0,0 +1,39 @@
1
+ import { Scalar } from '@letsrunit/utils';
2
+
3
+ type Modifier = 'Control' | 'Shift' | 'Alt' | 'Meta';
4
+ type Key = Modifier | 'Enter' | 'Escape' | 'Tab' | 'Backspace' | 'Delete' | 'Space' | 'ArrowUp' | 'ArrowDown' | 'ArrowLeft' | 'ArrowRight' | 'PageUp' | 'PageDown' | 'Home' | 'End' | `F${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12}`;
5
+ type KeyCombo = {
6
+ /** Modifiers pressed and held before the final key. */
7
+ modifiers: Modifier[];
8
+ /** The final key to press (e.g. 'Enter', 'S', 'ArrowUp', 'F5', etc.). */
9
+ key: Key | string;
10
+ };
11
+
12
+ interface ParameterTypeDefinition<T> {
13
+ name: string;
14
+ placeholder: string;
15
+ regexp: readonly RegExp[] | readonly string[] | RegExp | string;
16
+ transformer?: (...match: string[]) => T;
17
+ useForSnippets?: boolean;
18
+ preferForRegexpMatch?: boolean;
19
+ }
20
+ declare function booleanParameter(trueValue: string, falseValue: string, regexp?: RegExp): ParameterTypeDefinition<boolean>;
21
+ declare function enumParameter<const T extends readonly string[]>(values: T, regexp?: RegExp): ParameterTypeDefinition<T[number]>;
22
+ declare function valueParameter(name?: string): ParameterTypeDefinition<Scalar | Scalar[]>;
23
+ declare function locatorParameter(name?: string): ParameterTypeDefinition<string>;
24
+ declare function keysParameter(name?: string): ParameterTypeDefinition<KeyCombo>;
25
+
26
+ interface Feature {
27
+ name?: string;
28
+ description?: string;
29
+ comments?: string;
30
+ background?: string[];
31
+ steps: string[];
32
+ }
33
+ declare function makeFeature({ name, description, comments, background, steps }: Feature): string;
34
+ declare function parseFeature(input: string): Feature;
35
+ declare function deltaSteps(steps: string[], newSteps: string[]): string[];
36
+
37
+ declare function sanitizeStepDefinition<T extends string | RegExp>(step: T): T;
38
+
39
+ export { type Feature, type KeyCombo, type ParameterTypeDefinition, booleanParameter, deltaSteps, enumParameter, keysParameter, locatorParameter, makeFeature, parseFeature, sanitizeStepDefinition, valueParameter };