@step-forge/step-forge 0.0.6 → 0.0.7-beta.1
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/dist/step-forge.js +212 -0
- package/package.json +9 -8
- package/.eslintignore +0 -6
- package/.eslintrc +0 -18
- package/.prettierignore +0 -6
- package/.prettierrc +0 -15
- package/CHANGELOG.md +0 -28
- package/cucumber.mjs +0 -38
- package/docs/assets/state_deps.gif +0 -0
- package/dts-bundle-generator.config.ts +0 -11
- package/features/basic.feature +0 -21
- package/features/exported.feature +0 -6
- package/features/steps/commonSteps.ts +0 -93
- package/features/steps/exportedSteps.ts +0 -42
- package/features/steps/world.ts +0 -29
- package/src/builderTypeUtils.js +0 -2
- package/src/builderTypeUtils.js.map +0 -1
- package/src/builderTypeUtils.ts +0 -27
- package/src/common.js +0 -73
- package/src/common.js.map +0 -1
- package/src/common.ts +0 -138
- package/src/given.js +0 -34
- package/src/given.js.map +0 -1
- package/src/given.ts +0 -102
- package/src/index.js +0 -6
- package/src/index.js.map +0 -1
- package/src/index.ts +0 -6
- package/src/then.js +0 -34
- package/src/then.js.map +0 -1
- package/src/then.ts +0 -128
- package/src/utils.js +0 -54
- package/src/utils.js.map +0 -1
- package/src/utils.ts +0 -74
- package/src/vite-env.d.ts.old +0 -1
- package/src/when.js +0 -34
- package/src/when.js.map +0 -1
- package/src/when.ts +0 -118
- package/src/world.js +0 -51
- package/src/world.js.map +0 -1
- package/src/world.ts +0 -90
- package/test/givenCompilationTests.ts +0 -130
- package/test/testUtils.ts +0 -30
- package/test/thenCompilationTests.ts +0 -207
- package/test/whenCompilationTests.ts +0 -157
- package/ts-node-esm-register.js +0 -8
- package/tsconfig.cucumber.json +0 -23
- package/tsconfig.json +0 -28
- package/vite.config.ts +0 -36
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
var z = Object.defineProperty;
|
|
2
|
+
var B = (n, e, t) => e in n ? z(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var o = (n, e, t) => B(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { Then as A, When as C, Given as M } from "@cucumber/cucumber";
|
|
5
|
+
import c from "lodash";
|
|
6
|
+
const a = (n) => typeof n == "string", j = (n, e) => (n.forEach((t) => {
|
|
7
|
+
if (!e.given[t])
|
|
8
|
+
throw new Error(`Key ${String(t)} is required in given state`);
|
|
9
|
+
}), n.reduce(
|
|
10
|
+
(t, r) => ({
|
|
11
|
+
...t,
|
|
12
|
+
[r]: e.given[r]
|
|
13
|
+
}),
|
|
14
|
+
{}
|
|
15
|
+
)), N = (n, e) => (n.forEach((t) => {
|
|
16
|
+
if (!e.when[t])
|
|
17
|
+
throw new Error(`Key ${String(t)} is required in when state`);
|
|
18
|
+
}), n.reduce(
|
|
19
|
+
(t, r) => ({
|
|
20
|
+
...t,
|
|
21
|
+
[r]: e.when[r]
|
|
22
|
+
}),
|
|
23
|
+
{}
|
|
24
|
+
)), P = (n, e) => (n.forEach((t) => {
|
|
25
|
+
if (!e.then[t])
|
|
26
|
+
throw new Error(`Key ${String(t)} is required in then state`);
|
|
27
|
+
}), n.reduce(
|
|
28
|
+
(t, r) => ({
|
|
29
|
+
...t,
|
|
30
|
+
[r]: e.then[r]
|
|
31
|
+
}),
|
|
32
|
+
{}
|
|
33
|
+
)), x = (n) => {
|
|
34
|
+
const e = parseInt(n, 10);
|
|
35
|
+
return isNaN(e) ? n === "true" ? !0 : n === "false" ? !1 : n : e;
|
|
36
|
+
}, I = {
|
|
37
|
+
given: M,
|
|
38
|
+
when: C,
|
|
39
|
+
then: A
|
|
40
|
+
}, h = (n, e, t = {
|
|
41
|
+
given: {},
|
|
42
|
+
when: {},
|
|
43
|
+
then: {}
|
|
44
|
+
}) => (r) => {
|
|
45
|
+
const s = n, {
|
|
46
|
+
given: g,
|
|
47
|
+
when: d,
|
|
48
|
+
then: w
|
|
49
|
+
} = t;
|
|
50
|
+
return {
|
|
51
|
+
statement: n,
|
|
52
|
+
dependencies: t,
|
|
53
|
+
stepType: e,
|
|
54
|
+
stepFunction: r,
|
|
55
|
+
register: () => {
|
|
56
|
+
const f = s.length, m = Array.from({ length: f }, () => "{string}"), v = s(...m), l = Object.defineProperty(
|
|
57
|
+
async function(...p) {
|
|
58
|
+
const q = p.map(x), F = Object.entries(g ?? {}).filter(([, i]) => i === "required").map(([i]) => i), D = j(
|
|
59
|
+
F,
|
|
60
|
+
this
|
|
61
|
+
), O = {
|
|
62
|
+
...c.pick(this.given, Object.keys(g ?? {})),
|
|
63
|
+
...D
|
|
64
|
+
}, E = Object.entries(d ?? {}).filter(([, i]) => i === "required").map(([i]) => i), K = N(
|
|
65
|
+
E,
|
|
66
|
+
this
|
|
67
|
+
), W = {
|
|
68
|
+
...c.pick(this.when, Object.keys(d ?? {})),
|
|
69
|
+
...K
|
|
70
|
+
}, b = Object.entries(w ?? {}).filter(([, i]) => i === "required").map(([i]) => i), G = P(
|
|
71
|
+
b,
|
|
72
|
+
this
|
|
73
|
+
), $ = {
|
|
74
|
+
...c.pick(this.then, Object.keys(w ?? {})),
|
|
75
|
+
...G
|
|
76
|
+
}, y = await r({
|
|
77
|
+
variables: q,
|
|
78
|
+
given: O,
|
|
79
|
+
when: W,
|
|
80
|
+
then: $
|
|
81
|
+
});
|
|
82
|
+
this[e].merge({
|
|
83
|
+
...y
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
"length",
|
|
87
|
+
{ value: f, configurable: !0 }
|
|
88
|
+
), S = I[e];
|
|
89
|
+
return S(v, l), {
|
|
90
|
+
stepType: e,
|
|
91
|
+
dependencies: t,
|
|
92
|
+
statement: s,
|
|
93
|
+
stepFunction: r
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}, _ = (n, e) => (t) => {
|
|
98
|
+
const r = {
|
|
99
|
+
...t,
|
|
100
|
+
when: {},
|
|
101
|
+
then: {}
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
step: h(n, e, r)
|
|
105
|
+
};
|
|
106
|
+
}, H = (n) => (e) => {
|
|
107
|
+
let t;
|
|
108
|
+
a(e) ? t = () => e : t = e;
|
|
109
|
+
const r = _(t, n), s = h(t, n);
|
|
110
|
+
return {
|
|
111
|
+
dependencies: r,
|
|
112
|
+
step: s
|
|
113
|
+
};
|
|
114
|
+
}, Z = () => ({
|
|
115
|
+
statement: H("given")
|
|
116
|
+
}), J = (n, e) => (t) => {
|
|
117
|
+
const r = {
|
|
118
|
+
given: t.given ?? {},
|
|
119
|
+
when: t.when ?? {},
|
|
120
|
+
then: {}
|
|
121
|
+
};
|
|
122
|
+
return {
|
|
123
|
+
step: h(n, e, r)
|
|
124
|
+
};
|
|
125
|
+
}, L = (n) => (e) => {
|
|
126
|
+
let t;
|
|
127
|
+
a(e) ? t = () => e : t = e;
|
|
128
|
+
const r = J(t, n), s = h(t, n);
|
|
129
|
+
return {
|
|
130
|
+
dependencies: r,
|
|
131
|
+
step: s
|
|
132
|
+
};
|
|
133
|
+
}, T = () => ({
|
|
134
|
+
statement: L("when")
|
|
135
|
+
}), Q = (n, e) => (t) => {
|
|
136
|
+
const r = {
|
|
137
|
+
given: t.given ?? {},
|
|
138
|
+
when: t.when ?? {},
|
|
139
|
+
then: t.then ?? {}
|
|
140
|
+
};
|
|
141
|
+
return {
|
|
142
|
+
step: h(n, e, r)
|
|
143
|
+
};
|
|
144
|
+
}, R = (n) => (e) => {
|
|
145
|
+
let t;
|
|
146
|
+
a(e) ? t = () => e : t = e;
|
|
147
|
+
const r = Q(t, n), s = h(t, n);
|
|
148
|
+
return {
|
|
149
|
+
dependencies: r,
|
|
150
|
+
step: s
|
|
151
|
+
};
|
|
152
|
+
}, k = () => ({
|
|
153
|
+
statement: R("then")
|
|
154
|
+
});
|
|
155
|
+
function u(n, e) {
|
|
156
|
+
if (c.isArray(n))
|
|
157
|
+
return n.concat(e);
|
|
158
|
+
if (n && !c.isPlainObject(n) && n !== e)
|
|
159
|
+
throw new Error(
|
|
160
|
+
`Merge would have destroyed previous value ${n} with ${e}`
|
|
161
|
+
);
|
|
162
|
+
return n;
|
|
163
|
+
}
|
|
164
|
+
class V {
|
|
165
|
+
constructor() {
|
|
166
|
+
o(this, "givenState", {});
|
|
167
|
+
o(this, "whenState", {});
|
|
168
|
+
o(this, "thenState", {});
|
|
169
|
+
}
|
|
170
|
+
get given() {
|
|
171
|
+
return {
|
|
172
|
+
...this.givenState,
|
|
173
|
+
merge: (e) => {
|
|
174
|
+
this.givenState = c.merge(
|
|
175
|
+
{ ...this.givenState },
|
|
176
|
+
e,
|
|
177
|
+
u
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
get when() {
|
|
183
|
+
return {
|
|
184
|
+
...this.whenState,
|
|
185
|
+
merge: (e) => {
|
|
186
|
+
this.whenState = c.merge(
|
|
187
|
+
{ ...this.whenState },
|
|
188
|
+
e,
|
|
189
|
+
u
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
get then() {
|
|
195
|
+
return {
|
|
196
|
+
...this.thenState,
|
|
197
|
+
merge: (e) => {
|
|
198
|
+
this.thenState = c.merge(
|
|
199
|
+
{ ...this.thenState },
|
|
200
|
+
e,
|
|
201
|
+
u
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
export {
|
|
208
|
+
V as BasicWorld,
|
|
209
|
+
Z as givenBuilder,
|
|
210
|
+
k as thenBuilder,
|
|
211
|
+
T as whenBuilder
|
|
212
|
+
};
|
package/package.json
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@step-forge/step-forge",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"module": "./dist/step-forge.js",
|
|
3
|
+
"version": "0.0.7-beta.1",
|
|
5
4
|
"type": "module",
|
|
6
5
|
"exports": {
|
|
7
6
|
".": {
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"import": "./dist/"
|
|
7
|
+
"types": "./dist/types/index.d.ts",
|
|
8
|
+
"import": "./dist/step-forge.js",
|
|
9
|
+
"default": "./dist/step-forge.js"
|
|
12
10
|
}
|
|
13
11
|
},
|
|
14
|
-
"types": "./dist/index.d.ts",
|
|
12
|
+
"types": "./dist/types/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
15
16
|
"scripts": {
|
|
16
17
|
"dev": "vite --host",
|
|
17
|
-
"build": "rimraf
|
|
18
|
+
"build": "rimraf dist && tsc --emitDeclarationOnly --outDir dist/types && vite build && dts-bundle-generator --config ./dts-bundle-generator.config.ts",
|
|
18
19
|
"test:cucumber": "NODE_ENV=test NODE_OPTIONS=\"--experimental-specifier-resolution=node --loader ts-node/esm\" TS_NODE_PROJECT=./tsconfig.cucumber.json cucumber-js -p default",
|
|
19
20
|
"test:ci": "NODE_ENV=test cucumber-js -p ci",
|
|
20
21
|
"test": "NODE_ENV=test PORT=7888 LOG_LEVEL=none cucumber-js -p all 2> /dev/null",
|
package/.eslintignore
DELETED
package/.eslintrc
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"root": true,
|
|
3
|
-
"parser": "@typescript-eslint/parser",
|
|
4
|
-
"plugins": ["@typescript-eslint", "prettier"],
|
|
5
|
-
"extends": [
|
|
6
|
-
"eslint:recommended",
|
|
7
|
-
"plugin:@typescript-eslint/eslint-recommended",
|
|
8
|
-
"plugin:@typescript-eslint/recommended",
|
|
9
|
-
"prettier"
|
|
10
|
-
],
|
|
11
|
-
"env": {
|
|
12
|
-
"browser": true,
|
|
13
|
-
"node": true
|
|
14
|
-
},
|
|
15
|
-
"rules": {
|
|
16
|
-
"prettier/prettier": "error"
|
|
17
|
-
}
|
|
18
|
-
}
|
package/.prettierignore
DELETED
package/.prettierrc
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"printWidth": 80,
|
|
3
|
-
"tabWidth": 2,
|
|
4
|
-
"singleQuote": false,
|
|
5
|
-
"trailingComma": "es5",
|
|
6
|
-
"arrowParens": "avoid",
|
|
7
|
-
"bracketSpacing": true,
|
|
8
|
-
"useTabs": false,
|
|
9
|
-
"endOfLine": "auto",
|
|
10
|
-
"singleAttributePerLine": false,
|
|
11
|
-
"bracketSameLine": false,
|
|
12
|
-
"jsxSingleQuote": false,
|
|
13
|
-
"quoteProps": "as-needed",
|
|
14
|
-
"semi": true
|
|
15
|
-
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to the "@step-forge/step-forge" project will be documented in this file.
|
|
4
|
-
|
|
5
|
-
## [0.0.5] - 2024-12-31
|
|
6
|
-
|
|
7
|
-
- Add support for exporting steps
|
|
8
|
-
|
|
9
|
-
## [0.0.4] - 2024-07-30
|
|
10
|
-
|
|
11
|
-
- Update all packages to the latest versions
|
|
12
|
-
- Remove support for CommonJS modules
|
|
13
|
-
|
|
14
|
-
## [0.0.3] - 2024-01-23
|
|
15
|
-
|
|
16
|
-
- Update all packages to the latest versions (update to vite 5.x)
|
|
17
|
-
|
|
18
|
-
## [0.0.2] - 2023-01-18
|
|
19
|
-
|
|
20
|
-
- Update all packages to the latest versions (update to vite 4.x)
|
|
21
|
-
|
|
22
|
-
## [0.0.1] - 2022-09-08
|
|
23
|
-
|
|
24
|
-
- Update all packages to the latest versions (update to vite 3.x)
|
|
25
|
-
|
|
26
|
-
## [0.0.0] - 2022-03-28
|
|
27
|
-
|
|
28
|
-
- Initial release
|
package/cucumber.mjs
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
const defaultProfile = {
|
|
2
|
-
format: [
|
|
3
|
-
process.env.CI || !process.stdout.isTTY ? "progress" : "progress-bar",
|
|
4
|
-
"json:./reports/cucumber-json-reports/report.json",
|
|
5
|
-
"rerun:./reports/cucumber/@rerun.txt",
|
|
6
|
-
"usage:./reports/cucumber/usage.txt",
|
|
7
|
-
],
|
|
8
|
-
parallel: 1,
|
|
9
|
-
importModule: ["ts-node/esm", "tsconfig-paths/register"],
|
|
10
|
-
import: [
|
|
11
|
-
"./features/steps/**/*.ts",
|
|
12
|
-
"./features/steps/*.ts",
|
|
13
|
-
"./src/**/*.ts",
|
|
14
|
-
],
|
|
15
|
-
strict: false,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const ciProfile = {
|
|
19
|
-
format: [
|
|
20
|
-
process.env.CI || !process.stdout.isTTY ? "progress" : "progress-bar",
|
|
21
|
-
"json:./reports/cucumber-json-reports/report.json",
|
|
22
|
-
"rerun:./reports/cucumber/@rerun.txt",
|
|
23
|
-
"usage:./reports/cucumber/usage.txt",
|
|
24
|
-
],
|
|
25
|
-
parallel: 1,
|
|
26
|
-
importModule: ["ts-node/register/transpile-only", "tsconfig-paths/register"],
|
|
27
|
-
import: ["./features/steps/**/*.ts", "./features/steps/*.ts"],
|
|
28
|
-
strict: false,
|
|
29
|
-
publish: true,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const all = {
|
|
33
|
-
...defaultProfile,
|
|
34
|
-
paths: ["./features"],
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export { ciProfile as ci, all };
|
|
38
|
-
export default defaultProfile;
|
|
Binary file
|
package/features/basic.feature
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
Feature: Steps written in gherkin can be matched to Step Forge steps
|
|
2
|
-
|
|
3
|
-
Scenario: Basic feature steps with no dependencies or variables can be run as a cucumber scenario
|
|
4
|
-
Given I started
|
|
5
|
-
When I got here
|
|
6
|
-
Then everything was good
|
|
7
|
-
|
|
8
|
-
Scenario: Basic feature steps with dependencies can be run as a cucumber scenario
|
|
9
|
-
Given a user
|
|
10
|
-
When I save the user
|
|
11
|
-
Then there is a user
|
|
12
|
-
|
|
13
|
-
Scenario: Basic feature steps with variables can be run as a cucumber scenario
|
|
14
|
-
Given a user named "John"
|
|
15
|
-
When I save the user
|
|
16
|
-
Then there is a user
|
|
17
|
-
|
|
18
|
-
Scenario: Basic feature steps with dependencies and variables can be run as a cucumber scenario
|
|
19
|
-
Given a user
|
|
20
|
-
When I name the user "John"
|
|
21
|
-
Then the user's name is "John"
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { givenBuilder } from "../../src/given";
|
|
2
|
-
import { whenBuilder } from "../../src/when";
|
|
3
|
-
import { thenBuilder } from "../../src/then";
|
|
4
|
-
import { GivenState, ThenState, WhenState } from "./world";
|
|
5
|
-
import { expect } from "earl";
|
|
6
|
-
|
|
7
|
-
// --- No dependency no variable steps --- //
|
|
8
|
-
givenBuilder<GivenState>()
|
|
9
|
-
.statement("I started")
|
|
10
|
-
.step(() => ({}))
|
|
11
|
-
.register();
|
|
12
|
-
|
|
13
|
-
whenBuilder<GivenState, WhenState>()
|
|
14
|
-
.statement("I got here")
|
|
15
|
-
.step(() => ({}))
|
|
16
|
-
.register();
|
|
17
|
-
|
|
18
|
-
thenBuilder<GivenState, WhenState, ThenState>()
|
|
19
|
-
.statement("everything was good")
|
|
20
|
-
.step(() => ({}))
|
|
21
|
-
.register();
|
|
22
|
-
|
|
23
|
-
// --- Dependency only steps --- //
|
|
24
|
-
givenBuilder<GivenState>()
|
|
25
|
-
.statement("a user")
|
|
26
|
-
.step(() => {
|
|
27
|
-
return {
|
|
28
|
-
user: {
|
|
29
|
-
type: "person",
|
|
30
|
-
token: "random",
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
})
|
|
34
|
-
.register();
|
|
35
|
-
|
|
36
|
-
whenBuilder<GivenState, WhenState>()
|
|
37
|
-
.statement("I save the user")
|
|
38
|
-
.dependencies({ given: { user: "required" } })
|
|
39
|
-
.step(({ given: { user } }) => {
|
|
40
|
-
return {
|
|
41
|
-
user: {
|
|
42
|
-
...user,
|
|
43
|
-
saved: true,
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
})
|
|
47
|
-
.register();
|
|
48
|
-
|
|
49
|
-
thenBuilder<GivenState, WhenState, ThenState>()
|
|
50
|
-
.statement("there is a user")
|
|
51
|
-
.dependencies({ when: { user: "required" } })
|
|
52
|
-
.step(({ when: { user } }) => {
|
|
53
|
-
expect(user.saved).toBeTruthy();
|
|
54
|
-
})
|
|
55
|
-
.register();
|
|
56
|
-
|
|
57
|
-
// --- Variable only steps --- //
|
|
58
|
-
givenBuilder<GivenState>()
|
|
59
|
-
.statement((userName: string) => `a user named ${userName}`)
|
|
60
|
-
.step(({ variables: [userName] }) => {
|
|
61
|
-
return {
|
|
62
|
-
user: {
|
|
63
|
-
type: "person",
|
|
64
|
-
token: userName,
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
})
|
|
68
|
-
.register();
|
|
69
|
-
|
|
70
|
-
// --- More complex steps --- //
|
|
71
|
-
|
|
72
|
-
whenBuilder<GivenState, WhenState>()
|
|
73
|
-
.statement((userName: string) => `I name the user ${userName}`)
|
|
74
|
-
.dependencies({ given: { user: "required" } })
|
|
75
|
-
.step(({ given: { user }, variables: [userName] }) => {
|
|
76
|
-
return {
|
|
77
|
-
user: {
|
|
78
|
-
...user,
|
|
79
|
-
token: userName,
|
|
80
|
-
saved: true,
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
})
|
|
84
|
-
.register();
|
|
85
|
-
|
|
86
|
-
thenBuilder<GivenState, WhenState, ThenState>()
|
|
87
|
-
.statement((userName: string) => `the user's name is ${userName}`)
|
|
88
|
-
.dependencies({ when: { user: "required" } })
|
|
89
|
-
.step(({ when: { user }, variables: [userName] }) => {
|
|
90
|
-
const token = user.token;
|
|
91
|
-
expect(token).toEqual(userName);
|
|
92
|
-
})
|
|
93
|
-
.register();
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { expect } from "earl";
|
|
2
|
-
import { givenBuilder } from "../../src/given";
|
|
3
|
-
import { thenBuilder } from "../../src/then";
|
|
4
|
-
import { whenBuilder } from "../../src/when";
|
|
5
|
-
import { GivenState, ThenState, WhenState } from "./world";
|
|
6
|
-
|
|
7
|
-
const Given = givenBuilder<GivenState>().statement;
|
|
8
|
-
const When = whenBuilder<GivenState, WhenState>().statement;
|
|
9
|
-
const Then = thenBuilder<GivenState, WhenState, ThenState>().statement;
|
|
10
|
-
|
|
11
|
-
Given("a bank user")
|
|
12
|
-
.step(() => {
|
|
13
|
-
return {
|
|
14
|
-
user: {
|
|
15
|
-
type: "customer",
|
|
16
|
-
token: "random",
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
})
|
|
20
|
-
.register();
|
|
21
|
-
|
|
22
|
-
When((amount: string, currency: string) => `I deposit ${amount} ${currency}`)
|
|
23
|
-
.dependencies({ given: { user: "required" } })
|
|
24
|
-
.step(({ variables: [rawAmount, currency], given: { user } }) => {
|
|
25
|
-
const amount = parseFloat(rawAmount);
|
|
26
|
-
return {
|
|
27
|
-
deposit: {
|
|
28
|
-
amount,
|
|
29
|
-
currency,
|
|
30
|
-
user,
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
})
|
|
34
|
-
.register();
|
|
35
|
-
|
|
36
|
-
Then((amount: string) => `the balance is ${amount}`)
|
|
37
|
-
.dependencies({ when: { deposit: "required" } })
|
|
38
|
-
.step(({ when: { deposit }, variables: [rawAmount] }) => {
|
|
39
|
-
const amount = parseFloat(rawAmount);
|
|
40
|
-
expect(deposit.amount).toEqual(amount);
|
|
41
|
-
})
|
|
42
|
-
.register();
|
package/features/steps/world.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { setWorldConstructor } from "@cucumber/cucumber";
|
|
2
|
-
import { BasicWorld } from "../../src/world";
|
|
3
|
-
|
|
4
|
-
export interface GivenState {
|
|
5
|
-
user: {
|
|
6
|
-
type: string;
|
|
7
|
-
token: string;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface WhenState {
|
|
12
|
-
user: {
|
|
13
|
-
type: string;
|
|
14
|
-
token: string;
|
|
15
|
-
saved: boolean;
|
|
16
|
-
};
|
|
17
|
-
deposit: {
|
|
18
|
-
amount: number;
|
|
19
|
-
currency: string;
|
|
20
|
-
user: {
|
|
21
|
-
type: string;
|
|
22
|
-
token: string;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface ThenState {}
|
|
28
|
-
|
|
29
|
-
setWorldConstructor(BasicWorld<GivenState, WhenState, ThenState>);
|
package/src/builderTypeUtils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"builderTypeUtils.js","sourceRoot":"","sources":["builderTypeUtils.ts"],"names":[],"mappings":"AAkBA,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,SAAmD,EAC9B,EAAE,CAAC,OAAO,SAAS,KAAK,QAAQ,CAAC"}
|
package/src/builderTypeUtils.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
export type StepType = "given" | "when" | "then";
|
|
3
|
-
|
|
4
|
-
export type InferAndReplace<T, U> = never extends T ? U : T;
|
|
5
|
-
|
|
6
|
-
export type HasKeys<T> =
|
|
7
|
-
T extends Record<any, any> ? (keyof T extends never ? never : T) : T;
|
|
8
|
-
|
|
9
|
-
export type EmptyObject = Record<string, never>;
|
|
10
|
-
|
|
11
|
-
export type RequiredOrOptional<T> = {
|
|
12
|
-
[K in keyof T]?: "required" | "optional";
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type GetFunctionArgs<T> = T extends (...args: infer A) => any
|
|
16
|
-
? A
|
|
17
|
-
: never;
|
|
18
|
-
|
|
19
|
-
export const isString = (
|
|
20
|
-
statement: string | ((...args: [...any]) => string)
|
|
21
|
-
): statement is string => typeof statement === "string";
|
|
22
|
-
|
|
23
|
-
export type EmptyDependencies = {
|
|
24
|
-
given: EmptyObject;
|
|
25
|
-
when: EmptyObject;
|
|
26
|
-
then: EmptyObject;
|
|
27
|
-
};
|
package/src/common.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { Given as CucGiven, Then as CucThen, When as CucWhen, } from "@cucumber/cucumber";
|
|
3
|
-
import _ from "lodash";
|
|
4
|
-
import { requireFromGiven, requireFromThen, requireFromWhen, typeCoercer, } from "./utils";
|
|
5
|
-
const cucFunctionMap = {
|
|
6
|
-
given: CucGiven,
|
|
7
|
-
when: CucWhen,
|
|
8
|
-
then: CucThen,
|
|
9
|
-
};
|
|
10
|
-
export const addStep = (statement, stepType, dependencies = {
|
|
11
|
-
given: {},
|
|
12
|
-
when: {},
|
|
13
|
-
then: {},
|
|
14
|
-
}) => (stepFunction) => {
|
|
15
|
-
const statementFunction = statement;
|
|
16
|
-
const { given: givenDependencies, when: whenDependencies, then: thenDependencies, } = dependencies;
|
|
17
|
-
return {
|
|
18
|
-
statement,
|
|
19
|
-
dependencies,
|
|
20
|
-
stepType,
|
|
21
|
-
stepFunction,
|
|
22
|
-
register: () => {
|
|
23
|
-
const argCount = statementFunction.length;
|
|
24
|
-
const argMatchers = Array.from({ length: argCount }, () => "{string}");
|
|
25
|
-
const statement = statementFunction(...argMatchers);
|
|
26
|
-
const cucStepFunction = Object.defineProperty(async function (...args) {
|
|
27
|
-
const coercedArgs = args.map(typeCoercer);
|
|
28
|
-
const requiredGivenKeys = Object.entries(givenDependencies ?? {})
|
|
29
|
-
.filter(([, value]) => value === "required")
|
|
30
|
-
.map(([key]) => key);
|
|
31
|
-
const ensuredGivenValues = requireFromGiven(requiredGivenKeys, this);
|
|
32
|
-
const narrowedGiven = {
|
|
33
|
-
..._.pick(this.given, Object.keys(givenDependencies ?? {})),
|
|
34
|
-
...ensuredGivenValues,
|
|
35
|
-
};
|
|
36
|
-
const requiredWhenKeys = Object.entries(whenDependencies ?? {})
|
|
37
|
-
.filter(([, value]) => value === "required")
|
|
38
|
-
.map(([key]) => key);
|
|
39
|
-
const ensuredWhenValues = requireFromWhen(requiredWhenKeys, this);
|
|
40
|
-
const narrowedWhen = {
|
|
41
|
-
..._.pick(this.when, Object.keys(whenDependencies ?? {})),
|
|
42
|
-
...ensuredWhenValues,
|
|
43
|
-
};
|
|
44
|
-
const requiredThenKeys = Object.entries(thenDependencies ?? {})
|
|
45
|
-
.filter(([, value]) => value === "required")
|
|
46
|
-
.map(([key]) => key);
|
|
47
|
-
const ensuredThenValues = requireFromThen(requiredThenKeys, this);
|
|
48
|
-
const narrowedThen = {
|
|
49
|
-
..._.pick(this.then, Object.keys(thenDependencies ?? {})),
|
|
50
|
-
...ensuredThenValues,
|
|
51
|
-
};
|
|
52
|
-
const result = await stepFunction({
|
|
53
|
-
variables: coercedArgs,
|
|
54
|
-
given: narrowedGiven,
|
|
55
|
-
when: narrowedWhen,
|
|
56
|
-
then: narrowedThen,
|
|
57
|
-
});
|
|
58
|
-
this[stepType].merge({
|
|
59
|
-
...result,
|
|
60
|
-
});
|
|
61
|
-
}, "length", { value: argCount, configurable: true });
|
|
62
|
-
const cucStep = cucFunctionMap[stepType];
|
|
63
|
-
cucStep(statement, cucStepFunction);
|
|
64
|
-
return {
|
|
65
|
-
stepType,
|
|
66
|
-
dependencies,
|
|
67
|
-
statement: statementFunction,
|
|
68
|
-
stepFunction,
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
//# sourceMappingURL=common.js.map
|
package/src/common.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["common.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EACL,KAAK,IAAI,QAAQ,EACjB,IAAI,IAAI,OAAO,EACf,IAAI,IAAI,OAAO,GAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,CAAC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