@step-forge/step-forge 0.0.7-beta.6 → 0.0.7
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/.claude/settings.local.json +17 -0
- package/.eslintignore +6 -0
- package/.eslintrc +18 -0
- package/.prettierignore +6 -0
- package/.prettierrc +15 -0
- package/CHANGELOG.md +28 -0
- package/CLAUDE.md +115 -0
- package/README.md +45 -39
- package/cucumber.mjs +39 -0
- package/dist/step-forge.cjs +1 -1
- package/dist/step-forge.js +143 -120
- package/dist/types/src/builderTypeUtils.d.ts +14 -0
- package/dist/types/src/common.d.ts +32 -0
- package/dist/types/src/given.d.ts +73 -0
- package/dist/types/src/index.d.ts +5 -0
- package/dist/types/src/then.d.ts +73 -0
- package/dist/types/src/utils.d.ts +5 -0
- package/dist/types/src/when.d.ts +72 -0
- package/dist/types/src/world.d.ts +21 -0
- package/docs/assets/state_deps.gif +0 -0
- package/dts-bundle-generator.config.cjs +19 -0
- package/features/TESTING.md +100 -0
- package/features/analyzer/analyzer.feature +83 -0
- package/features/analyzer/fixtures/ambiguous-step.feature +5 -0
- package/features/analyzer/fixtures/missing-given-dep.feature +5 -0
- package/features/analyzer/fixtures/missing-multiple-deps.feature +6 -0
- package/features/analyzer/fixtures/missing-when-dep.feature +5 -0
- package/features/analyzer/fixtures/steps.ts +113 -0
- package/features/analyzer/fixtures/undefined-step.feature +5 -0
- package/features/analyzer/fixtures/undefined-with-missing-dep.feature +5 -0
- package/features/analyzer/fixtures/valid-and-but-keywords.feature +8 -0
- package/features/analyzer/fixtures/valid-deps.feature +6 -0
- package/features/analyzer/fixtures/valid-no-deps.feature +6 -0
- package/features/analyzer/fixtures/valid-optional-deps.feature +6 -0
- package/features/analyzer/fixtures/valid-variables.feature +6 -0
- package/features/basic.feature +21 -0
- package/features/exported.feature +6 -0
- package/features/steps/analyzerSteps.ts +53 -0
- package/features/steps/commonSteps.ts +93 -0
- package/features/steps/exportedSteps.ts +42 -0
- package/features/steps/world.ts +29 -0
- package/package.json +33 -26
- package/rolldown.config.mjs +34 -0
- package/src/analyzer/cli.ts +96 -0
- package/src/analyzer/gherkinParser.ts +175 -0
- package/src/analyzer/index.ts +77 -0
- package/src/analyzer/rules/ambiguousStepRule.ts +36 -0
- package/src/analyzer/rules/dependencyRule.ts +59 -0
- package/src/analyzer/rules/index.ts +23 -0
- package/src/analyzer/rules/undefinedStepRule.ts +31 -0
- package/src/analyzer/stepExtractor.ts +432 -0
- package/src/analyzer/stepMatcher.ts +67 -0
- package/src/analyzer/types.ts +55 -0
- package/src/builderTypeUtils.ts +27 -0
- package/src/common.ts +138 -0
- package/src/given.ts +102 -0
- package/src/index.ts +6 -0
- package/src/then.ts +128 -0
- package/src/utils.ts +74 -0
- package/src/when.ts +118 -0
- package/src/world.ts +90 -0
- package/test/givenCompilationTests.ts +130 -0
- package/test/testUtils.ts +30 -0
- package/test/thenCompilationTests.ts +207 -0
- package/test/whenCompilationTests.ts +157 -0
- package/ts-node-esm-register.js +8 -0
- package/tsconfig.cucumber.json +14 -0
- package/tsconfig.json +29 -0
- package/dist/types/index.d.ts +0 -301
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { thenBuilder } from "../src/then";
|
|
2
|
+
import {
|
|
3
|
+
SampleGivenState,
|
|
4
|
+
SampleThenState,
|
|
5
|
+
SampleWhenState,
|
|
6
|
+
} from "./testUtils";
|
|
7
|
+
|
|
8
|
+
// Simplest possible example
|
|
9
|
+
thenBuilder<SampleGivenState, SampleWhenState, SampleThenState>()
|
|
10
|
+
.statement("Then we should see something")
|
|
11
|
+
.step(() => {
|
|
12
|
+
return {
|
|
13
|
+
i: { j: "result" },
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// Simple dependency on given state example
|
|
18
|
+
thenBuilder<SampleGivenState, SampleWhenState, SampleThenState>()
|
|
19
|
+
.statement("Then we should see something")
|
|
20
|
+
.dependencies({
|
|
21
|
+
given: {
|
|
22
|
+
a: "required",
|
|
23
|
+
},
|
|
24
|
+
})
|
|
25
|
+
.step(({ given }) => {
|
|
26
|
+
return {
|
|
27
|
+
i: { j: `Result with ${given.a}` },
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Simple dependency on when state example
|
|
32
|
+
thenBuilder<SampleGivenState, SampleWhenState, SampleThenState>()
|
|
33
|
+
.statement("Then we should see something")
|
|
34
|
+
.dependencies({
|
|
35
|
+
when: {
|
|
36
|
+
d: "required",
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
.step(({ when }) => {
|
|
40
|
+
return {
|
|
41
|
+
i: { j: `Result with ${when.d}` },
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Simple dependency on then state example
|
|
46
|
+
thenBuilder<SampleGivenState, SampleWhenState, SampleThenState>()
|
|
47
|
+
.statement("Then we should see something")
|
|
48
|
+
.dependencies({
|
|
49
|
+
then: {
|
|
50
|
+
g: "required",
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
.step(({ then }) => {
|
|
54
|
+
return {
|
|
55
|
+
i: { j: `Result with ${then.g}` },
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Simple variables example
|
|
60
|
+
thenBuilder<SampleGivenState, SampleWhenState, SampleThenState>()
|
|
61
|
+
.statement((v1: string, v2: number) => `Then we should see ${v1} ${v2} times`)
|
|
62
|
+
.step(({ variables: [v1, v2] }) => {
|
|
63
|
+
return {
|
|
64
|
+
i: { j: `Result ${v1} ${v2}` },
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Complex example with all dependencies
|
|
69
|
+
thenBuilder<SampleGivenState, SampleWhenState, SampleThenState>()
|
|
70
|
+
.statement((v1: string, v2: number) => `Then we should see ${v1} ${v2} times`)
|
|
71
|
+
.dependencies({
|
|
72
|
+
given: {
|
|
73
|
+
a: "required",
|
|
74
|
+
b: "optional",
|
|
75
|
+
},
|
|
76
|
+
when: {
|
|
77
|
+
d: "required",
|
|
78
|
+
e: "optional",
|
|
79
|
+
},
|
|
80
|
+
then: {
|
|
81
|
+
g: "required",
|
|
82
|
+
h: "optional",
|
|
83
|
+
},
|
|
84
|
+
})
|
|
85
|
+
.step(
|
|
86
|
+
({
|
|
87
|
+
variables: [v1, v2],
|
|
88
|
+
given: { a, b },
|
|
89
|
+
when: { d, e },
|
|
90
|
+
then: { g, h },
|
|
91
|
+
}) => {
|
|
92
|
+
return {
|
|
93
|
+
i: { j: `Result ${v1} ${v2} with ${a} ${b} ${d} ${e} ${g} ${h}` },
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
// ----- Should not compile section ----
|
|
99
|
+
|
|
100
|
+
// @ts-expect-error - Should not compile without a statement
|
|
101
|
+
thenBuilder<SampleGivenState, SampleWhenState, SampleThenState>().step(() => {
|
|
102
|
+
return {
|
|
103
|
+
i: { j: "result" },
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
thenBuilder<SampleGivenState, SampleWhenState, SampleThenState>()
|
|
108
|
+
.statement(() => "Then we should see something")
|
|
109
|
+
// @ts-expect-error - Should not compile since no variables are declared
|
|
110
|
+
.step(({ variables: [v1, v2] }) => {
|
|
111
|
+
return {
|
|
112
|
+
i: { j: `Result ${v1} ${v2}` },
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
thenBuilder<SampleGivenState, SampleWhenState, SampleThenState>()
|
|
117
|
+
.statement("Then we should see something")
|
|
118
|
+
// @ts-expect-error - Should not compile since no variables are declared
|
|
119
|
+
.step(({ variables: [v1, v2] }) => {
|
|
120
|
+
return {
|
|
121
|
+
i: { j: `Result ${v1} ${v2}` },
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
thenBuilder<SampleGivenState, SampleWhenState, SampleThenState>()
|
|
126
|
+
.statement(
|
|
127
|
+
(v1: string, v2: number, v3: boolean) =>
|
|
128
|
+
`Then we should see ${v1} ${v2} ${v3}`
|
|
129
|
+
)
|
|
130
|
+
// @ts-expect-error - Should not compile since the number of variables exceeds the number declared
|
|
131
|
+
.step(({ variables: [v1, v2, v3, v4] }) => {
|
|
132
|
+
return {
|
|
133
|
+
i: { j: `Result ${v1} ${v2} ${v3} ${v4}` },
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
thenBuilder<SampleGivenState, SampleWhenState, SampleThenState>()
|
|
138
|
+
.statement("Then we should see something")
|
|
139
|
+
.dependencies({ given: { a: "required" } })
|
|
140
|
+
.step(({ given }) => {
|
|
141
|
+
return {
|
|
142
|
+
// @ts-expect-error - Should not compile if we attempt to access a part of state that was not declared as a dependency
|
|
143
|
+
i: { j: `Result ${given.b}` },
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
thenBuilder<SampleGivenState, SampleWhenState, SampleThenState>()
|
|
148
|
+
.statement("Then we should see something")
|
|
149
|
+
.dependencies({ when: { d: "required" } })
|
|
150
|
+
.step(({ when }) => {
|
|
151
|
+
return {
|
|
152
|
+
// @ts-expect-error - Should not compile if we attempt to access a part of state that was not declared as a dependency
|
|
153
|
+
i: { j: `Result ${when.f}` },
|
|
154
|
+
};
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
thenBuilder<SampleGivenState, SampleWhenState, SampleThenState>()
|
|
158
|
+
.statement("Then we should see something")
|
|
159
|
+
.dependencies({ then: { g: "required" } })
|
|
160
|
+
.step(({ then }) => {
|
|
161
|
+
return {
|
|
162
|
+
// @ts-expect-error - Should not compile if we attempt to access a part of state that was not declared as a dependency
|
|
163
|
+
i: { j: `Result ${then.i}` },
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
thenBuilder<SampleGivenState, SampleWhenState, SampleThenState>()
|
|
168
|
+
.statement("Then we should see something")
|
|
169
|
+
.dependencies({ given: { a: "optional" } })
|
|
170
|
+
.step(({ given }) => {
|
|
171
|
+
// @ts-expect-error - Should not compile since a is optional and can be undefined
|
|
172
|
+
const strictA: string = given.a;
|
|
173
|
+
return {
|
|
174
|
+
i: { j: `Result ${strictA}` },
|
|
175
|
+
};
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
thenBuilder<SampleGivenState, SampleWhenState, SampleThenState>()
|
|
179
|
+
.statement("Then we should see something")
|
|
180
|
+
.dependencies({ when: { e: "optional" } })
|
|
181
|
+
.step(({ when }) => {
|
|
182
|
+
// @ts-expect-error - Should not compile since e is optional and can be undefined
|
|
183
|
+
const strictE: string = when.e;
|
|
184
|
+
return {
|
|
185
|
+
i: { j: `Result ${strictE}` },
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
thenBuilder<SampleGivenState, SampleWhenState, SampleThenState>()
|
|
190
|
+
.statement("Then we should see something")
|
|
191
|
+
.dependencies({ then: { h: "optional" } })
|
|
192
|
+
.step(({ then }) => {
|
|
193
|
+
// @ts-expect-error - Should not compile since h is optional and can be undefined
|
|
194
|
+
const strictH: string = then.h;
|
|
195
|
+
return {
|
|
196
|
+
i: { j: `Result ${strictH}` },
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
thenBuilder<SampleGivenState, SampleWhenState, SampleThenState>()
|
|
201
|
+
.statement("Then we should see something")
|
|
202
|
+
// @ts-expect-error - Should not compile since the return type is not a partial of then state
|
|
203
|
+
.step(() => {
|
|
204
|
+
return {
|
|
205
|
+
a: "hello",
|
|
206
|
+
};
|
|
207
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { whenBuilder } from "../src/when";
|
|
2
|
+
import { SampleGivenState, SampleWhenState } from "./testUtils";
|
|
3
|
+
|
|
4
|
+
// Simplest possible example
|
|
5
|
+
whenBuilder<SampleGivenState, SampleWhenState>()
|
|
6
|
+
.statement("When a user does something")
|
|
7
|
+
.step(() => {
|
|
8
|
+
return {
|
|
9
|
+
e: "action",
|
|
10
|
+
};
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// Simple dependency on given state example
|
|
14
|
+
whenBuilder<SampleGivenState, SampleWhenState>()
|
|
15
|
+
.statement("When a user does something")
|
|
16
|
+
.dependencies({
|
|
17
|
+
given: {
|
|
18
|
+
a: "required",
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
.step(({ given }) => {
|
|
22
|
+
return {
|
|
23
|
+
e: `Action with ${given.a}`,
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Simple dependency on when state example
|
|
28
|
+
whenBuilder<SampleGivenState, SampleWhenState>()
|
|
29
|
+
.statement("When a user does something")
|
|
30
|
+
.dependencies({
|
|
31
|
+
when: {
|
|
32
|
+
d: "required",
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
.step(({ when }) => {
|
|
36
|
+
return {
|
|
37
|
+
e: `Action with ${when.d}`,
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Simple variables example
|
|
42
|
+
whenBuilder<SampleGivenState, SampleWhenState>()
|
|
43
|
+
.statement((v1: string, v2: number) => `When a user does ${v1} ${v2} times`)
|
|
44
|
+
.step(({ variables: [v1, v2] }) => {
|
|
45
|
+
return {
|
|
46
|
+
e: `Action ${v1} ${v2}`,
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Complex example with both dependencies
|
|
51
|
+
whenBuilder<SampleGivenState, SampleWhenState>()
|
|
52
|
+
.statement((v1: string, v2: number) => `When a user does ${v1} ${v2} times`)
|
|
53
|
+
.dependencies({
|
|
54
|
+
given: {
|
|
55
|
+
a: "required",
|
|
56
|
+
b: "optional",
|
|
57
|
+
},
|
|
58
|
+
when: {
|
|
59
|
+
d: "required",
|
|
60
|
+
e: "optional",
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
.step(({ variables: [v1, v2], given: { a, b }, when: { d, e } }) => {
|
|
64
|
+
return {
|
|
65
|
+
e: `Action ${v1} ${v2} with ${a} ${b} ${d} ${e}`,
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// ----- Should not compile section ----
|
|
70
|
+
|
|
71
|
+
// @ts-expect-error - Should not compile without a statement
|
|
72
|
+
whenBuilder<SampleGivenState, SampleWhenState>().step(() => {
|
|
73
|
+
return {
|
|
74
|
+
a: "action",
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
whenBuilder<SampleGivenState, SampleWhenState>()
|
|
79
|
+
.statement(() => "When a user does something")
|
|
80
|
+
// @ts-expect-error - Should not compile since no variables are declared
|
|
81
|
+
.step(({ variables: [v1, v2] }) => {
|
|
82
|
+
return {
|
|
83
|
+
a: `Action ${v1} ${v2}`,
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
whenBuilder<SampleGivenState, SampleWhenState>()
|
|
88
|
+
.statement("When a user does something")
|
|
89
|
+
// @ts-expect-error - Should not compile since no variables are declared
|
|
90
|
+
.step(({ variables: [v1, v2] }) => {
|
|
91
|
+
return {
|
|
92
|
+
a: `Action ${v1} ${v2}`,
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
whenBuilder<SampleGivenState, SampleWhenState>()
|
|
97
|
+
.statement(
|
|
98
|
+
(v1: string, v2: number, v3: boolean) =>
|
|
99
|
+
`When a user does ${v1} ${v2} ${v3}`
|
|
100
|
+
)
|
|
101
|
+
// @ts-expect-error - Should not compile since the number of variables exceeds the number declared
|
|
102
|
+
.step(({ variables: [v1, v2, v3, v4] }) => {
|
|
103
|
+
return {
|
|
104
|
+
a: `Action ${v1} ${v2} ${v3} ${v4}`,
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
whenBuilder<SampleGivenState, SampleWhenState>()
|
|
109
|
+
.statement("When a user does something")
|
|
110
|
+
.dependencies({ given: { a: "required" } })
|
|
111
|
+
.step(({ given }) => {
|
|
112
|
+
return {
|
|
113
|
+
// @ts-expect-error - Should not compile if we attempt to access a part of state that was not declared as a dependency
|
|
114
|
+
e: `Action ${given.b}`,
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
whenBuilder<SampleGivenState, SampleWhenState>()
|
|
119
|
+
.statement("When a user does something")
|
|
120
|
+
.dependencies({ when: { d: "required" } })
|
|
121
|
+
.step(({ when }) => {
|
|
122
|
+
return {
|
|
123
|
+
// @ts-expect-error - Should not compile if we attempt to access a part of state that was not declared as a dependency
|
|
124
|
+
e: `Action ${when.f}`,
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
whenBuilder<SampleGivenState, SampleWhenState>()
|
|
129
|
+
.statement("When a user does something")
|
|
130
|
+
.dependencies({ given: { a: "optional" } })
|
|
131
|
+
.step(({ given }) => {
|
|
132
|
+
// @ts-expect-error - Should not compile since a is optional and can be undefined
|
|
133
|
+
const strictA: string = given.a;
|
|
134
|
+
return {
|
|
135
|
+
e: `Action ${strictA}`,
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
whenBuilder<SampleGivenState, SampleWhenState>()
|
|
140
|
+
.statement("When a user does something")
|
|
141
|
+
.dependencies({ when: { e: "optional" } })
|
|
142
|
+
.step(({ when }) => {
|
|
143
|
+
// @ts-expect-error - Should not compile since a is optional and can be undefined
|
|
144
|
+
const strictE: string = when.e;
|
|
145
|
+
return {
|
|
146
|
+
f: [strictE.length],
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
whenBuilder<SampleGivenState, SampleWhenState>()
|
|
151
|
+
.statement("When a user does something")
|
|
152
|
+
// @ts-expect-error - Should not compile since the return type is not a partial of when state
|
|
153
|
+
.step(() => {
|
|
154
|
+
return {
|
|
155
|
+
a: "hello",
|
|
156
|
+
};
|
|
157
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"allowJs": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"allowImportingTsExtensions": true,
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"moduleDetection": "force"
|
|
11
|
+
},
|
|
12
|
+
"include": ["features/**/*.ts", "src/**/*.ts"],
|
|
13
|
+
"exclude": ["node_modules", "src/vite-env.d.ts"]
|
|
14
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"rootDir": ".",
|
|
4
|
+
"paths": {
|
|
5
|
+
"@/*": ["./src/*"],
|
|
6
|
+
"@@/*": ["./*"]
|
|
7
|
+
},
|
|
8
|
+
"target": "ESNext",
|
|
9
|
+
"useDefineForClassFields": true,
|
|
10
|
+
"module": "ESNext",
|
|
11
|
+
"lib": ["ESNext", "DOM"],
|
|
12
|
+
"moduleResolution": "Node",
|
|
13
|
+
"strict": true,
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"resolveJsonModule": true,
|
|
16
|
+
"esModuleInterop": true,
|
|
17
|
+
"noEmit": false,
|
|
18
|
+
"emitDeclarationOnly": true,
|
|
19
|
+
"noUnusedLocals": true,
|
|
20
|
+
"noUnusedParameters": true,
|
|
21
|
+
"noImplicitReturns": true,
|
|
22
|
+
"forceConsistentCasingInFileNames": true,
|
|
23
|
+
"types": ["node"],
|
|
24
|
+
"declaration": true,
|
|
25
|
+
"declarationDir": "./build/dist/types"
|
|
26
|
+
},
|
|
27
|
+
"include": ["src"],
|
|
28
|
+
"exclude": ["**/*.test.ts", "node_modules", "test/**", ".history/**"]
|
|
29
|
+
}
|