@systemfsoftware/storybook-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/LICENSE +203 -0
- package/README.md +23 -0
- package/dist/index.d.ts +228 -0
- package/dist/index.mjs +357 -0
- package/package.json +82 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
Copyright (c) 2026 Ryan Lee (systemfsoftware)
|
|
2
|
+
|
|
3
|
+
Apache License
|
|
4
|
+
Version 2.0, January 2004
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
12
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
15
|
+
the copyright owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
18
|
+
other entities that control, are controlled by, or are under common
|
|
19
|
+
control with that entity. For the purposes of this definition,
|
|
20
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
21
|
+
direction or management of such entity, whether by contract or
|
|
22
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
23
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
24
|
+
|
|
25
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
26
|
+
exercising permissions granted by this License.
|
|
27
|
+
|
|
28
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
29
|
+
including but not limited to software source code, documentation
|
|
30
|
+
source, and configuration files.
|
|
31
|
+
|
|
32
|
+
"Object" form shall mean any form resulting from mechanical
|
|
33
|
+
transformation or translation of a Source form, including but
|
|
34
|
+
not limited to compiled object code, generated documentation,
|
|
35
|
+
and conversions to other media types.
|
|
36
|
+
|
|
37
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
38
|
+
Object form, made available under the License, as indicated by a
|
|
39
|
+
copyright notice that is included in or attached to the work
|
|
40
|
+
(an example is provided in the Appendix below).
|
|
41
|
+
|
|
42
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
43
|
+
form, that is based on (or derived from) the Work and for which the
|
|
44
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
45
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
46
|
+
of this License, Derivative Works shall not include works that remain
|
|
47
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
48
|
+
the Work and Derivative Works thereof.
|
|
49
|
+
|
|
50
|
+
"Contribution" shall mean any work of authorship, including
|
|
51
|
+
the original version of the Work and any modifications or additions
|
|
52
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
53
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
54
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
55
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
56
|
+
means any form of electronic, verbal, or written communication sent
|
|
57
|
+
to the Licensor or its representatives, including but not limited to
|
|
58
|
+
communication on electronic mailing lists, source code control systems,
|
|
59
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
60
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
61
|
+
excluding communication that is conspicuously marked or otherwise
|
|
62
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
63
|
+
|
|
64
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
65
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
66
|
+
subsequently incorporated within the Work.
|
|
67
|
+
|
|
68
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
71
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
72
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
73
|
+
Work and such Derivative Works in Source or Object form.
|
|
74
|
+
|
|
75
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
(except as stated in this section) patent license to make, have made,
|
|
79
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
80
|
+
where such license applies only to those patent claims licensable
|
|
81
|
+
by such Contributor that are necessarily infringed by their
|
|
82
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
83
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
84
|
+
institute patent litigation against any entity (including a
|
|
85
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
86
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
87
|
+
or contributory patent infringement, then any patent licenses
|
|
88
|
+
granted to You under this License for that Work shall terminate
|
|
89
|
+
as of the date such litigation is filed.
|
|
90
|
+
|
|
91
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
92
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
93
|
+
modifications, and in Source or Object form, provided that You
|
|
94
|
+
meet the following conditions:
|
|
95
|
+
|
|
96
|
+
(a) You must give any other recipients of the Work or
|
|
97
|
+
Derivative Works a copy of this License; and
|
|
98
|
+
|
|
99
|
+
(b) You must cause any modified files to carry prominent notices
|
|
100
|
+
stating that You changed the files; and
|
|
101
|
+
|
|
102
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
103
|
+
that You distribute, all copyright, patent, trademark, and
|
|
104
|
+
attribution notices from the Source form of the Work,
|
|
105
|
+
excluding those notices that do not pertain to any part of
|
|
106
|
+
the Derivative Works; and
|
|
107
|
+
|
|
108
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
109
|
+
distribution, then any Derivative Works that You distribute must
|
|
110
|
+
include a readable copy of the attribution notices contained
|
|
111
|
+
within such NOTICE file, excluding those notices that do not
|
|
112
|
+
pertain to any part of the Derivative Works, in at least one
|
|
113
|
+
of the following places: within a NOTICE text file distributed
|
|
114
|
+
as part of the Derivative Works; within the Source form or
|
|
115
|
+
documentation, if provided along with the Derivative Works; or,
|
|
116
|
+
within a display generated by the Derivative Works, if and
|
|
117
|
+
wherever such third-party notices normally appear. The contents
|
|
118
|
+
of the NOTICE file are for informational purposes only and
|
|
119
|
+
do not modify the License. You may add Your own attribution
|
|
120
|
+
notices within Derivative Works that You distribute, alongside
|
|
121
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
122
|
+
that such additional attribution notices cannot be construed
|
|
123
|
+
as modifying the License.
|
|
124
|
+
|
|
125
|
+
You may add Your own copyright statement to Your modifications and
|
|
126
|
+
may provide additional or different license terms and conditions
|
|
127
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
128
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
129
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
130
|
+
the conditions stated in this License.
|
|
131
|
+
|
|
132
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
133
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
134
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
135
|
+
this License, without any additional terms or conditions.
|
|
136
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
137
|
+
the terms of any separate license agreement you may have executed
|
|
138
|
+
with Licensor regarding such Contributions.
|
|
139
|
+
|
|
140
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
141
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
142
|
+
except as required for reasonable and customary use in describing the
|
|
143
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
144
|
+
|
|
145
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
146
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
147
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
148
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
149
|
+
implied, including, without limitation, any warranties or conditions
|
|
150
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
151
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
152
|
+
appropriateness of using or redistributing the Work and assume any
|
|
153
|
+
risks associated with Your exercise of permissions under this License.
|
|
154
|
+
|
|
155
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
156
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
157
|
+
unless required by applicable law (such as deliberate and grossly
|
|
158
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
159
|
+
liable to You for damages, including any direct, indirect, special,
|
|
160
|
+
incidental, or consequential damages of any character arising as a
|
|
161
|
+
result of this License or out of the use or inability to use the
|
|
162
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
163
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
164
|
+
other commercial damages or losses), even if such Contributor
|
|
165
|
+
has been advised of the possibility of such damages.
|
|
166
|
+
|
|
167
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
168
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
169
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
170
|
+
or other liability obligations and/or rights consistent with this
|
|
171
|
+
License. However, in accepting such obligations, You may act only
|
|
172
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
173
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
174
|
+
defend, and hold each Contributor harmless for any liability
|
|
175
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
176
|
+
of your accepting any such warranty or additional liability.
|
|
177
|
+
|
|
178
|
+
END OF TERMS AND CONDITIONS
|
|
179
|
+
|
|
180
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
181
|
+
|
|
182
|
+
To apply the Apache License to your work, attach the following
|
|
183
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
184
|
+
replaced with your own identifying information. (Don't include
|
|
185
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
186
|
+
comment syntax for the file format. We also recommend that a
|
|
187
|
+
file or class name and description of purpose be included on the
|
|
188
|
+
same "printed page" as the copyright notice for easier
|
|
189
|
+
identification within third-party archives.
|
|
190
|
+
|
|
191
|
+
Copyright 2026 Ryan Lee (systemfsoftware)
|
|
192
|
+
|
|
193
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
194
|
+
you may not use this file except in compliance with the License.
|
|
195
|
+
You may obtain a copy of the License at
|
|
196
|
+
|
|
197
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
198
|
+
|
|
199
|
+
Unless required by applicable law or agreed to in writing, software
|
|
200
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
201
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
202
|
+
See the License for the specific language governing permissions and
|
|
203
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @systemfsoftware/storybook-gherkin
|
|
2
|
+
|
|
3
|
+
Feature specs as Storybook stories — Gherkin Given/When/Then embedded in CSF with typed captures and scenario outlines, executing under Storybook's browser-mode play functions.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @systemfsoftware/storybook-gherkin 'effect@4.0.0-rc.108' 'storybook@>=10.0.0'
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Those are peer dependencies: this package declares them but does not install them, so one copy is shared with the rest of your project.
|
|
12
|
+
|
|
13
|
+
## Entry points
|
|
14
|
+
|
|
15
|
+
- `@systemfsoftware/storybook-gherkin`
|
|
16
|
+
|
|
17
|
+
## API
|
|
18
|
+
|
|
19
|
+
The public surface is generated from the source and versioned with the package: [`etc/storybook-gherkin.api.md`](./etc/storybook-gherkin.api.md).
|
|
20
|
+
|
|
21
|
+
## License
|
|
22
|
+
|
|
23
|
+
Apache-2.0. Part of [systemfsoftware](https://github.com/systemfsoftware/systemfsoftware/tree/main/packages/storybook-gherkin#readme).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { Context, Effect, Schema } from "effect";
|
|
2
|
+
import { UserEventObject, screen, within } from "storybook/test";
|
|
3
|
+
import { Simplify, UnionToIntersection } from "type-fest";
|
|
4
|
+
//#region src/Capture.d.ts
|
|
5
|
+
interface Capture<Name extends string = string, _A = unknown> {
|
|
6
|
+
readonly _tag: 'Capture';
|
|
7
|
+
readonly name: Name;
|
|
8
|
+
readonly schema: Schema.ConstraintDecoder<unknown> | undefined;
|
|
9
|
+
readonly default: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
declare function capture<Name extends string, A>(name: Name, options: {
|
|
12
|
+
readonly schema: Schema.Codec<A, string>;
|
|
13
|
+
readonly default?: string;
|
|
14
|
+
}): Capture<Name, A>;
|
|
15
|
+
declare function capture<Name extends string>(name: Name, options?: {
|
|
16
|
+
readonly default?: string;
|
|
17
|
+
}): Capture<Name, string>;
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/Errors.schema.d.ts
|
|
20
|
+
declare const EmptyScenario_base: Schema.Class<EmptyScenario, Schema.TaggedStruct<"EmptyScenario", {
|
|
21
|
+
readonly scenario: Schema.String;
|
|
22
|
+
}>, import("effect/Cause").YieldableError>;
|
|
23
|
+
/**
|
|
24
|
+
* Two channels:
|
|
25
|
+
* - Declaration time: every violation except `CaptureDecodeFailed` is thrown
|
|
26
|
+
* during module evaluation of the story file, so a malformed spec fails the
|
|
27
|
+
* Storybook import before any story runs.
|
|
28
|
+
* - Run time: `CaptureDecodeFailed` travels the typed error channel of
|
|
29
|
+
* `Step.run` and surfaces when the play edge interprets the scenario.
|
|
30
|
+
*/
|
|
31
|
+
declare class EmptyScenario extends EmptyScenario_base {}
|
|
32
|
+
declare const MissingThen_base: Schema.Class<MissingThen, Schema.TaggedStruct<"MissingThen", {
|
|
33
|
+
readonly scenario: Schema.String;
|
|
34
|
+
}>, import("effect/Cause").YieldableError>;
|
|
35
|
+
/** Without a Then-phase step nothing is asserted — the scenario is not a spec. */
|
|
36
|
+
declare class MissingThen extends MissingThen_base {}
|
|
37
|
+
declare const BackgroundNotGiven_base: Schema.Class<BackgroundNotGiven, Schema.TaggedStruct<"BackgroundNotGiven", {
|
|
38
|
+
readonly step: Schema.String;
|
|
39
|
+
readonly resolved: Schema.Literals<readonly ["Given", "When", "Then"]>;
|
|
40
|
+
}>, import("effect/Cause").YieldableError>;
|
|
41
|
+
declare class BackgroundNotGiven extends BackgroundNotGiven_base {}
|
|
42
|
+
declare const DuplicateCapture_base: Schema.Class<DuplicateCapture, Schema.TaggedStruct<"DuplicateCapture", {
|
|
43
|
+
readonly step: Schema.String;
|
|
44
|
+
readonly name: Schema.String;
|
|
45
|
+
}>, import("effect/Cause").YieldableError>;
|
|
46
|
+
declare class DuplicateCapture extends DuplicateCapture_base {}
|
|
47
|
+
declare const UnresolvedCapture_base: Schema.Class<UnresolvedCapture, Schema.TaggedStruct<"UnresolvedCapture", {
|
|
48
|
+
readonly scenario: Schema.String;
|
|
49
|
+
readonly step: Schema.String;
|
|
50
|
+
readonly capture: Schema.String;
|
|
51
|
+
}>, import("effect/Cause").YieldableError>;
|
|
52
|
+
/** Capture values come from a literal hole, `with`, or an outline row — none matched. */
|
|
53
|
+
declare class UnresolvedCapture extends UnresolvedCapture_base {}
|
|
54
|
+
declare const OutlineEmpty_base: Schema.Class<OutlineEmpty, Schema.TaggedStruct<"OutlineEmpty", {
|
|
55
|
+
readonly outline: Schema.String;
|
|
56
|
+
}>, import("effect/Cause").YieldableError>;
|
|
57
|
+
declare class OutlineEmpty extends OutlineEmpty_base {}
|
|
58
|
+
declare const OutlineInconsistentKeys_base: Schema.Class<OutlineInconsistentKeys, Schema.TaggedStruct<"OutlineInconsistentKeys", {
|
|
59
|
+
readonly outline: Schema.String;
|
|
60
|
+
readonly row: Schema.String;
|
|
61
|
+
readonly expected: Schema.$Array<Schema.String>;
|
|
62
|
+
readonly actual: Schema.$Array<Schema.String>;
|
|
63
|
+
}>, import("effect/Cause").YieldableError>;
|
|
64
|
+
declare class OutlineInconsistentKeys extends OutlineInconsistentKeys_base {}
|
|
65
|
+
declare const OutlineDuplicateRowName_base: Schema.Class<OutlineDuplicateRowName, Schema.TaggedStruct<"OutlineDuplicateRowName", {
|
|
66
|
+
readonly outline: Schema.String;
|
|
67
|
+
readonly name: Schema.String;
|
|
68
|
+
}>, import("effect/Cause").YieldableError>;
|
|
69
|
+
/** Row names become the exported story names, so duplicates would collide. */
|
|
70
|
+
declare class OutlineDuplicateRowName extends OutlineDuplicateRowName_base {}
|
|
71
|
+
declare const OutlineMissingCapture_base: Schema.Class<OutlineMissingCapture, Schema.TaggedStruct<"OutlineMissingCapture", {
|
|
72
|
+
readonly outline: Schema.String;
|
|
73
|
+
readonly row: Schema.String;
|
|
74
|
+
readonly capture: Schema.String;
|
|
75
|
+
}>, import("effect/Cause").YieldableError>;
|
|
76
|
+
declare class OutlineMissingCapture extends OutlineMissingCapture_base {}
|
|
77
|
+
declare const CaptureDecodeFailed_base: Schema.Class<CaptureDecodeFailed, Schema.TaggedStruct<"CaptureDecodeFailed", {
|
|
78
|
+
readonly step: Schema.String;
|
|
79
|
+
readonly capture: Schema.String;
|
|
80
|
+
readonly value: Schema.String;
|
|
81
|
+
readonly cause: Schema.Unknown;
|
|
82
|
+
}>, import("effect/Cause").YieldableError>;
|
|
83
|
+
declare class CaptureDecodeFailed extends CaptureDecodeFailed_base {}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/Steps.d.ts
|
|
86
|
+
type Keyword = 'Given' | 'When' | 'Then' | 'And' | 'But' | 'Star';
|
|
87
|
+
type ConcreteKeyword = 'Given' | 'When' | 'Then';
|
|
88
|
+
interface CaptureModel {
|
|
89
|
+
readonly name: string;
|
|
90
|
+
/** Service-free decode view — the v4 counterpart of the removed no-context alias. */
|
|
91
|
+
readonly schema: Schema.ConstraintDecoder<unknown> | undefined;
|
|
92
|
+
readonly default: string | undefined;
|
|
93
|
+
}
|
|
94
|
+
interface StepModel {
|
|
95
|
+
readonly keyword: Keyword;
|
|
96
|
+
/** Static segments around the holes — length is always captures.length + 1. */
|
|
97
|
+
readonly parts: readonly string[];
|
|
98
|
+
readonly captures: readonly CaptureModel[];
|
|
99
|
+
}
|
|
100
|
+
type ExampleRow = {
|
|
101
|
+
readonly name: string;
|
|
102
|
+
} & Readonly<Record<string, string>>;
|
|
103
|
+
type Canvas = ReturnType<typeof within>;
|
|
104
|
+
type StepFn = (label: string, fn: () => Promise<void>) => Promise<void> | void;
|
|
105
|
+
interface Report {
|
|
106
|
+
readonly type: string;
|
|
107
|
+
readonly version?: number;
|
|
108
|
+
readonly result: unknown;
|
|
109
|
+
readonly status: 'failed' | 'passed' | 'warning';
|
|
110
|
+
}
|
|
111
|
+
interface ReportingAPI {
|
|
112
|
+
readonly reports: Report[];
|
|
113
|
+
readonly addReport: (report: Report) => void;
|
|
114
|
+
}
|
|
115
|
+
interface PlayContext<TArgs = unknown> {
|
|
116
|
+
readonly canvas: Canvas;
|
|
117
|
+
readonly canvasElement: HTMLElement;
|
|
118
|
+
readonly step: StepFn;
|
|
119
|
+
readonly userEvent: UserEventObject;
|
|
120
|
+
readonly args: TArgs;
|
|
121
|
+
readonly globals: Record<string, unknown>;
|
|
122
|
+
readonly parameters: Record<string, unknown>;
|
|
123
|
+
readonly loaded: Record<string, unknown>;
|
|
124
|
+
readonly abortSignal: AbortSignal;
|
|
125
|
+
readonly reporting: ReportingAPI;
|
|
126
|
+
}
|
|
127
|
+
interface StepContext<TArgs = unknown> {
|
|
128
|
+
readonly canvas: Canvas;
|
|
129
|
+
readonly screen: typeof screen;
|
|
130
|
+
readonly userEvent: UserEventObject;
|
|
131
|
+
readonly step: StepFn;
|
|
132
|
+
readonly args: TArgs;
|
|
133
|
+
readonly globals: Record<string, unknown>;
|
|
134
|
+
readonly parameters: Record<string, unknown>;
|
|
135
|
+
readonly loaded: Record<string, unknown>;
|
|
136
|
+
readonly canvasElement: HTMLElement;
|
|
137
|
+
/**
|
|
138
|
+
* Fires on story teardown (remount, navigation, HMR). Since the 2026-08-09
|
|
139
|
+
* Effect-composition refactor, the play edge interrupts the in-flight step
|
|
140
|
+
* on abort — steps no longer run to completion after teardown. The step
|
|
141
|
+
* handler's own promise is abandoned, not cancelled: observe this signal
|
|
142
|
+
* for cleanup or to race long-running work.
|
|
143
|
+
*/
|
|
144
|
+
readonly abortSignal: AbortSignal;
|
|
145
|
+
readonly reporting: ReportingAPI;
|
|
146
|
+
readonly context: PlayContext<TArgs>;
|
|
147
|
+
}
|
|
148
|
+
type Hole = Capture | string | number;
|
|
149
|
+
type CapsOf<THoles extends readonly Hole[]> = THoles extends readonly [] ? {} : Simplify<UnionToIntersection<{ [K in keyof THoles]: THoles[K] extends Capture<infer N, infer A> ? { [P in N]: A; } : {}; }[number]>>;
|
|
150
|
+
type StepHandler<TCaps, TArgs = unknown> = (ctx: StepContext<TArgs>, caps: TCaps) => void | Promise<void>;
|
|
151
|
+
interface Step<TArgs = unknown> {
|
|
152
|
+
readonly _tag: 'Step';
|
|
153
|
+
readonly model: StepModel;
|
|
154
|
+
readonly run: (values: Readonly<Record<string, string>>, ctx: StepContext<TArgs>) => Effect.Effect<void, CaptureDecodeFailed>;
|
|
155
|
+
}
|
|
156
|
+
interface StepBuilder<THoles extends readonly Hole[], TArgs = unknown> {
|
|
157
|
+
(handler: StepHandler<CapsOf<THoles>, TArgs>): Step<TArgs>;
|
|
158
|
+
}
|
|
159
|
+
type StepCtor = {
|
|
160
|
+
<const THoles extends readonly Hole[]>(statics: TemplateStringsArray, ...holes: THoles): StepBuilder<THoles>;
|
|
161
|
+
<TArgs, const THoles extends readonly Hole[] = readonly Hole[]>(statics: TemplateStringsArray, ...holes: THoles): StepBuilder<THoles, TArgs>;
|
|
162
|
+
};
|
|
163
|
+
declare const Given: StepCtor;
|
|
164
|
+
declare const When: StepCtor;
|
|
165
|
+
declare const Then: StepCtor;
|
|
166
|
+
declare const And: StepCtor;
|
|
167
|
+
declare const But: StepCtor;
|
|
168
|
+
declare const Star: StepCtor;
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/Feature.d.ts
|
|
171
|
+
interface StorySpec<TArgs = unknown> {
|
|
172
|
+
readonly name: string;
|
|
173
|
+
readonly play: (context: PlayContext<TArgs>) => Promise<void>;
|
|
174
|
+
}
|
|
175
|
+
interface ScenarioOptions {
|
|
176
|
+
/** Capture values for a plain (non-outline) scenario, keyed by capture name. */
|
|
177
|
+
readonly with?: Readonly<Record<string, string>>;
|
|
178
|
+
}
|
|
179
|
+
interface FeatureOptions {
|
|
180
|
+
/**
|
|
181
|
+
* Context that interprets a scenario's step program at the play edge,
|
|
182
|
+
* defaulting to `Context.empty()`. Supply a context carrying services
|
|
183
|
+
* or a custom scheduler to make them available to the run.
|
|
184
|
+
*/
|
|
185
|
+
readonly context?: Context.Context<never>;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Anything positional after the scenario name: a step, a step group from
|
|
189
|
+
* `Steps(...)` / `From(...)`, or — in first position only — an options object.
|
|
190
|
+
*/
|
|
191
|
+
type StepArg<TArgs> = Step<TArgs> | readonly Step<TArgs>[];
|
|
192
|
+
interface ScenarioFn<TArgs> {
|
|
193
|
+
(name: string, ...steps: readonly StepArg<TArgs>[]): StorySpec<TArgs>;
|
|
194
|
+
(name: string, options: ScenarioOptions, ...steps: readonly StepArg<TArgs>[]): StorySpec<TArgs>;
|
|
195
|
+
}
|
|
196
|
+
interface OutlineBuilder<TArgs> {
|
|
197
|
+
readonly examples: (rows: readonly ExampleRow[]) => Record<string, StorySpec<TArgs>>;
|
|
198
|
+
}
|
|
199
|
+
interface OutlineFn<TArgs> {
|
|
200
|
+
(name: string, ...steps: readonly StepArg<TArgs>[]): OutlineBuilder<TArgs>;
|
|
201
|
+
(name: string, options: ScenarioOptions, ...steps: readonly StepArg<TArgs>[]): OutlineBuilder<TArgs>;
|
|
202
|
+
}
|
|
203
|
+
interface RuleScope<TArgs> {
|
|
204
|
+
readonly scenario: ScenarioFn<TArgs>;
|
|
205
|
+
readonly scenarioOutline: OutlineFn<TArgs>;
|
|
206
|
+
}
|
|
207
|
+
interface Feature<M, TArgs = unknown> {
|
|
208
|
+
readonly meta: M;
|
|
209
|
+
readonly type: <TNext>() => Feature<M, TNext>;
|
|
210
|
+
readonly background: (...steps: readonly Step<TArgs>[]) => void;
|
|
211
|
+
readonly scenario: ScenarioFn<TArgs>;
|
|
212
|
+
readonly scenarioOutline: OutlineFn<TArgs>;
|
|
213
|
+
readonly rule: (name: string) => RuleScope<TArgs>;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Declare a feature: a story set whose scenarios execute as CSF `play`
|
|
217
|
+
* functions. `options.context` (default `Context.empty()`) is the Effect
|
|
218
|
+
* context interpreting each scenario's composed step program exactly once,
|
|
219
|
+
* at the play edge.
|
|
220
|
+
*/
|
|
221
|
+
declare const feature: <M>(meta: M, options?: FeatureOptions) => Feature<M>;
|
|
222
|
+
declare const Steps: <TArgs>(...steps: readonly Step<TArgs>[]) => Step<TArgs>[];
|
|
223
|
+
interface StoryWithPlay<TArgs> {
|
|
224
|
+
readonly play?: (context: PlayContext<TArgs>) => Promise<void> | void;
|
|
225
|
+
}
|
|
226
|
+
declare const From: <TArgs>(story: StoryWithPlay<TArgs>) => Step<TArgs>[];
|
|
227
|
+
//#endregion
|
|
228
|
+
export { And, BackgroundNotGiven, But, type Canvas, type CapsOf, type Capture, CaptureDecodeFailed, type CaptureModel, type ConcreteKeyword, DuplicateCapture, EmptyScenario, type ExampleRow, type Feature, type FeatureOptions, From, Given, type Hole, type Keyword, MissingThen, type OutlineBuilder, OutlineDuplicateRowName, OutlineEmpty, type OutlineFn, OutlineInconsistentKeys, OutlineMissingCapture, type PlayContext, type Report, type ReportingAPI, type RuleScope, type ScenarioFn, type ScenarioOptions, Star, type Step, type StepArg, type StepBuilder, type StepContext, type StepCtor, type StepFn, type StepHandler, type StepModel, Steps, type StorySpec, Then, UnresolvedCapture, When, capture, feature };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { Array as Array$1, Cause, Context, Deferred, Effect, Exit, Fiber, Match, Schema } from "effect";
|
|
2
|
+
import { screen } from "storybook/test";
|
|
3
|
+
//#region src/Capture.ts
|
|
4
|
+
function capture(name, options) {
|
|
5
|
+
return {
|
|
6
|
+
_tag: "Capture",
|
|
7
|
+
name,
|
|
8
|
+
schema: options?.schema,
|
|
9
|
+
default: options?.default
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/Errors.schema.ts
|
|
14
|
+
const ConcreteKeywordSchema = Schema.Literals([
|
|
15
|
+
"Given",
|
|
16
|
+
"When",
|
|
17
|
+
"Then"
|
|
18
|
+
]);
|
|
19
|
+
/**
|
|
20
|
+
* Two channels:
|
|
21
|
+
* - Declaration time: every violation except `CaptureDecodeFailed` is thrown
|
|
22
|
+
* during module evaluation of the story file, so a malformed spec fails the
|
|
23
|
+
* Storybook import before any story runs.
|
|
24
|
+
* - Run time: `CaptureDecodeFailed` travels the typed error channel of
|
|
25
|
+
* `Step.run` and surfaces when the play edge interprets the scenario.
|
|
26
|
+
*/
|
|
27
|
+
var EmptyScenario = class extends Schema.TaggedError()("EmptyScenario", { scenario: Schema.String }) {};
|
|
28
|
+
/** Without a Then-phase step nothing is asserted — the scenario is not a spec. */
|
|
29
|
+
var MissingThen = class extends Schema.TaggedError()("MissingThen", { scenario: Schema.String }) {};
|
|
30
|
+
var BackgroundNotGiven = class extends Schema.TaggedError()("BackgroundNotGiven", {
|
|
31
|
+
step: Schema.String,
|
|
32
|
+
resolved: ConcreteKeywordSchema
|
|
33
|
+
}) {};
|
|
34
|
+
var DuplicateCapture = class extends Schema.TaggedError()("DuplicateCapture", {
|
|
35
|
+
step: Schema.String,
|
|
36
|
+
name: Schema.String
|
|
37
|
+
}) {};
|
|
38
|
+
/** Capture values come from a literal hole, `with`, or an outline row — none matched. */
|
|
39
|
+
var UnresolvedCapture = class extends Schema.TaggedError()("UnresolvedCapture", {
|
|
40
|
+
scenario: Schema.String,
|
|
41
|
+
step: Schema.String,
|
|
42
|
+
capture: Schema.String
|
|
43
|
+
}) {};
|
|
44
|
+
var OutlineEmpty = class extends Schema.TaggedError()("OutlineEmpty", { outline: Schema.String }) {};
|
|
45
|
+
var OutlineInconsistentKeys = class extends Schema.TaggedError()("OutlineInconsistentKeys", {
|
|
46
|
+
outline: Schema.String,
|
|
47
|
+
row: Schema.String,
|
|
48
|
+
expected: Schema.Array(Schema.String),
|
|
49
|
+
actual: Schema.Array(Schema.String)
|
|
50
|
+
}) {};
|
|
51
|
+
/** Row names become the exported story names, so duplicates would collide. */
|
|
52
|
+
var OutlineDuplicateRowName = class extends Schema.TaggedError()("OutlineDuplicateRowName", {
|
|
53
|
+
outline: Schema.String,
|
|
54
|
+
name: Schema.String
|
|
55
|
+
}) {};
|
|
56
|
+
var OutlineMissingCapture = class extends Schema.TaggedError()("OutlineMissingCapture", {
|
|
57
|
+
outline: Schema.String,
|
|
58
|
+
row: Schema.String,
|
|
59
|
+
capture: Schema.String
|
|
60
|
+
}) {};
|
|
61
|
+
var CaptureDecodeFailed = class extends Schema.TaggedError()("CaptureDecodeFailed", {
|
|
62
|
+
step: Schema.String,
|
|
63
|
+
capture: Schema.String,
|
|
64
|
+
value: Schema.String,
|
|
65
|
+
cause: Schema.Unknown
|
|
66
|
+
}) {};
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/Steps.ts
|
|
69
|
+
const joinStep = (step, renderHole) => [step.parts[0] ?? "", ...step.captures.flatMap((cap, i) => [renderHole(cap), step.parts[i + 1] ?? ""])].join("");
|
|
70
|
+
const displayPattern = (step) => joinStep(step, (cap) => `{${cap.name}}`);
|
|
71
|
+
const renderStepText = (step, values) => joinStep(step, (cap) => values[cap.name] ?? cap.default ?? `{${cap.name}}`);
|
|
72
|
+
const resolveKeyword = (keyword, previous) => Match.value(keyword).pipe(Match.when("Given", () => "Given"), Match.when("When", () => "When"), Match.when("Then", () => "Then"), Match.when("And", () => previous), Match.when("But", () => previous), Match.when("Star", () => previous), Match.exhaustive);
|
|
73
|
+
const resolveKeywords = (steps) => {
|
|
74
|
+
return Array$1.mapAccum(steps, "Given", (previous, s) => {
|
|
75
|
+
const resolved = resolveKeyword(s.keyword, previous);
|
|
76
|
+
return [resolved, {
|
|
77
|
+
...s,
|
|
78
|
+
resolved
|
|
79
|
+
}];
|
|
80
|
+
})[1];
|
|
81
|
+
};
|
|
82
|
+
const STEP_TAG = "Step";
|
|
83
|
+
const buildModel = (keyword, statics, holes) => {
|
|
84
|
+
const parts = [];
|
|
85
|
+
const captures = [];
|
|
86
|
+
let current = statics[0] ?? "";
|
|
87
|
+
for (const [i, hole] of holes.entries()) if (typeof hole === "string") current += hole + (statics[i + 1] ?? "");
|
|
88
|
+
else if (typeof hole === "number") current += String(hole) + (statics[i + 1] ?? "");
|
|
89
|
+
else {
|
|
90
|
+
parts.push(current);
|
|
91
|
+
current = statics[i + 1] ?? "";
|
|
92
|
+
captures.push({
|
|
93
|
+
name: hole.name,
|
|
94
|
+
schema: hole.schema,
|
|
95
|
+
default: hole.default
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
parts.push(current);
|
|
99
|
+
const model = {
|
|
100
|
+
keyword,
|
|
101
|
+
parts,
|
|
102
|
+
captures
|
|
103
|
+
};
|
|
104
|
+
const seen = /* @__PURE__ */ new Set();
|
|
105
|
+
for (const cap of captures) {
|
|
106
|
+
if (seen.has(cap.name)) throw DuplicateCapture.make({
|
|
107
|
+
step: displayPattern(model),
|
|
108
|
+
name: cap.name
|
|
109
|
+
});
|
|
110
|
+
seen.add(cap.name);
|
|
111
|
+
}
|
|
112
|
+
return model;
|
|
113
|
+
};
|
|
114
|
+
const decodeCapture = (cap, values, model) => {
|
|
115
|
+
const raw = values[cap.name] ?? cap.default;
|
|
116
|
+
if (cap.schema === void 0) return Effect.succeed(raw);
|
|
117
|
+
return Schema.decodeEffect(cap.schema)(raw).pipe(Effect.mapError((error) => CaptureDecodeFailed.make({
|
|
118
|
+
step: displayPattern(model),
|
|
119
|
+
capture: cap.name,
|
|
120
|
+
value: raw ?? "",
|
|
121
|
+
cause: error
|
|
122
|
+
})));
|
|
123
|
+
};
|
|
124
|
+
const makeStepCtor = (keyword) => {
|
|
125
|
+
function ctor(statics, ...holes) {
|
|
126
|
+
return (handler) => {
|
|
127
|
+
const model = buildModel(keyword, statics, holes);
|
|
128
|
+
return {
|
|
129
|
+
_tag: STEP_TAG,
|
|
130
|
+
model,
|
|
131
|
+
run: (values, ctx) => Effect.forEach(model.captures, (cap) => decodeCapture(cap, values, model)).pipe(Effect.flatMap((decoded) => {
|
|
132
|
+
const caps = {};
|
|
133
|
+
for (const [cap, value] of Array$1.zip(model.captures, decoded)) caps[cap.name] = value;
|
|
134
|
+
return Effect.promise(() => Promise.resolve(handler(ctx, caps)));
|
|
135
|
+
}))
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
return ctor;
|
|
140
|
+
};
|
|
141
|
+
const Given = makeStepCtor("Given");
|
|
142
|
+
const When = makeStepCtor("When");
|
|
143
|
+
const Then = makeStepCtor("Then");
|
|
144
|
+
const And = makeStepCtor("And");
|
|
145
|
+
const But = makeStepCtor("But");
|
|
146
|
+
const Star = makeStepCtor("Star");
|
|
147
|
+
const isStep = (value) => {
|
|
148
|
+
if (typeof value !== "object" || value === null) return false;
|
|
149
|
+
return Reflect.get(value, "_tag") === STEP_TAG && "model" in value && "run" in value;
|
|
150
|
+
};
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/Feature.ts
|
|
153
|
+
const displayKeyword = (model) => model.keyword === "Star" ? "*" : model.keyword;
|
|
154
|
+
const buildStepContext = (ctx) => ({
|
|
155
|
+
canvas: ctx.canvas,
|
|
156
|
+
screen,
|
|
157
|
+
userEvent: ctx.userEvent,
|
|
158
|
+
step: ctx.step,
|
|
159
|
+
args: ctx.args,
|
|
160
|
+
globals: ctx.globals,
|
|
161
|
+
parameters: ctx.parameters,
|
|
162
|
+
loaded: ctx.loaded,
|
|
163
|
+
canvasElement: ctx.canvasElement,
|
|
164
|
+
abortSignal: ctx.abortSignal,
|
|
165
|
+
reporting: ctx.reporting,
|
|
166
|
+
context: ctx
|
|
167
|
+
});
|
|
168
|
+
/**
|
|
169
|
+
* Total classification of an interpreted program's `Exit`, shared by the play
|
|
170
|
+
* edge and the step bridge: interruption resolves silently, success returns
|
|
171
|
+
* the value, and any other cause is rethrown as the original error instance
|
|
172
|
+
* (`Cause.squash`) so Storybook's panel keeps the matcher diff.
|
|
173
|
+
*/
|
|
174
|
+
const squashExit = (exit) => Exit.match(exit, {
|
|
175
|
+
onSuccess: (value) => value,
|
|
176
|
+
onFailure: (cause) => {
|
|
177
|
+
if (Exit.hasInterrupts(exit)) return void 0;
|
|
178
|
+
throw Cause.squash(cause);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
/**
|
|
182
|
+
* One scenario step, composed as an Effect. Storybook's instrumented `step`
|
|
183
|
+
* expects a promise whose settlement tracks the step's work, so the body runs
|
|
184
|
+
* in a child fiber that settles a deferred; the bridge promise given to
|
|
185
|
+
* `stepCtx.step` awaits that deferred and rejects with the step's original error.
|
|
186
|
+
* The bridge interprets only this pure signalling effect; user code runs in
|
|
187
|
+
* the single play-edge interpretation. The `ensuring` finalizer interrupts
|
|
188
|
+
* the child on every parent exit — success (no-op on a joined fiber),
|
|
189
|
+
* failure, and interruption — so an independently failed `stepCtx.step` never
|
|
190
|
+
* orphans a running step body.
|
|
191
|
+
*/
|
|
192
|
+
const runStep = (step, values, stepCtx) => {
|
|
193
|
+
const label = `${displayKeyword(step.model)} ${renderStepText(step.model, values)}`;
|
|
194
|
+
return Deferred.make().pipe(Effect.flatMap((done) => {
|
|
195
|
+
const bridge = () => Effect.runPromiseExit(Effect.flatten(Deferred.await(done))).then(squashExit);
|
|
196
|
+
return Effect.forkChild(step.run(values, stepCtx).pipe(Effect.exit, Effect.flatMap((exit) => Deferred.succeed(done, exit)), Effect.ensuring(Deferred.interrupt(done).pipe(Effect.asVoid)))).pipe(Effect.flatMap((fiber) => Effect.promise(() => Promise.resolve(stepCtx.step(label, bridge))).pipe(Effect.flatMap(() => Fiber.join(fiber)), Effect.ensuring(Fiber.interrupt(fiber).pipe(Effect.asVoid)))));
|
|
197
|
+
}));
|
|
198
|
+
};
|
|
199
|
+
const executeSteps = (ordered, values, ctx) => {
|
|
200
|
+
const stepCtx = buildStepContext(ctx);
|
|
201
|
+
return Effect.forEach(ordered, (s) => runStep(s, values, stepCtx), { discard: true });
|
|
202
|
+
};
|
|
203
|
+
/** The single interpretation edge of the package. */
|
|
204
|
+
const interpretPlay = (context, program, ctx) => Effect.runPromiseExitWith(context)(program, { signal: ctx.abortSignal }).then(squashExit);
|
|
205
|
+
const rowValuesFor = (row) => Object.fromEntries(Object.entries(row).filter(([k]) => k !== "name"));
|
|
206
|
+
const sortKeys = (keys) => {
|
|
207
|
+
const sorted = keys.slice();
|
|
208
|
+
sorted.sort();
|
|
209
|
+
return sorted;
|
|
210
|
+
};
|
|
211
|
+
const validateScenarioSteps = (fullName, models, withRecord) => {
|
|
212
|
+
if (models.length === 0) throw EmptyScenario.make({ scenario: fullName });
|
|
213
|
+
if (!resolveKeywords(models).some((r) => r.resolved === "Then")) throw MissingThen.make({ scenario: fullName });
|
|
214
|
+
for (const stepModel of models) for (const cap of stepModel.captures) {
|
|
215
|
+
const hasDefault = cap.default !== void 0;
|
|
216
|
+
const hasWith = Object.prototype.hasOwnProperty.call(withRecord, cap.name);
|
|
217
|
+
if (!hasDefault && !hasWith) throw UnresolvedCapture.make({
|
|
218
|
+
scenario: fullName,
|
|
219
|
+
step: displayPattern(stepModel),
|
|
220
|
+
capture: cap.name
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
const isScenarioOptions = (value) => !isStep(value) && !Array.isArray(value);
|
|
225
|
+
const parseScenarioArgs = (rest) => {
|
|
226
|
+
const firstArg = rest[0];
|
|
227
|
+
const options = firstArg !== void 0 && isScenarioOptions(firstArg) ? firstArg : void 0;
|
|
228
|
+
const body = options === void 0 ? rest : rest.slice(1);
|
|
229
|
+
const steps = [];
|
|
230
|
+
for (const item of body) if (isStep(item)) steps.push(item);
|
|
231
|
+
else if (Array.isArray(item)) for (const inner of item) {
|
|
232
|
+
if (!isStep(inner)) throw new TypeError(`Steps group contains a non-step value of type ${typeof inner}`);
|
|
233
|
+
steps.push(inner);
|
|
234
|
+
}
|
|
235
|
+
else throw new TypeError(`Scenario arguments must be steps or step groups; got type ${typeof item}`);
|
|
236
|
+
return {
|
|
237
|
+
options,
|
|
238
|
+
steps
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
const makeScenario = (background, prefix, context) => {
|
|
242
|
+
function scenario(name, ...rest) {
|
|
243
|
+
const { options, steps } = parseScenarioArgs(rest);
|
|
244
|
+
const fullName = prefix === "" ? name : `${prefix}: ${name}`;
|
|
245
|
+
const withRecord = options?.with ?? {};
|
|
246
|
+
validateScenarioSteps(fullName, steps.map((s) => s.model), withRecord);
|
|
247
|
+
return {
|
|
248
|
+
name: fullName,
|
|
249
|
+
play: (ctx) => interpretPlay(context, executeSteps([...background, ...steps], withRecord, ctx), ctx)
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
return scenario;
|
|
253
|
+
};
|
|
254
|
+
const validateOutlineRows = (rows, captureNames, fullName) => {
|
|
255
|
+
if (rows.length === 0) throw OutlineEmpty.make({ outline: fullName });
|
|
256
|
+
const seenRowNames = /* @__PURE__ */ new Set();
|
|
257
|
+
const firstKeys = sortKeys(Object.keys(rows[0] ?? {}).filter((k) => k !== "name"));
|
|
258
|
+
for (const row of rows) {
|
|
259
|
+
if (seenRowNames.has(row.name)) throw OutlineDuplicateRowName.make({
|
|
260
|
+
outline: fullName,
|
|
261
|
+
name: row.name
|
|
262
|
+
});
|
|
263
|
+
seenRowNames.add(row.name);
|
|
264
|
+
const actual = sortKeys(Object.keys(row).filter((k) => k !== "name"));
|
|
265
|
+
if (actual.length !== firstKeys.length || actual.some((k, i) => k !== firstKeys[i])) throw OutlineInconsistentKeys.make({
|
|
266
|
+
outline: fullName,
|
|
267
|
+
row: row.name,
|
|
268
|
+
expected: [...firstKeys],
|
|
269
|
+
actual: [...actual]
|
|
270
|
+
});
|
|
271
|
+
for (const cap of captureNames) if (!Object.prototype.hasOwnProperty.call(row, cap)) throw OutlineMissingCapture.make({
|
|
272
|
+
outline: fullName,
|
|
273
|
+
row: row.name,
|
|
274
|
+
capture: cap
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
const makeOutline = (background, prefix, context) => {
|
|
279
|
+
function outline(name, ...rest) {
|
|
280
|
+
const { options, steps } = parseScenarioArgs(rest);
|
|
281
|
+
const fullName = prefix === "" ? name : `${prefix}: ${name}`;
|
|
282
|
+
const withRecord = options?.with ?? {};
|
|
283
|
+
const models = steps.map((s) => s.model);
|
|
284
|
+
if (models.length === 0) throw EmptyScenario.make({ scenario: fullName });
|
|
285
|
+
if (!resolveKeywords(models).some((r) => r.resolved === "Then")) throw MissingThen.make({ scenario: fullName });
|
|
286
|
+
const captureNames = /* @__PURE__ */ new Set();
|
|
287
|
+
for (const m of models) for (const c of m.captures) captureNames.add(c.name);
|
|
288
|
+
const buildRowSpec = (row) => {
|
|
289
|
+
const values = {
|
|
290
|
+
...withRecord,
|
|
291
|
+
...rowValuesFor(row)
|
|
292
|
+
};
|
|
293
|
+
return {
|
|
294
|
+
name: `${fullName} — ${row.name}`,
|
|
295
|
+
play: (ctx) => interpretPlay(context, executeSteps([...background, ...steps], values, ctx), ctx)
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
const examples = (rows) => {
|
|
299
|
+
validateOutlineRows(rows, captureNames, fullName);
|
|
300
|
+
const out = {};
|
|
301
|
+
for (const row of rows) out[row.name] = buildRowSpec(row);
|
|
302
|
+
return out;
|
|
303
|
+
};
|
|
304
|
+
return { examples };
|
|
305
|
+
}
|
|
306
|
+
return outline;
|
|
307
|
+
};
|
|
308
|
+
const makeBackground = (background) => (...steps) => {
|
|
309
|
+
const resolvedKeywords = resolveKeywords(steps.map((s) => s.model));
|
|
310
|
+
for (let i = 0; i < steps.length; i++) {
|
|
311
|
+
const step = steps[i];
|
|
312
|
+
const resolvedEntry = resolvedKeywords[i];
|
|
313
|
+
if (step === void 0 || resolvedEntry === void 0) continue;
|
|
314
|
+
if (resolvedEntry.resolved !== "Given") throw BackgroundNotGiven.make({
|
|
315
|
+
step: displayPattern(step.model),
|
|
316
|
+
resolved: resolvedEntry.resolved
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
background.push(...steps);
|
|
320
|
+
};
|
|
321
|
+
const makeFeature = (meta, context) => {
|
|
322
|
+
const background = [];
|
|
323
|
+
return {
|
|
324
|
+
meta,
|
|
325
|
+
type: () => makeFeature(meta, context),
|
|
326
|
+
background: makeBackground(background),
|
|
327
|
+
scenario: makeScenario(background, "", context),
|
|
328
|
+
scenarioOutline: makeOutline(background, "", context),
|
|
329
|
+
rule: (ruleName) => ({
|
|
330
|
+
scenario: makeScenario(background, ruleName, context),
|
|
331
|
+
scenarioOutline: makeOutline(background, ruleName, context)
|
|
332
|
+
})
|
|
333
|
+
};
|
|
334
|
+
};
|
|
335
|
+
/**
|
|
336
|
+
* Declare a feature: a story set whose scenarios execute as CSF `play`
|
|
337
|
+
* functions. `options.context` (default `Context.empty()`) is the Effect
|
|
338
|
+
* context interpreting each scenario's composed step program exactly once,
|
|
339
|
+
* at the play edge.
|
|
340
|
+
*/
|
|
341
|
+
const feature = (meta, options = {}) => makeFeature(meta, options.context ?? Context.empty());
|
|
342
|
+
const Steps = (...steps) => [...steps];
|
|
343
|
+
const From = (story) => {
|
|
344
|
+
const play = story.play;
|
|
345
|
+
if (play === void 0) return [];
|
|
346
|
+
return [{
|
|
347
|
+
_tag: "Step",
|
|
348
|
+
model: {
|
|
349
|
+
keyword: "Given",
|
|
350
|
+
parts: ["the prior scenario completed"],
|
|
351
|
+
captures: []
|
|
352
|
+
},
|
|
353
|
+
run: (_values, ctx) => Effect.promise(() => Promise.resolve(play(ctx.context)))
|
|
354
|
+
}];
|
|
355
|
+
};
|
|
356
|
+
//#endregion
|
|
357
|
+
export { And, BackgroundNotGiven, But, CaptureDecodeFailed, DuplicateCapture, EmptyScenario, From, Given, MissingThen, OutlineDuplicateRowName, OutlineEmpty, OutlineInconsistentKeys, OutlineMissingCapture, Star, Steps, Then, UnresolvedCapture, When, capture, feature };
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@systemfsoftware/storybook-gherkin",
|
|
3
|
+
"license": "Apache-2.0",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"author": "Ryan Lee <drdgvhbh@gmail.com>",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/systemfsoftware/systemfsoftware.git",
|
|
9
|
+
"directory": "packages/storybook-gherkin"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/systemfsoftware/systemfsoftware/tree/main/packages/storybook-gherkin#readme",
|
|
12
|
+
"bugs": "https://github.com/systemfsoftware/systemfsoftware/issues",
|
|
13
|
+
"description": "Feature specs as Storybook stories — Gherkin Given/When/Then embedded in CSF with typed captures and scenario outlines, executing under Storybook's browser-mode play functions.",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"effect",
|
|
16
|
+
"effect-ts",
|
|
17
|
+
"storybook",
|
|
18
|
+
"gherkin",
|
|
19
|
+
"bdd",
|
|
20
|
+
"cucumber",
|
|
21
|
+
"given-when-then",
|
|
22
|
+
"scenario-outline",
|
|
23
|
+
"stories",
|
|
24
|
+
"csf",
|
|
25
|
+
"acceptance-testing"
|
|
26
|
+
],
|
|
27
|
+
"type": "module",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"default": "./dist/index.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./package.json": "./package.json"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"type-fest": "^5.8.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"effect": "4.0.0-rc.108",
|
|
43
|
+
"storybook": ">=10.0.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@storybook/addon-vitest": "^10.5.0",
|
|
47
|
+
"@storybook/react-vite": "^10.5.0",
|
|
48
|
+
"@systemfsoftware/arethetypeswrong-cli": "^1.1.1",
|
|
49
|
+
"@types/node": "^24",
|
|
50
|
+
"@types/react": "^19.2.18",
|
|
51
|
+
"@types/react-dom": "^19.2.4",
|
|
52
|
+
"@vitest/browser": "^4",
|
|
53
|
+
"@vitest/browser-playwright": "^4",
|
|
54
|
+
"effect": "4.0.0-rc.108",
|
|
55
|
+
"oxlint": "^1.77.0",
|
|
56
|
+
"playwright": "^1",
|
|
57
|
+
"react": "^19.2.8",
|
|
58
|
+
"react-dom": "^19.2.8",
|
|
59
|
+
"rimraf": "^6.1.3",
|
|
60
|
+
"storybook": "^10.5.0",
|
|
61
|
+
"tsdown": "^0.22.14",
|
|
62
|
+
"typescript": "^7",
|
|
63
|
+
"vite": "^8",
|
|
64
|
+
"vitest": "^4.1.10",
|
|
65
|
+
"@systemfsoftware/oxlint-config": "^0.1.0",
|
|
66
|
+
"@systemfsoftware/tsconfig": "^1.3.1"
|
|
67
|
+
},
|
|
68
|
+
"publishConfig": {
|
|
69
|
+
"provenance": true
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"clean": "rimraf dist",
|
|
73
|
+
"build": "tsdown && pnpm dts:check",
|
|
74
|
+
"typecheck": "tsc --noEmit --incremental",
|
|
75
|
+
"lint": "f=${OXLINT_FORMAT:-${AGENT:+agent}}; oxlint . --config oxlint.config.ts --format=${f:-default}",
|
|
76
|
+
"lint:tsgo": "effect-tsgo diagnostics --project tsconfig.json --format ${TSGO_FORMAT:-text}",
|
|
77
|
+
"attw": "attw --pack .",
|
|
78
|
+
"dts:check": "node scripts/check-dts.mjs",
|
|
79
|
+
"storybook": "storybook dev -p 6006 --no-open",
|
|
80
|
+
"test:browser": "vitest run"
|
|
81
|
+
}
|
|
82
|
+
}
|