nukadoko 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +291 -0
- data/README.ja.md +58 -5
- data/README.md +15 -3
- data/exe/nuka +8 -0
- data/lib/nukadoko/aria_snapshot.rb +1008 -0
- data/lib/nukadoko/aria_tree.rb +150 -0
- data/lib/nukadoko/base.rb +274 -0
- data/lib/nukadoko/check.rb +669 -22
- data/lib/nukadoko/claim_check.rb +177 -0
- data/lib/nukadoko/claim_check_run.rb +293 -0
- data/lib/nukadoko/claim_line.rb +381 -0
- data/lib/nukadoko/claim_rules.rb +519 -0
- data/lib/nukadoko/claims.rb +407 -30
- data/lib/nukadoko/cli.rb +802 -19
- data/lib/nukadoko/codes.json +942 -0
- data/lib/nukadoko/codes.rb +19 -0
- data/lib/nukadoko/command.rb +214 -12
- data/lib/nukadoko/criteria.rb +172 -0
- data/lib/nukadoko/definition.rb +33 -41
- data/lib/nukadoko/env_check.rb +90 -0
- data/lib/nukadoko/features.rb +80 -10
- data/lib/nukadoko/fixtures.rb +296 -10
- data/lib/nukadoko/http_recording.rb +68 -0
- data/lib/nukadoko/init.rb +130 -0
- data/lib/nukadoko/judge.rb +221 -0
- data/lib/nukadoko/judgment_file.rb +78 -0
- data/lib/nukadoko/judgments.rb +256 -0
- data/lib/nukadoko/literal.rb +129 -0
- data/lib/nukadoko/measured.rb +105 -0
- data/lib/nukadoko/order.rb +84 -0
- data/lib/nukadoko/parts.rb +42 -21
- data/lib/nukadoko/pattern.rb +11 -1
- data/lib/nukadoko/poll.rb +17 -6
- data/lib/nukadoko/program.rb +105 -17
- data/lib/nukadoko/project_fixtures.rb +17 -2
- data/lib/nukadoko/report_allure.rb +751 -0
- data/lib/nukadoko/report_messages.rb +167 -0
- data/lib/nukadoko/report_run.rb +169 -0
- data/lib/nukadoko/run.rb +865 -88
- data/lib/nukadoko/run_record.rb +532 -0
- data/lib/nukadoko/scaffold.rb +1015 -0
- data/lib/nukadoko/schema.rb +61 -4
- data/lib/nukadoko/secrets.rb +359 -0
- data/lib/nukadoko/selection.rb +163 -0
- data/lib/nukadoko/signature.rb +4 -1
- data/lib/nukadoko/skill.rb +36 -0
- data/lib/nukadoko/step.rb +62 -21
- data/lib/nukadoko/summary.rb +662 -0
- data/lib/nukadoko/table.rb +34 -2
- data/lib/nukadoko/text_fit.rb +179 -0
- data/lib/nukadoko/trace.rb +244 -0
- data/lib/nukadoko/trace_actions.rb +116 -0
- data/lib/nukadoko/tree_passes.rb +119 -0
- data/lib/nukadoko/verdict.rb +128 -0
- data/lib/nukadoko/version.rb +2 -1
- data/lib/nukadoko/vocabulary.rb +6 -0
- data/lib/nukadoko/walk.rb +305 -0
- data/lib/nukadoko/walk_files.rb +473 -0
- data/lib/nukadoko/walk_step.rb +149 -0
- data/lib/nukadoko.rb +36 -0
- data/llms.txt +296 -0
- data/sig/generated/nukadoko/aria_snapshot.rbs +331 -0
- data/sig/generated/nukadoko/aria_tree.rbs +142 -0
- data/sig/generated/nukadoko/base.rbs +136 -0
- data/sig/generated/nukadoko/check.rbs +255 -0
- data/sig/generated/nukadoko/claim_check.rbs +118 -0
- data/sig/generated/nukadoko/claim_check_run.rbs +88 -0
- data/sig/generated/nukadoko/claim_line.rbs +158 -0
- data/sig/generated/nukadoko/claim_rules.rbs +172 -0
- data/sig/generated/nukadoko/claims.rbs +165 -0
- data/sig/generated/nukadoko/cli.rbs +182 -0
- data/sig/generated/nukadoko/codes.rbs +16 -0
- data/sig/generated/nukadoko/command.rbs +109 -0
- data/sig/generated/nukadoko/criteria.rbs +83 -0
- data/sig/generated/nukadoko/definition.rbs +30 -0
- data/sig/generated/nukadoko/env_check.rbs +38 -0
- data/sig/generated/nukadoko/features.rbs +101 -0
- data/sig/generated/nukadoko/fixtures.rbs +152 -0
- data/sig/generated/nukadoko/http_recording.rbs +29 -0
- data/sig/generated/nukadoko/init.rbs +66 -0
- data/sig/generated/nukadoko/judge.rbs +64 -0
- data/sig/generated/nukadoko/judgment_file.rbs +39 -0
- data/sig/generated/nukadoko/judgments.rbs +120 -0
- data/sig/generated/nukadoko/literal.rbs +71 -0
- data/sig/generated/nukadoko/measured.rbs +42 -0
- data/sig/generated/nukadoko/order.rbs +54 -0
- data/sig/generated/nukadoko/parts.rbs +35 -0
- data/sig/generated/nukadoko/pattern.rbs +28 -0
- data/sig/generated/nukadoko/poll.rbs +40 -0
- data/sig/generated/nukadoko/program.rbs +101 -0
- data/sig/generated/nukadoko/project_fixtures.rbs +57 -0
- data/sig/generated/nukadoko/report_allure.rbs +268 -0
- data/sig/generated/nukadoko/report_messages.rbs +68 -0
- data/sig/generated/nukadoko/report_run.rbs +102 -0
- data/sig/generated/nukadoko/run.rbs +257 -0
- data/sig/generated/nukadoko/run_record.rbs +174 -0
- data/sig/generated/nukadoko/scaffold.rbs +328 -0
- data/sig/generated/nukadoko/schema.rbs +137 -0
- data/sig/generated/nukadoko/secrets.rbs +157 -0
- data/sig/generated/nukadoko/selection.rbs +73 -0
- data/sig/generated/nukadoko/signature.rbs +17 -0
- data/sig/generated/nukadoko/skill.rbs +20 -0
- data/sig/generated/nukadoko/step.rbs +115 -0
- data/sig/generated/nukadoko/summary.rbs +204 -0
- data/sig/generated/nukadoko/table.rbs +43 -0
- data/sig/generated/nukadoko/text_fit.rbs +70 -0
- data/sig/generated/nukadoko/trace.rbs +127 -0
- data/sig/generated/nukadoko/trace_actions.rbs +40 -0
- data/sig/generated/nukadoko/tree_passes.rbs +48 -0
- data/sig/generated/nukadoko/verdict.rbs +56 -0
- data/sig/generated/nukadoko/version.rbs +5 -0
- data/sig/generated/nukadoko/vocabulary.rbs +25 -0
- data/sig/generated/nukadoko/walk.rbs +139 -0
- data/sig/generated/nukadoko/walk_files.rbs +189 -0
- data/sig/generated/nukadoko/walk_step.rbs +50 -0
- data/sig/generated/nukadoko.rbs +15 -0
- data/sig/nukadoko.rbs +5 -48
- data/skills/nukadoko/SKILL.md +120 -0
- data/skills/nukadoko/references/checking-steps.md +200 -0
- data/skills/nukadoko/references/diagnosing.md +200 -0
- data/skills/nukadoko/references/done.md +99 -0
- data/skills/nukadoko/references/evidence.md +124 -0
- data/skills/nukadoko/references/examples/cli.md +230 -0
- data/skills/nukadoko/references/examples/http-api.md +339 -0
- data/skills/nukadoko/references/examples/workflow.md +173 -0
- data/skills/nukadoko/references/exploring.md +184 -0
- data/skills/nukadoko/references/fixtures.md +198 -0
- data/skills/nukadoko/references/from-prose.md +51 -0
- data/skills/nukadoko/references/judgments.md +95 -0
- data/skills/nukadoko/references/maintenance.md +97 -0
- data/skills/nukadoko/references/merge-risk.md +74 -0
- data/skills/nukadoko/references/parts.md +152 -0
- data/skills/nukadoko/references/perturbed-worlds.md +107 -0
- data/skills/nukadoko/references/program.md +200 -0
- data/skills/nukadoko/references/reviewing.md +200 -0
- data/skills/nukadoko/references/running.md +200 -0
- data/skills/nukadoko/references/scenario-rules.md +188 -0
- data/skills/nukadoko/references/states.md +66 -0
- data/skills/nukadoko/references/step-files.md +200 -0
- data/skills/nukadoko/references/verdicts.md +200 -0
- data/skills/nukadoko/references/writing-steps.md +200 -0
- data/skills/nukadoko/references/writing-the-feature.md +165 -0
- data/skills/nukadoko/scripts/claude-code-verdict-hook.mjs +99 -0
- data/skills/nukadoko/scripts/merge-risk.jq +56 -0
- data/skills/nukadoko-verification/SKILL.md +263 -0
- metadata +121 -1
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# The step file and its pattern
|
|
2
|
+
|
|
3
|
+
## The shape of a step file
|
|
4
|
+
|
|
5
|
+
One step per file, as the file's `default` export. Discovery reads that
|
|
6
|
+
export and nothing else, and the file name is the step's name: the
|
|
7
|
+
`nuka do <name>` you call it by, and the name every finding and step
|
|
8
|
+
record uses for it. Feature files and step files both live under the
|
|
9
|
+
configured `featuresDir`, `features` unless the project says otherwise,
|
|
10
|
+
with feature files ending in `.feature`. A file a scenario runs as a process (a fake server, a fixture script) belongs outside `featuresDir`: discovery imports every module under it on every `nuka check`, top-level code included.
|
|
11
|
+
|
|
12
|
+
Step files end in `.ts`, except in a CommonJS project (no
|
|
13
|
+
`"type": "module"` in `package.json`), where they end in `.mts` instead.
|
|
14
|
+
Under `"type": "commonjs"`, Node reads a plain `.ts` file as CommonJS, and
|
|
15
|
+
nukadoko is ESM-only. With no `"type"`, Node loads a `.ts` file only after
|
|
16
|
+
it parses it again, with a `MODULE_TYPELESS_PACKAGE_JSON` warning.
|
|
17
|
+
`nuka init` already wrote a matching `nukadoko.config.mts` in that case
|
|
18
|
+
(`running.md`, "Setting up"), so the same rule applies to every
|
|
19
|
+
step file underneath it.
|
|
20
|
+
|
|
21
|
+
Node runs a step file by erasing its types, so write TypeScript that
|
|
22
|
+
erases cleanly. Import another step file by its own name, `.ts` included
|
|
23
|
+
(`import openAccount from "./open-account.ts"`), the spelling `nuka
|
|
24
|
+
scaffold --from` writes. When `tsconfig.json` sets neither
|
|
25
|
+
`rewriteRelativeImportExtensions` nor `allowImportingTsExtensions`, or a
|
|
26
|
+
file in its `extends` chain cannot be read, scaffold writes `./open-account.js` and a `note:` line instead; `nuka`
|
|
27
|
+
loads the `.ts` file under that name, so keep it. Import a type with `import type`: a type imported
|
|
28
|
+
without it stays an import and fails with "does not provide an export
|
|
29
|
+
named". An `enum`, a `namespace`, or a constructor parameter property does
|
|
30
|
+
not load at all; `nuka check` reports `step-file-import-failed` at its
|
|
31
|
+
line. Write an object with `as const` and a field assigned in the
|
|
32
|
+
constructor instead.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
// features/steps/set-product-out-of-stock.ts
|
|
36
|
+
import { defineStep, z } from "nukadoko";
|
|
37
|
+
|
|
38
|
+
export default defineStep({
|
|
39
|
+
pattern: "the product {sku:string} is out of stock",
|
|
40
|
+
description: "Set a product's stock to zero",
|
|
41
|
+
args: z.object({ sku: z.string().describe("The product's own SKU") }),
|
|
42
|
+
returns: z.object({
|
|
43
|
+
stock: z.number().describe("The stock left after the write"),
|
|
44
|
+
}),
|
|
45
|
+
// mutates defaults to true, so a writing step can leave it out; a step
|
|
46
|
+
// that only reads has to say mutates: false.
|
|
47
|
+
async run({ request }, args) {
|
|
48
|
+
const res = await request.post(`/products/${args.sku}/stock`, {
|
|
49
|
+
data: { stock: 0 },
|
|
50
|
+
});
|
|
51
|
+
return res.json();
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`z` above comes from nukadoko itself, so there is nothing to install
|
|
57
|
+
separately for it. If your own project already uses zod and you want to
|
|
58
|
+
pass one of its own schemas into a step, that schema needs to be zod 4.
|
|
59
|
+
|
|
60
|
+
`pattern` is one string. Use `patterns: [...]` for a step that answers to
|
|
61
|
+
more than one line, and omit both for a step only ever reached by name.
|
|
62
|
+
|
|
63
|
+
`returns` can be left out. It then defaults to an empty object, and `run`
|
|
64
|
+
may return nothing, which fits a Given that only sets something up. A
|
|
65
|
+
Then has no `run` at all: it declares `claims`, and an `observe` when
|
|
66
|
+
no earlier step returned the value (`checking-steps.md`). A Given or When
|
|
67
|
+
that observes something (a page, a response, a file) returns what it
|
|
68
|
+
observed, and declares `returns` for it: without one, a returned key
|
|
69
|
+
fails the step as `result_invalid`, naming the key.
|
|
70
|
+
|
|
71
|
+
`run`'s first argument, and `observe`'s, has to be written as an object destructuring
|
|
72
|
+
pattern, every time, because nukadoko reads which fixtures to build from
|
|
73
|
+
that pattern's source text without ever calling `run`. A step needing no
|
|
74
|
+
fixtures at all writes `run({}, args)`, and one needing neither writes
|
|
75
|
+
`run()`. A fixture the project declares in `nukadoko.config.ts` also needs
|
|
76
|
+
a `StepFixtures` declaration before `tsc` accepts a step that
|
|
77
|
+
destructures it ("Declaring a fixture" in `fixtures.md` shows the block). `run({ sum })` reads `sum` as a fixture; when `sum` is an args
|
|
78
|
+
key, `nuka check` says so and names `run({}, { sum })`. Any other parameter, `_ctx` included, is refused. `page`,
|
|
79
|
+
`context` and `request` are Playwright's own objects, so reach for
|
|
80
|
+
Playwright's documentation for what to call on them rather than guessing.
|
|
81
|
+
On the compat door those same `page` and `request` names are harness
|
|
82
|
+
getters, not bag fields: `defineWorld` refuses them. `nuka check` reports
|
|
83
|
+
`step-file-import-failed`, and `nuka run` stops with the same message,
|
|
84
|
+
which names the field. Reach them with `await this.openPage()` and
|
|
85
|
+
`await this.openRequest()`.
|
|
86
|
+
|
|
87
|
+
A typed step's `run` has a deadline: `stepTimeout` in `nukadoko.config.ts`,
|
|
88
|
+
twenty minutes unless the project sets it. A step that waits longer by
|
|
89
|
+
design (an export, a batch job) declares its own `timeout` in milliseconds
|
|
90
|
+
on `defineStep`, which overrides `stepTimeout` for that step only. There is
|
|
91
|
+
no value meaning "no limit". `nuka steps` and `nuka describe` show a
|
|
92
|
+
declared `timeout`; a step that shows none runs under `stepTimeout`.
|
|
93
|
+
Any other key on `defineStep` (a leftover `rationale`, a misspelling)
|
|
94
|
+
does nothing, and `nuka check` warns `step-option-ignored` for it.
|
|
95
|
+
|
|
96
|
+
## Return more than what a later step cites
|
|
97
|
+
|
|
98
|
+
Basing `returns` on citation alone drops the values this step's own
|
|
99
|
+
correctness depended on but nothing downstream reads (a computed date, a
|
|
100
|
+
chosen id, a resolved name), and those are exactly what a step record gets
|
|
101
|
+
read for once something has failed. Return them even if the scenario never
|
|
102
|
+
reads them back; the alternative is reconstructing what was actually sent
|
|
103
|
+
from another system's error message. This is also what a downstream
|
|
104
|
+
failure's own step record can show you: a failed step's `used` entries
|
|
105
|
+
carry each upstream step's full `result`, so whatever this step declined to
|
|
106
|
+
return is exactly what stays missing from that step record too.
|
|
107
|
+
|
|
108
|
+
## Several people in one scenario
|
|
109
|
+
|
|
110
|
+
When the app tells people apart by a cookie, give each person a browser context of their own:
|
|
111
|
+
`await pageAs(name, { javaScriptEnabled: false })` returns Playwright's
|
|
112
|
+
`Page` (a `context.newPage()` tab shares cookies). Later calls for a name
|
|
113
|
+
return the same page; other options there throw. A name is 1 to 64
|
|
114
|
+
lowercase letters, digits, and hyphens, starting with a letter or digit, or it throws:
|
|
115
|
+
take it from the feature line, lowercased (`pageAs(name.toLowerCase())`); records tag it with `as`.
|
|
116
|
+
|
|
117
|
+
## `page.goto` and baseURL
|
|
118
|
+
|
|
119
|
+
A leading slash in `page.goto("/path")` replaces baseURL's own path, the
|
|
120
|
+
standard URL resolution rule, not something nukadoko adds. Measured
|
|
121
|
+
against Playwright 1.61.1 with `baseURL:
|
|
122
|
+
"https://demo.playwright.dev/todomvc/"`: `goto("/")` lands on
|
|
123
|
+
`https://demo.playwright.dev/`, the host's own root, not the app under
|
|
124
|
+
`/todomvc/`. `goto("./")` and the absolute `goto("/todomvc/")` both land
|
|
125
|
+
on `https://demo.playwright.dev/todomvc/#/` instead. A step whose app
|
|
126
|
+
lives under a path writes one of those two forms for its first
|
|
127
|
+
navigation, never a bare leading slash.
|
|
128
|
+
|
|
129
|
+
## Writing the pattern
|
|
130
|
+
|
|
131
|
+
Every parameter is `{key:type}`, and the key names the `args` field it
|
|
132
|
+
fills: `"a customer {email:string} is onboarded"` fills `args.email`. An
|
|
133
|
+
unnamed `{string}` is refused outright, so there is no shorter form to
|
|
134
|
+
reach for.
|
|
135
|
+
|
|
136
|
+
`{key:string}` only matches text wrapped in double quotes; an unquoted
|
|
137
|
+
value does not match at all, and `nuka check` reports the whole line as
|
|
138
|
+
`undefined-step`. When exactly one pattern fits the line once quoted, the
|
|
139
|
+
finding also names the step, the `{...:string}` parameter, and the line
|
|
140
|
+
rewritten with quotes. `"a customer {email:string} is onboarded"` binds `a customer "ada@example.com" is
|
|
141
|
+
onboarded`, quotes included in the line but stripped from the captured
|
|
142
|
+
value; `a customer ada@example.com is onboarded` binds nothing. `{word}`
|
|
143
|
+
differs on both counts: it matches one unquoted, space-free token with no
|
|
144
|
+
quotes needed, and if a value is quoted anyway, the quotes stay part of
|
|
145
|
+
the captured text instead of being stripped.
|
|
146
|
+
|
|
147
|
+
A pattern is a Cucumber Expression, so three characters are syntax: `/`
|
|
148
|
+
separates alternative words, `(` and `)` mark optional text, and `{`
|
|
149
|
+
opens a capture. A literal one is escaped with a backslash, `I POST this
|
|
150
|
+
body to \/items`, which a JSON string in the step file writes as
|
|
151
|
+
`"I POST this body to \\/items"`. Unescaped, `nuka scaffold` refuses the
|
|
152
|
+
pattern and `nuka check` reports `pattern-syntax-error`, both naming the
|
|
153
|
+
column (`examples/http-api.md`).
|
|
154
|
+
|
|
155
|
+
Do not carry a list of type names around. Get one wrong and `nuka check`
|
|
156
|
+
prints the parameter types **this** project has registered, custom ones
|
|
157
|
+
from `nukadoko.config.ts` included, which is the only list that is true
|
|
158
|
+
here rather than true of nukadoko in general.
|
|
159
|
+
|
|
160
|
+
Add to that list instead of working around it when a pattern keeps
|
|
161
|
+
needing the same shape spelled out by hand. `parameterTypes` in
|
|
162
|
+
`nukadoko.config.ts` takes a `{ name, regexp, transformer? }` entry per
|
|
163
|
+
type: a `negation` type matching an optional `" not"` and turning it into
|
|
164
|
+
a `z.boolean()` lets a pattern write `will{negated:negation} return`
|
|
165
|
+
straight into an `args` key of that type. `transformer` only coerces the
|
|
166
|
+
matched text. It runs with the scenario's World as `this`, and a Promise
|
|
167
|
+
it returns is awaited before the step. The `args` schema is still what
|
|
168
|
+
actually validates it. The
|
|
169
|
+
one thing a project cannot do is redefine a built-in name (`int`,
|
|
170
|
+
`string`, and the rest): that would quietly change what every pattern
|
|
171
|
+
already using it means.
|
|
172
|
+
|
|
173
|
+
The pattern and the schema are checked against each other, both ways: a
|
|
174
|
+
key the pattern captures that `args` has no field for is an error, and so
|
|
175
|
+
is a required `args` field that nothing captures and no `from` fills.
|
|
176
|
+
Neither side can drift away from the other quietly, so adding an `args`
|
|
177
|
+
field and forgetting the capture costs you one `nuka check`, never a
|
|
178
|
+
browser session.
|
|
179
|
+
|
|
180
|
+
`capture-type-mismatch` is the type half of that comparison: the JS type
|
|
181
|
+
of a built-in capture against the field's primitive type. `{int}`,
|
|
182
|
+
`{float}`, `{double}`, `{byte}`, `{short}`, and `{long}` give a number;
|
|
183
|
+
`{word}`, `{string}`, the anonymous `{key:}`, and `{bigdecimal}` give a
|
|
184
|
+
string; `{biginteger}` gives a bigint. A number capture against a string
|
|
185
|
+
or boolean field is the finding, and so is any other pair that differs. A
|
|
186
|
+
pipe or transform is read through its input side. A union, `z.any()`, a
|
|
187
|
+
preprocess, and a custom parameter type are never reported. It does not fire when the schema coerces the captured value
|
|
188
|
+
(`z.coerce.number()` for a `{string}`, `z.coerce.string()` for an
|
|
189
|
+
`{int}`), because the run accepts that capture. A field that does not
|
|
190
|
+
coerce still is that finding. The one-line description is `nuka check
|
|
191
|
+
--codes`.
|
|
192
|
+
|
|
193
|
+
A record stores a bigint as its decimal string, and `nuka do --args`
|
|
194
|
+
takes a `z.bigint()` field the same way (`{"count":"123"}`), not as a JSON
|
|
195
|
+
number.
|
|
196
|
+
|
|
197
|
+
Capturing the same key twice in one pattern is refused too. One args
|
|
198
|
+
field holds one value, and keeping the last capture would drop the
|
|
199
|
+
earlier one. `nuka check` reports it and `nuka run` refuses the binding
|
|
200
|
+
before the step body runs, and both name the key.
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# Reading the verdict table
|
|
2
|
+
|
|
3
|
+
A run ends in one table, run.json's `table`, and the run summary opens
|
|
4
|
+
with it: one row per criterion, one column per world and environment
|
|
5
|
+
(`head <environment>`, then the conditions it declares, and under
|
|
6
|
+
`--base` also `base <environment>` and `old <environment>`), and one
|
|
7
|
+
verdict per row, which the exit code follows. Under the table, each red
|
|
8
|
+
row gets one line that says why and where it stopped. `failed`,
|
|
9
|
+
`unproven`, and `moved` are red; `held`, `proven`, and `removed` are green.
|
|
10
|
+
|
|
11
|
+
## A scenario behind a switch
|
|
12
|
+
|
|
13
|
+
A passing scenario shows the code does what it says, not that the
|
|
14
|
+
scenario would notice if it did not. A feature behind a switch can show
|
|
15
|
+
that: give each side of the switch an environment that names its side in
|
|
16
|
+
`conditions` (`references/program.md`, "Environments and programs nukadoko
|
|
17
|
+
does not start"), and tag the scenario on its Feature, Rule, Scenario, or Examples line:
|
|
18
|
+
|
|
19
|
+
- `@with:<condition>`: the condition is on (`true`, or any value).
|
|
20
|
+
- `@with:<condition>=<value>`: it has exactly that string. `=true` and
|
|
21
|
+
`=false` are malformed: write `@with:` or `@without:`.
|
|
22
|
+
- `@without:<condition>`: it is off (`false`, or not declared).
|
|
23
|
+
|
|
24
|
+
Its cell is required where the environment meets every tag and a control
|
|
25
|
+
elsewhere; an untagged scenario is required everywhere. Each cell in
|
|
26
|
+
run.json names the conditions its role came from. nukadoko trusts
|
|
27
|
+
`conditions` and does not check them against the program, so derive the
|
|
28
|
+
switch from them with `{condition.<name>}` (`references/program.md`).
|
|
29
|
+
`nuka run` without `--env` runs every environment that declares `conditions`, or
|
|
30
|
+
the ones the program file's `defaultEnvironments` names. Under `--env`,
|
|
31
|
+
a scenario no named environment meets is not run, and the summary's
|
|
32
|
+
`left-out` entry counts it (`<n> criteria not run`). A control never turns the run red. Tag only what the criteria say depends
|
|
33
|
+
on the switch, and write the Then so it would fail on the other side: a
|
|
34
|
+
When that errors there proves nothing. A time zone, a clock, or a seed no criterion
|
|
35
|
+
may depend on gets environments and no tag (`references/perturbed-worlds.md`).
|
|
36
|
+
|
|
37
|
+
When the program writes `flag` lines to `{events}` (`references/program.md`),
|
|
38
|
+
run.json's `flags` has one row per flag and side the head steps' lines named
|
|
39
|
+
(the side the program got, not the one `conditions` declares), listing the
|
|
40
|
+
criteria that evaluated it there, with their `verdict`, cells, and `gates`,
|
|
41
|
+
and `counts` by verdict (`controls` for one seen there only in controls).
|
|
42
|
+
The summary gives each row a line under "Flags". Read it before a flag is turned on for everyone: `failed` on
|
|
43
|
+
the `on` side is a criterion that does not hold with the flag on, and a
|
|
44
|
+
control listed only under the side its environment does not declare never ran
|
|
45
|
+
the side it was meant to. Join a row with the program's own record of the flag
|
|
46
|
+
by `name` and `side`. Two environments whose `conditions` differ in one get
|
|
47
|
+
run.json's `paths` too: each criterion's steps compared by what the program
|
|
48
|
+
did (`changed`, `open` while a side's lines may still come, `same_so_far`
|
|
49
|
+
when what came reads alike, `same`), under "Changed paths". Both are
|
|
50
|
+
evidence; turning the flag on is the person's call.
|
|
51
|
+
|
|
52
|
+
## Where no step looked
|
|
53
|
+
|
|
54
|
+
`lists` in the program file (`references/program.md`, docs/spec.md
|
|
55
|
+
"Lists") names the routes and flags the program has, so run.json can
|
|
56
|
+
name the places no step reached. With a routes list, `routes` has an
|
|
57
|
+
entry per method and route a list or a head step's `request` line
|
|
58
|
+
names: `requests` (0 for a route no step requested), `statuses`,
|
|
59
|
+
`listed_in` (empty for a route no list names), `handlers`, and the
|
|
60
|
+
criteria that sent them. A request is not a check: a Given's counts as a
|
|
61
|
+
Then's, so a route with requests may still be one no claim reads. The
|
|
62
|
+
summary's "Routes" names the listed routes no step requested, apart from
|
|
63
|
+
a PATCH whose handler a PUT reached, and the requests no list names. A
|
|
64
|
+
world whose list was not read gives no `routes` and a
|
|
65
|
+
`program-list-unread` warning: fix the command before reading a gap.
|
|
66
|
+
With a flags list, `flags` has a row for every side it declares, with
|
|
67
|
+
no `criteria` for a side no criterion evaluated, and `listed_in`;
|
|
68
|
+
`only_side_evaluated: true` (the summary's "only this side was
|
|
69
|
+
evaluated") marks a flag whose other sides never ran.
|
|
70
|
+
Tell the person which routes no criterion requested; whether one needs a
|
|
71
|
+
criterion is theirs to decide.
|
|
72
|
+
|
|
73
|
+
## Compared with the base
|
|
74
|
+
|
|
75
|
+
`nuka run --base <the base>` is the run a pull request carries. It
|
|
76
|
+
compares each criterion with the base: `unchanged` (a rename, a move, or
|
|
77
|
+
a tag such as `@smoke` changes nothing), `changed` (an edit to a step, a
|
|
78
|
+
table, a docstring, an Examples row, a condition tag, or an `@expects:` tag), `new`, or
|
|
79
|
+
`removed`. The summary's first line says what changed, and whether the
|
|
80
|
+
mapping did: a step file or helper under the features directory, the
|
|
81
|
+
config's fixtures or parameter types, an environment's conditions.
|
|
82
|
+
|
|
83
|
+
- A `new` or `changed` row also runs in the `base` world, the base's
|
|
84
|
+
code under your criteria and steps. Its Then has to fail there, at one
|
|
85
|
+
line in each of `--proof-runs` runs, for the row to be `proven`. Write
|
|
86
|
+
the Then so it fails without the change: a When that errors there
|
|
87
|
+
proves nothing.
|
|
88
|
+
- An `unchanged` row, when the mapping changed, its tags did
|
|
89
|
+
(`retagged`), or its name or file did (`renamed_from`), also runs in the `old` world, your code under the base's feature file, steps, and conditions, and has to
|
|
90
|
+
pass there. A rewritten step that now checks less is what this catches.
|
|
91
|
+
- When both program files name `{events}`, the base also runs every row
|
|
92
|
+
head ran, once, for run.json's `paths` alone (`for_paths`, `(for paths)`
|
|
93
|
+
on stderr; no cell, no proof runs), and `paths` pairs each environment's
|
|
94
|
+
base with its head, step by step: "Changed paths" lists under
|
|
95
|
+
`base → head` what the program does differently at head, the criteria
|
|
96
|
+
that did not change included, a refactor's too: head's `{events}` alone
|
|
97
|
+
builds the base world. A changed criterion there has `explained_by`:
|
|
98
|
+
`intent` when rows of the change's `INTENT.md` declare every difference
|
|
99
|
+
(`references/done.md`), `criterion_change` when its sentences are new
|
|
100
|
+
or changed, and `null` otherwise; the summary lists the `null` ones
|
|
101
|
+
first, and says when every unchanged criterion did the same. Tell the
|
|
102
|
+
person; it is evidence, and a `null` one is the first thing to read. A
|
|
103
|
+
write to a table `lists.tables` marks as bookkeeping or infrastructure
|
|
104
|
+
is listed after the rest (`holds`; `marked_only` when it is all that
|
|
105
|
+
differs): no sentence is about it, but another reader of that table,
|
|
106
|
+
such as a guard on telemetry, may be.
|
|
107
|
+
|
|
108
|
+
## The cells
|
|
109
|
+
|
|
110
|
+
A cell reads `pass`; `fail@<line>`, a claim broke at that Then line;
|
|
111
|
+
`broke@<line>`, it stopped there before a claim was judged; `flaky@<line>`,
|
|
112
|
+
its runs disagree; or `·`, it did not run, and its `reason` says why.
|
|
113
|
+
Only a claim proves: a failed assertion in a compat or `run` step bound
|
|
114
|
+
in Then position is `broke`, so a compat suite's rows are `held` or
|
|
115
|
+
`failed`, never `proven`, until their Thens become claim steps. Under
|
|
116
|
+
`--base`, a new or changed one is `unproven` for that reason, which its
|
|
117
|
+
reason names, unless it is tagged `@held` and passes at the base.
|
|
118
|
+
`(control)` marks a control, and `(2 runs)` how often it ran. A control
|
|
119
|
+
that failed at a Then line runs again until it has broken the same claim
|
|
120
|
+
there `--proof-runs` times (2 by default), each a `proof run <k>/<n>` line on
|
|
121
|
+
stderr. Under `--concurrency`, a proof round whose worker could not
|
|
122
|
+
finish (its BeforeAll or AfterAll failed) leaves the control `broke` with
|
|
123
|
+
the reason and a `proof-run-incomplete` warning: the row reads as one
|
|
124
|
+
no control proves (under `--base`, its base cell decides), so correct
|
|
125
|
+
the hook. A `broke` cell whose reason says a claim was judged before every
|
|
126
|
+
execution event it counts had arrived (`claim-judged-early`) was judged on
|
|
127
|
+
lines still on their way (its `after_world_stop` has the whole count): have
|
|
128
|
+
the program write a request's line after the work inside it, and work that
|
|
129
|
+
outlives the request as a job (docs/execution-events.md "Inside first").
|
|
130
|
+
|
|
131
|
+
A `broke` cell with an `unexpected-failure` finding passed over a program
|
|
132
|
+
that failed under a step in a way no tag names: a 5xx response, an uncaught
|
|
133
|
+
page error, or an `error` reported with `handled: false`. Fix the program.
|
|
134
|
+
Only when the criteria say the scenario causes that failure (a maintenance
|
|
135
|
+
page) tag it `@expects:status=<500-599>`, `@expects:page-error=<name>`, or
|
|
136
|
+
`@expects:error=<class>`, as the `fix:` line spells it, and ask the person:
|
|
137
|
+
the tag is part of the criterion. `expects-unseen` notes a tag that matched
|
|
138
|
+
nothing; `nuka check` reports `expects-tag-malformed` and `expects-unread`.
|
|
139
|
+
|
|
140
|
+
## What to do for each verdict
|
|
141
|
+
|
|
142
|
+
- **`failed`**: a required head cell did not pass. Diagnose it like any
|
|
143
|
+
failure (`references/diagnosing.md`). A row with no required cell is
|
|
144
|
+
`failed` too: no environment of the default selection meets its tags.
|
|
145
|
+
`nuka check` reports that first as `condition-unmet`, and a run under
|
|
146
|
+
`--no-check` as `criterion-without-required-cell`, whose `do:` runs it
|
|
147
|
+
where it is met; add the environment, or correct the tags.
|
|
148
|
+
- **`proven`**: it passed where it is required, and a control broke a
|
|
149
|
+
the same claim at one Then line in each of `--proof-runs` runs: the
|
|
150
|
+
scenario tells the behaviour apart. Nothing to do. A control's failure
|
|
151
|
+
has no `do:` and is not a failure to fix.
|
|
152
|
+
- **`held`**: it passed where it is required, and nothing showed it would
|
|
153
|
+
notice otherwise. With no control (an untagged scenario, or a run of one
|
|
154
|
+
environment), that is all a run can say. With a control that passed,
|
|
155
|
+
the Then does not check what the switch changes, or the switch does not
|
|
156
|
+
reach what the Then reads: report the row to the person rather than
|
|
157
|
+
calling the criterion covered, and do not rewrite the Then on your own
|
|
158
|
+
to make the control fail. A control that is `broke@<line>` proves
|
|
159
|
+
nothing either: a Given or When failed where the behaviour is absent,
|
|
160
|
+
before any Then was judged. Under `--base`, an `unchanged` row no
|
|
161
|
+
control proves is `held` when the mapping did not change or the old
|
|
162
|
+
world passed it, and a `@held` row when the base passed it.
|
|
163
|
+
- **`unproven`** (red): a `new` or `changed` row passed, and nothing
|
|
164
|
+
shows its Then failing without the change: the base passed it, broke
|
|
165
|
+
before a Then, or did not run. When the base already had the behaviour
|
|
166
|
+
(a scenario written for code that works), tag it `@held` and ask the
|
|
167
|
+
person to confirm; otherwise the Then does not see what the change did,
|
|
168
|
+
which is the person's to hear about, not a Then to weaken.
|
|
169
|
+
- **`moved`** (red): an `unchanged` row passed at head, but not under
|
|
170
|
+
the base's steps, so the approved sentence no longer means what it
|
|
171
|
+
meant. Read the reason: a step that now checks something else is a
|
|
172
|
+
change to report to the person; a reason that says the base's steps
|
|
173
|
+
did not load (a module of the program they import moved) means the
|
|
174
|
+
refactor broke the old steps, and docs/upgrading.md in the package says
|
|
175
|
+
how to land one.
|
|
176
|
+
- **`removed`**: the base had the criterion and you dropped it. The
|
|
177
|
+
summary quotes it under "Removed criteria" so the person sees it went.
|
|
178
|
+
|
|
179
|
+
Each `unproven` and `moved` row is also a `criterion-unproven` or
|
|
180
|
+
`criterion-moved` finding; its `do:` line judges the row again against the
|
|
181
|
+
same base by its commit hash, which holds after you commit or the base moves.
|
|
182
|
+
A reason that says `--base` does not support a shape yet (a symbolic link, a
|
|
183
|
+
feature file outside the features directory, a workspace package, a
|
|
184
|
+
submodule) means that world was not built: make the `fix:` edit, or run the
|
|
185
|
+
`do:` line, which leaves `--base` off, and tell the person the row was not
|
|
186
|
+
judged against the base.
|
|
187
|
+
|
|
188
|
+
## The findings
|
|
189
|
+
|
|
190
|
+
`nuka check` reads the tags against the environments a run would select
|
|
191
|
+
(`nuka check --env` names them as `nuka run --env` does).
|
|
192
|
+
`condition-tag-malformed` is a tag that is none of the three forms.
|
|
193
|
+
`condition-unknown` names a condition no environment declares: when the
|
|
194
|
+
switch was removed, the side whose code stayed decides, so the `@with:`
|
|
195
|
+
side keeps the scenario and the tag goes, and the other side means the
|
|
196
|
+
scenario goes. `condition-unmet` is a scenario no environment of the
|
|
197
|
+
default selection meets; under `--env` it is left out, not reported.
|
|
198
|
+
A run that leaves out every scenario it selected runs nothing and fails
|
|
199
|
+
with `nothing-selected`: nothing checked is no pass.
|
|
200
|
+
`@held` is kept in the row's `conditions`, and only `--base` reads it.
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# Writing a step
|
|
2
|
+
|
|
3
|
+
Finding a step, scaffolding it, running it alone, and chaining it. The
|
|
4
|
+
file's shape and its pattern: `step-files.md`. A Then, which claims:
|
|
5
|
+
`checking-steps.md`. Helpers, parts, and splitting: `parts.md`. Fixtures,
|
|
6
|
+
`scratch`, and `poll`: `fixtures.md`. States: `states.md`.
|
|
7
|
+
|
|
8
|
+
## Reading the vocabulary
|
|
9
|
+
|
|
10
|
+
`nuka steps --json` lists the whole vocabulary; `nuka describe <step>`
|
|
11
|
+
gives one step's full contract; read the JSON itself for the field
|
|
12
|
+
shapes. Both name any step file that failed to import beside everything
|
|
13
|
+
else they could still read, and `nuka check` is where to fix the import.
|
|
14
|
+
When a step's args or returns schema cannot be represented as JSON
|
|
15
|
+
Schema (a `z.date()`, say), `nuka describe` still prints that step's
|
|
16
|
+
contract with `args_error` or `returns_error` naming the step, and exits
|
|
17
|
+
1. `nuka run` and `nuka do` run the step anyway: zod still validates the
|
|
18
|
+
values, and only the published contract is missing.
|
|
19
|
+
|
|
20
|
+
Two fields carry less than they look like they do. A `needs` of `null`
|
|
21
|
+
means this tool could not read that step's `run()`, so its fixture
|
|
22
|
+
contract is unknown, not empty. A `needs_inferred` list is a lexical
|
|
23
|
+
guess at the same question: a starting inventory, never a finished one,
|
|
24
|
+
and never grounds for concluding a step needs no browser.
|
|
25
|
+
|
|
26
|
+
Prefer what already exists: if an acceptance condition fits an existing
|
|
27
|
+
step, use it, even when the criterion's wording differs from its pattern.
|
|
28
|
+
|
|
29
|
+
## When the vocabulary has no step for it
|
|
30
|
+
|
|
31
|
+
Read the `undefined-step` message first. When it ends with `patterned
|
|
32
|
+
steps no scanned feature line binds:`, a step that already exists lost
|
|
33
|
+
its line, usually through a renamed sentence or a renamed pattern. Fix
|
|
34
|
+
the line or the pattern instead of scaffolding a second step.
|
|
35
|
+
|
|
36
|
+
Scaffold producers before consumers. `--from <step>.<key>` reads the
|
|
37
|
+
producer's `returns`, and a producer that is still a stub declares none:
|
|
38
|
+
`nuka scaffold` refuses with `<step> declares no returns, so it has no
|
|
39
|
+
key to chain`. So write each Given's `returns` first, then the When that
|
|
40
|
+
reads from it, then the Thens that read from the When.
|
|
41
|
+
|
|
42
|
+
When the feature already holds the lines, `nuka scaffold --feature
|
|
43
|
+
<file>` (the `do:` line of the `undefined-step` finding, with the file
|
|
44
|
+
filled in) writes one stub for each line `nuka check <file>` calls
|
|
45
|
+
undefined, with the pattern read from the line: a quoted value is
|
|
46
|
+
`{value:string}`, an integer `{value:int}`, a decimal `{value:float}`, and
|
|
47
|
+
a Then line gets a claim step: an `observe` that throws under a TODO and a
|
|
48
|
+
claim on the `actual` it returns. Return the observed value, or take it
|
|
49
|
+
through `from` and drop `observe`. Rename `value`, `value2` to what the
|
|
50
|
+
values mean, in the pattern and in `args` together. A `note:` line on
|
|
51
|
+
stderr names each line whose reading was not the only one, or would also
|
|
52
|
+
match another line: that stub's pattern is the line as written, with no
|
|
53
|
+
capture, so put the captures in by hand. A `next:` block on stderr gives
|
|
54
|
+
each stub's own single scaffold with `--replace`; add `--command` or
|
|
55
|
+
`--from` to it, as below (`--replace` refuses a file anyone edited).
|
|
56
|
+
|
|
57
|
+
1. `nuka scaffold <name> --pattern "<feature line>"`, kebab-case, one
|
|
58
|
+
file per step. Each `{key:type}` capture becomes an args field, so the
|
|
59
|
+
file passes `nuka check` against that line before `run` is written. A
|
|
60
|
+
type the project does not register is refused with the registered
|
|
61
|
+
names listed: a number is `{key:int}` or `{key:float}`, not
|
|
62
|
+
`{key:number}`. A pattern that is not a valid Cucumber Expression is
|
|
63
|
+
refused too ("Writing the pattern" in `step-files.md`).
|
|
64
|
+
Add `--then` for a step a Then line binds: it writes a claim step,
|
|
65
|
+
`claims` in place of `run`, with no `returns` and no `mutates`. With
|
|
66
|
+
one value the line states and one `--from`, the claim compares the two
|
|
67
|
+
with `equal` (`view: "text"` for `stdout` or `stderr`); otherwise it
|
|
68
|
+
writes an `observe` stub. It refuses a line that states no value, two
|
|
69
|
+
values of two JSON types, and a claim that leaves a stated value
|
|
70
|
+
unread. A step whose feature lines carry a docstring or a table gets
|
|
71
|
+
a `docstring` or `table` key, which a Then
|
|
72
|
+
claims like a capture; write the feature line first, or add the key by
|
|
73
|
+
hand, or `nuka check` reports `table-docstring-key-mismatch`.
|
|
74
|
+
Add `--from <step>.<key>` for each value the step reads from an
|
|
75
|
+
earlier step's result: it writes the import, the args field, and the
|
|
76
|
+
`from` entry ("Chaining a value from an earlier step"). Repeat it with
|
|
77
|
+
the same key for a key that either of two producers fills
|
|
78
|
+
(`--from a.dir --from b.dir`); their schemas for the key must match.
|
|
79
|
+
Add `--command <entry point>` for a When step that runs a program
|
|
80
|
+
(`--command src/cli.ts`, relative to the directory `nuka` runs in, and
|
|
81
|
+
refused unless a file is there): it writes `const cli = resolve("<entry
|
|
82
|
+
point>")`, the `runCommand` call in an empty `scratch.dir()`, and
|
|
83
|
+
`returns` of `exitCode`, `stdout`, and `stderr`. A file a Given wrote
|
|
84
|
+
is in the directory that Given returned: `--from <given>.dir --cwd dir`
|
|
85
|
+
runs the program there (`examples/cli.md`). Only captures are argv;
|
|
86
|
+
`--argv <key>` splits one on whitespace only (`"input.csv --json"`),
|
|
87
|
+
and any other `--from` value throws by name until you pass it (`env`).
|
|
88
|
+
The entry point runs under plain `node`, so when `.ts` files import
|
|
89
|
+
each other as `./x.js`, name the built program (`dist/cli.js`, with
|
|
90
|
+
`"pretest:scenarios": "npm run build"`). Without a value the `cli` line
|
|
91
|
+
holds a TODO that throws `fill in the entry point: <file>:<line>`.
|
|
92
|
+
Add `--request "<METHOD> <path>"` for a When step that calls an HTTP
|
|
93
|
+
API: one `request.fetch(path, { method })` on Playwright's `request`,
|
|
94
|
+
against the world's URL, returning `status` and `body` (the text). A `{key}`
|
|
95
|
+
in the path is that args key's value (`"GET /items/{id}"`), `--body
|
|
96
|
+
<key>` sends one as the data (`--body docstring`), and any other value
|
|
97
|
+
throws by name until you pass it. Quote a path in the feature line
|
|
98
|
+
(`When I request "/health"`) so `--feature` reads it as a value.
|
|
99
|
+
`--command` and `--request` write `mutates: true`, because scaffold
|
|
100
|
+
cannot know what the call writes; set it to `false`, with a comment
|
|
101
|
+
that says why, when it writes nothing a later scenario could read.
|
|
102
|
+
Add `--description "<text>"` for what the step does. Without it,
|
|
103
|
+
`--command` and `--request` write a description of what they generate;
|
|
104
|
+
any other form writes `TODO: describe <name>`, which `nuka check`
|
|
105
|
+
notes as `step-description-todo`. Leave `--pattern` out for a step reached by name only.
|
|
106
|
+
2. Implement it. The shape of that file is in `step-files.md`.
|
|
107
|
+
3. `nuka do <step> --args '<json>'`, exercise it alone, check the step
|
|
108
|
+
record, before it ever touches a feature. Fix and re-run until it does
|
|
109
|
+
what it's supposed to; only move on to the feature-level `nuka run` once
|
|
110
|
+
every new step in the scenario has passed this way on its own. A mid-flow
|
|
111
|
+
step runs as a part of a step that reaches that point; when that state
|
|
112
|
+
cannot be repeated, explore it through a Playwright MCP server first
|
|
113
|
+
(`references/exploring.md`).
|
|
114
|
+
|
|
115
|
+
## Asking before a step changes something
|
|
116
|
+
|
|
117
|
+
`mutates` defaults to `true`: a new step is assumed to change state unless
|
|
118
|
+
it says `mutates: false`, and `nuka describe <step>` shows which. Declare
|
|
119
|
+
what the step does, not what is convenient: a step that writes to the
|
|
120
|
+
application under test keeps `mutates: true`, and a step that only reads,
|
|
121
|
+
or only runs a program that writes nothing, says `mutates: false`.
|
|
122
|
+
|
|
123
|
+
The go-ahead depends on what the step reaches, not on the flag alone.
|
|
124
|
+
Before the *first* `nuka do` of a `mutates: true` step that reaches past
|
|
125
|
+
the project (a real service, a shared database, a file outside
|
|
126
|
+
`scratch`), tell the user what it is about to change and get their
|
|
127
|
+
go-ahead, once per step, not on every retry while fixing it, or
|
|
128
|
+
trial-and-error stops being possible. A step that writes only under
|
|
129
|
+
`scratch`, or to a server a fixture or `nukadoko.program.ts` started, needs no
|
|
130
|
+
go-ahead (`examples/http-api.md`), nor does a claim or `mutates: false` step.
|
|
131
|
+
|
|
132
|
+
With nobody to ask mid-task, because the caller handed the task over
|
|
133
|
+
rather than sitting in the conversation, the go-ahead has to exist before
|
|
134
|
+
the work starts. Either the instruction already covered these steps, and
|
|
135
|
+
your report says which, or it did not, and you list what you intend to
|
|
136
|
+
run and what each changes before starting. Running one and mentioning it
|
|
137
|
+
afterwards, because asking was inconvenient, is the one wrong answer.
|
|
138
|
+
|
|
139
|
+
If the same step still fails after three fix-and-retry cycles, stop and
|
|
140
|
+
report where it stands instead of guessing further. A prompt asking for a
|
|
141
|
+
different amount of patience ("try up to 10 times") overrides this
|
|
142
|
+
default; it is not a config setting. The same budget covers `nuka do
|
|
143
|
+
--use` while diagnosing a failed run (`references/diagnosing.md`).
|
|
144
|
+
|
|
145
|
+
## Running a step alone before it touches a feature
|
|
146
|
+
|
|
147
|
+
If the step body needs a local variable with the same name as a fixture,
|
|
148
|
+
destructure that fixture under an alias (`run({ page: pwPage, section },
|
|
149
|
+
args)`) instead of reusing the name: a same-named local shadows the fixture
|
|
150
|
+
silently rather than failing loudly.
|
|
151
|
+
|
|
152
|
+
`do` gives every call its own browser; `run` shares one page across a
|
|
153
|
+
scenario's steps, so a step green under `do` can still fail under `run` if
|
|
154
|
+
it depends on state an earlier step left (signed in, navigated elsewhere, a
|
|
155
|
+
dialog left open). Passing alone under `do` checks that each step works on
|
|
156
|
+
its own, not that it works in the scenario's own order; only `run` checks
|
|
157
|
+
that. Nothing carries across `do` calls or into a scenario, login state
|
|
158
|
+
included, so shared state needs fixing in the feature: give it its own
|
|
159
|
+
step, named for what it establishes, and call it once. A scenario that
|
|
160
|
+
needs to be signed in gets it from a fixture or a Given (`states.md`).
|
|
161
|
+
|
|
162
|
+
A step that declares `from` (see "Chaining a value from an earlier step"
|
|
163
|
+
below) still runs alone: pass the key in `--args` like any other, or add
|
|
164
|
+
`--use <step-record-id>` to take it from the result of an execution you
|
|
165
|
+
already have. The upstream step's name never goes on the command line, the
|
|
166
|
+
cited step record already records which step it belongs to. Repeat `--use`
|
|
167
|
+
for as many upstreams as the step reads.
|
|
168
|
+
|
|
169
|
+
## Chaining a value from an earlier step
|
|
170
|
+
|
|
171
|
+
When a step needs a value an earlier step produced, reach for `from` first:
|
|
172
|
+
`from: { key: [otherStep, "resultKey"] }` declares it, and the value is
|
|
173
|
+
filled in before the step runs (the argument stays required, and the
|
|
174
|
+
scenario reads as what actually chains to what). For a new step, `nuka
|
|
175
|
+
scaffold <name> --from other-step.resultKey` writes it: the import, the
|
|
176
|
+
args field typed by the producer's own schema
|
|
177
|
+
(`resultKey: otherStep.returns.shape.resultKey`), and the `from` entry.
|
|
178
|
+
Only fall back to the `resultOf` fixture inside `run` (it throws in a claim
|
|
179
|
+
step) for a read `from` cannot express: the value needs reshaping on the
|
|
180
|
+
way, which upstream step to read is decided at run time, or the whole
|
|
181
|
+
result is wanted rather than one key of it.
|
|
182
|
+
|
|
183
|
+
A value that can arrive two ways (created in one scenario, imported in
|
|
184
|
+
another) lists both, and the consuming step stays one step: `from: { key:
|
|
185
|
+
[[stepA, "id"], [stepB, "projectId"]] }`. There is no priority between them
|
|
186
|
+
and no rule to memorize: exactly one of the listed producers has to be
|
|
187
|
+
bound earlier in that scenario, so a scenario containing both is an error
|
|
188
|
+
rather than a coin flip. If a scenario genuinely exercises both producers,
|
|
189
|
+
they are not alternatives at all: give each its own args key and let the
|
|
190
|
+
step read both.
|
|
191
|
+
|
|
192
|
+
When the same producer runs more than once in a scenario, `from` reads
|
|
193
|
+
its most recent result: two registrations followed by "the confirmation
|
|
194
|
+
link is opened" confirm the second one (`examples/workflow.md`).
|
|
195
|
+
|
|
196
|
+
Declaring `from` is not just documentation: `nuka check` reads it and
|
|
197
|
+
verifies the producing step actually appears earlier in the same scenario,
|
|
198
|
+
before anything runs. Run `nuka check <feature>` before the first `nuka
|
|
199
|
+
run` so a broken binding order is caught without spending a browser session
|
|
200
|
+
on it.
|