nukadoko 0.5.0 → 0.7.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 +553 -3
- data/README.ja.md +22 -6
- data/README.md +13 -7
- data/docs/ci.ja.md +542 -0
- data/docs/ci.md +635 -0
- data/docs/commands.ja.md +1524 -0
- data/docs/commands.md +1281 -0
- data/docs/engines.json +19 -0
- data/docs/execution-events.ja.md +336 -0
- data/docs/execution-events.md +423 -0
- data/docs/glossary.json +1348 -0
- data/docs/guide.ja.md +733 -0
- data/docs/guide.md +815 -0
- data/docs/intent.ja.md +133 -0
- data/docs/intent.md +156 -0
- data/docs/layout.ja.md +442 -0
- data/docs/layout.md +399 -0
- data/docs/releasing.ja.md +186 -0
- data/docs/releasing.md +237 -0
- data/docs/ruby/reference.ja.md +302 -0
- data/docs/ruby/reference.md +368 -0
- data/docs/spec.ja.md +8916 -0
- data/docs/spec.md +11250 -0
- data/docs/tutorial.ja.md +451 -0
- data/docs/tutorial.md +458 -0
- data/docs/typescript/adopting.ja.md +231 -0
- data/docs/typescript/adopting.md +251 -0
- data/docs/typescript/doors.ja.md +301 -0
- data/docs/typescript/doors.md +329 -0
- data/docs/typescript/migration-playwright-test.ja.md +189 -0
- data/docs/typescript/migration-playwright-test.md +212 -0
- data/docs/typescript/migration.ja.md +391 -0
- data/docs/typescript/migration.md +505 -0
- data/docs/typescript/reference.ja.md +176 -0
- data/docs/typescript/reference.md +197 -0
- data/docs/typescript/upgrading.ja.md +1774 -0
- data/docs/typescript/upgrading.md +2224 -0
- data/docs/web-app.ja.md +627 -0
- data/docs/web-app.md +659 -0
- data/docs/writing-scenarios.ja.md +544 -0
- data/docs/writing-scenarios.md +563 -0
- data/lib/nukadoko/base.rb +12 -5
- data/lib/nukadoko/changed_files.rb +95 -0
- data/lib/nukadoko/check.rb +459 -51
- data/lib/nukadoko/claim_drops.rb +271 -0
- data/lib/nukadoko/claim_line.rb +24 -4
- data/lib/nukadoko/claim_rules.rb +143 -1
- data/lib/nukadoko/claim_sides.rb +157 -9
- data/lib/nukadoko/cli.rb +403 -50
- data/lib/nukadoko/codes.json +246 -21
- data/lib/nukadoko/codes.rb +21 -4
- data/lib/nukadoko/command.rb +120 -13
- data/lib/nukadoko/command_help.rb +128 -0
- data/lib/nukadoko/compat.rb +469 -0
- data/lib/nukadoko/criteria.rb +1 -1
- data/lib/nukadoko/definition.rb +157 -7
- data/lib/nukadoko/error_frames.rb +6 -3
- data/lib/nukadoko/events/count.rb +146 -0
- data/lib/nukadoko/events/counted.rb +114 -0
- data/lib/nukadoko/events/format.rb +257 -0
- data/lib/nukadoko/events/lists.rb +154 -0
- data/lib/nukadoko/events/path.rb +285 -0
- data/lib/nukadoko/events/read.rb +284 -0
- data/lib/nukadoko/events/reader.rb +490 -0
- data/lib/nukadoko/events/selection.rb +252 -0
- data/lib/nukadoko/events/tally.rb +438 -0
- data/lib/nukadoko/features.rb +2 -2
- data/lib/nukadoko/fixtures.rb +160 -35
- data/lib/nukadoko/http_recording.rb +6 -2
- data/lib/nukadoko/intent.rb +364 -0
- data/lib/nukadoko/intent_file.rb +81 -0
- data/lib/nukadoko/intent_view.rb +190 -0
- data/lib/nukadoko/js_json.rb +2 -1
- data/lib/nukadoko/judge.rb +2 -2
- data/lib/nukadoko/judgment_file.rb +22 -1
- data/lib/nukadoko/judgments.rb +33 -3
- data/lib/nukadoko/measure_mcp.rb +202 -0
- data/lib/nukadoko/parts.rb +8 -2
- data/lib/nukadoko/path_view.rb +252 -0
- data/lib/nukadoko/place_rows.rb +161 -0
- data/lib/nukadoko/program.rb +1265 -51
- data/lib/nukadoko/program_log.rb +122 -0
- data/lib/nukadoko/program_shape.rb +385 -0
- data/lib/nukadoko/project_fixtures.rb +43 -10
- data/lib/nukadoko/project_program.rb +5 -4
- data/lib/nukadoko/repeated_prefix.rb +310 -0
- data/lib/nukadoko/report_run.rb +3 -3
- data/lib/nukadoko/run.rb +1156 -159
- data/lib/nukadoko/run_record.rb +70 -46
- data/lib/nukadoko/scaffold.rb +24 -6
- data/lib/nukadoko/schema.rb +15 -2
- data/lib/nukadoko/secrets.rb +55 -5
- data/lib/nukadoko/states.rb +478 -0
- data/lib/nukadoko/step.rb +71 -2
- data/lib/nukadoko/step_fixtures.rb +52 -3
- data/lib/nukadoko/summary.rb +803 -30
- data/lib/nukadoko/table.rb +4 -2
- data/lib/nukadoko/text_fit.rb +20 -7
- data/lib/nukadoko/trace.rb +152 -45
- data/lib/nukadoko/tree_passes.rb +95 -33
- data/lib/nukadoko/underneath.rb +311 -0
- data/lib/nukadoko/verdict.rb +18 -1
- data/lib/nukadoko/version.rb +1 -1
- data/lib/nukadoko/vocabulary.rb +166 -23
- data/lib/nukadoko/walk.rb +2 -2
- data/lib/nukadoko/walk_step.rb +1 -1
- data/lib/nukadoko.rb +23 -0
- data/llms.txt +42 -35
- data/sig/generated/nukadoko/base.rbs +4 -4
- data/sig/generated/nukadoko/changed_files.rbs +42 -0
- data/sig/generated/nukadoko/check.rbs +147 -10
- data/sig/generated/nukadoko/claim_drops.rbs +135 -0
- data/sig/generated/nukadoko/claim_line.rbs +11 -0
- data/sig/generated/nukadoko/claim_rules.rbs +49 -4
- data/sig/generated/nukadoko/claim_sides.rbs +63 -12
- data/sig/generated/nukadoko/cli.rbs +80 -7
- data/sig/generated/nukadoko/codes.rbs +19 -4
- data/sig/generated/nukadoko/command.rbs +68 -1
- data/sig/generated/nukadoko/command_help.rbs +18 -0
- data/sig/generated/nukadoko/compat.rbs +392 -0
- data/sig/generated/nukadoko/criteria.rbs +1 -1
- data/sig/generated/nukadoko/definition.rbs +50 -0
- data/sig/generated/nukadoko/error_frames.rbs +1 -1
- data/sig/generated/nukadoko/events/count.rbs +69 -0
- data/sig/generated/nukadoko/events/counted.rbs +70 -0
- data/sig/generated/nukadoko/events/format.rbs +163 -0
- data/sig/generated/nukadoko/events/lists.rbs +47 -0
- data/sig/generated/nukadoko/events/path.rbs +161 -0
- data/sig/generated/nukadoko/events/read.rbs +109 -0
- data/sig/generated/nukadoko/events/reader.rbs +226 -0
- data/sig/generated/nukadoko/events/selection.rbs +100 -0
- data/sig/generated/nukadoko/events/tally.rbs +227 -0
- data/sig/generated/nukadoko/features.rbs +6 -4
- data/sig/generated/nukadoko/fixtures.rbs +67 -11
- data/sig/generated/nukadoko/http_recording.rbs +1 -1
- data/sig/generated/nukadoko/intent.rbs +132 -0
- data/sig/generated/nukadoko/intent_file.rbs +46 -0
- data/sig/generated/nukadoko/intent_view.rbs +69 -0
- data/sig/generated/nukadoko/judgment_file.rbs +7 -1
- data/sig/generated/nukadoko/judgments.rbs +10 -0
- data/sig/generated/nukadoko/measure_mcp.rbs +104 -0
- data/sig/generated/nukadoko/parts.rbs +2 -2
- data/sig/generated/nukadoko/path_view.rbs +105 -0
- data/sig/generated/nukadoko/place_rows.rbs +43 -0
- data/sig/generated/nukadoko/program.rbs +627 -23
- data/sig/generated/nukadoko/program_log.rbs +67 -0
- data/sig/generated/nukadoko/program_shape.rbs +147 -0
- data/sig/generated/nukadoko/project_fixtures.rbs +16 -3
- data/sig/generated/nukadoko/project_program.rbs +2 -1
- data/sig/generated/nukadoko/repeated_prefix.rbs +172 -0
- data/sig/generated/nukadoko/report_run.rbs +1 -1
- data/sig/generated/nukadoko/run.rbs +286 -41
- data/sig/generated/nukadoko/run_record.rbs +20 -12
- data/sig/generated/nukadoko/scaffold.rbs +3 -0
- data/sig/generated/nukadoko/schema.rbs +5 -0
- data/sig/generated/nukadoko/secrets.rbs +26 -3
- data/sig/generated/nukadoko/states.rbs +214 -0
- data/sig/generated/nukadoko/step.rbs +58 -1
- data/sig/generated/nukadoko/step_fixtures.rbs +39 -0
- data/sig/generated/nukadoko/summary.rbs +256 -2
- data/sig/generated/nukadoko/table.rbs +3 -2
- data/sig/generated/nukadoko/trace.rbs +108 -33
- data/sig/generated/nukadoko/tree_passes.rbs +36 -8
- data/sig/generated/nukadoko/underneath.rbs +141 -0
- data/sig/generated/nukadoko/verdict.rbs +8 -0
- data/sig/generated/nukadoko/vocabulary.rbs +45 -6
- data/skills/nukadoko/SKILL.md +18 -18
- data/skills/nukadoko/references/checking-steps.md +16 -83
- data/skills/nukadoko/references/diagnosing.md +6 -6
- data/skills/nukadoko/references/done.md +22 -0
- data/skills/nukadoko/references/evidence.md +19 -6
- data/skills/nukadoko/references/exploring.md +22 -7
- data/skills/nukadoko/references/fixtures.md +12 -32
- data/skills/nukadoko/references/judgments.md +18 -0
- data/skills/nukadoko/references/maintenance.md +1 -1
- data/skills/nukadoko/references/merge-risk.md +1 -1
- data/skills/nukadoko/references/parts.md +46 -23
- data/skills/nukadoko/references/{perturbed-worlds.md → perturbed-systems.md} +30 -12
- data/skills/nukadoko/references/program.md +168 -169
- data/skills/nukadoko/references/reviewing.md +20 -20
- data/skills/nukadoko/references/ruby/checking-steps.md +106 -0
- data/skills/nukadoko/references/ruby/examples/cli.md +212 -0
- data/skills/nukadoko/references/ruby/fixtures.md +34 -0
- data/skills/nukadoko/references/ruby/program.md +112 -0
- data/skills/nukadoko/references/ruby/step-files.md +115 -0
- data/skills/nukadoko/references/running.md +34 -34
- data/skills/nukadoko/references/scenario-rules.md +7 -6
- data/skills/nukadoko/references/states.md +7 -1
- data/skills/nukadoko/references/step-files.md +41 -120
- data/skills/nukadoko/references/typescript/checking-steps.md +129 -0
- data/skills/nukadoko/references/{examples → typescript/examples}/cli.md +1 -1
- data/skills/nukadoko/references/{examples → typescript/examples}/http-api.md +6 -6
- data/skills/nukadoko/references/{examples → typescript/examples}/workflow.md +1 -1
- data/skills/nukadoko/references/typescript/fixtures.md +56 -0
- data/skills/nukadoko/references/typescript/program.md +111 -0
- data/skills/nukadoko/references/typescript/step-files.md +104 -0
- data/skills/nukadoko/references/verdicts.md +10 -10
- data/skills/nukadoko/references/writing-steps.md +67 -67
- data/skills/nukadoko/references/writing-the-feature.md +1 -1
- data/skills/nukadoko-verification/SKILL.md +13 -8
- metadata +103 -7
- data/skills/nukadoko/references/ruby.md +0 -80
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
# Adding nukadoko to an existing project
|
|
2
|
+
|
|
3
|
+
This guide takes a project that already has code and unit tests to its
|
|
4
|
+
first scenario that runs green, in CI, with a run summary on the pull
|
|
5
|
+
request. It assumes a Node project; a repository without a `package.json`
|
|
6
|
+
starts with the note under [Setup details](../guide.md#setup-details).
|
|
7
|
+
|
|
8
|
+
Each step names the command and what it writes. The outputs below are
|
|
9
|
+
copied from a real run of the packed package in a scratch project whose
|
|
10
|
+
CLI, `src/cli.ts`, prints `Hello, <name>!`. The README walks the same
|
|
11
|
+
project with every file shown in full: see
|
|
12
|
+
[Beside your unit tests](../../README.md#beside-your-unit-tests).
|
|
13
|
+
|
|
14
|
+
## 1. Install nukadoko
|
|
15
|
+
|
|
16
|
+
You need Node 22.18 or later on the 22 line, or 23.6 or later. Install
|
|
17
|
+
nukadoko as a devDependency, pinned to one exact version:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install -D -E nukadoko
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`-E` writes `"nukadoko": "0.17.0"` instead of a caret range. While
|
|
24
|
+
nukadoko is 0.x, any release can change the public API, so move to a new
|
|
25
|
+
version on purpose and read [docs/typescript/upgrading.md](upgrading.md) when you do.
|
|
26
|
+
|
|
27
|
+
Steps that use `page` or `request` need Playwright. A CLI project does
|
|
28
|
+
not. To add it, follow [Install](../../README.md#install).
|
|
29
|
+
|
|
30
|
+
## 2. Run `nuka init`
|
|
31
|
+
|
|
32
|
+
Run it from the directory that holds the project's `package.json`:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
npx nuka init
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```text
|
|
39
|
+
nukadoko.config.ts
|
|
40
|
+
features/steps
|
|
41
|
+
.gitignore
|
|
42
|
+
package.json
|
|
43
|
+
tsconfig.json
|
|
44
|
+
next: read node_modules/nukadoko/llms.txt, written for an agent: the loop, every command, and every finding code
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`init` writes `nukadoko.config.ts` and `features/steps/`, and adds lines
|
|
48
|
+
to three files:
|
|
49
|
+
|
|
50
|
+
- `.gitignore` gains `.nukadoko/` (the state directory) and `.env`,
|
|
51
|
+
`.env.*`, and `!.env.example`.
|
|
52
|
+
- `package.json` gains `"test:scenarios": "nuka run"`, the one command a
|
|
53
|
+
person or CI runs.
|
|
54
|
+
- `tsconfig.json` gains `features/**/*` and the config file when its
|
|
55
|
+
`include` leaves them out, and `"rewriteRelativeImportExtensions": true` when it names
|
|
56
|
+
neither that option nor `allowImportingTsExtensions`.
|
|
57
|
+
|
|
58
|
+
Decide the optional flags now. `nuka init` refuses to run again once
|
|
59
|
+
`nukadoko.config.ts` exists.
|
|
60
|
+
|
|
61
|
+
- `--allure` writes `allurerc.mjs`, which sorts failures into Allure
|
|
62
|
+
categories. Without it, copy
|
|
63
|
+
[examples/allure/allurerc.mjs](https://github.com/meganemura/nukadoko/blob/main/typescript/examples/allure/allurerc.mjs) by hand.
|
|
64
|
+
|
|
65
|
+
A program under test that serves HTTP goes in the same file, as
|
|
66
|
+
`program`, which `nuka init` does not write. See
|
|
67
|
+
[Testing a web app](../web-app.md).
|
|
68
|
+
|
|
69
|
+
A CommonJS project (no `"type": "module"`) gets `nukadoko.config.mts`
|
|
70
|
+
instead, and `nuka scaffold` writes its step files as `.mts`. When the
|
|
71
|
+
package has no `"type"` at all, a `.ts` step file works there too, with a
|
|
72
|
+
`MODULE_TYPELESS_PACKAGE_JSON` warning from Node each time it loads.
|
|
73
|
+
Under `"type": "commonjs"` a `.ts` step file does not import, and `nuka
|
|
74
|
+
check` reports it as `step-file-import-failed`.
|
|
75
|
+
|
|
76
|
+
## 3. Write the first feature
|
|
77
|
+
|
|
78
|
+
Write one scenario for one behavior someone asked for, in their words,
|
|
79
|
+
and save it as `features/greet.feature`:
|
|
80
|
+
|
|
81
|
+
```gherkin
|
|
82
|
+
Feature: greet
|
|
83
|
+
|
|
84
|
+
Scenario: greets by name
|
|
85
|
+
When I run greet with "Ada"
|
|
86
|
+
Then the output says "Hello, Ada!"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## 4. Check it, then scaffold the missing steps
|
|
90
|
+
|
|
91
|
+
`nuka check` reads every feature and step file and runs nothing:
|
|
92
|
+
|
|
93
|
+
```sh
|
|
94
|
+
npx nuka check
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
```text
|
|
98
|
+
error undefined-step features/greet.feature:4 No step definition matches "I run greet with "Ada""
|
|
99
|
+
do: nuka scaffold --feature features/greet.feature
|
|
100
|
+
error undefined-step features/greet.feature:5 No step definition matches "the output says "Hello, Ada!""
|
|
101
|
+
do: nuka scaffold --feature features/greet.feature
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Run the `do:` line. It writes one stub for each line that no step
|
|
105
|
+
matches, and prints the command that redoes each stub with more options:
|
|
106
|
+
|
|
107
|
+
```sh
|
|
108
|
+
npx nuka scaffold --feature features/greet.feature
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```text
|
|
112
|
+
features/steps/i-run-greet-with.ts
|
|
113
|
+
features/steps/the-output-says.ts
|
|
114
|
+
next: redo a stub in place with its line below, adding --command, --request, --from, or --description; --replace overwrites the stub while nobody has edited it:
|
|
115
|
+
nuka scaffold i-run-greet-with --pattern 'I run greet with {value:string}' --replace
|
|
116
|
+
nuka scaffold the-output-says --pattern 'the output says {value:string}' --then --replace
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
A stub throws `not implemented` until you fill it in. For the common
|
|
120
|
+
shapes, redo it with an option instead of editing it:
|
|
121
|
+
|
|
122
|
+
- `--command <entry point>` makes a When step that runs your program in
|
|
123
|
+
an empty directory and returns `exitCode`, `stdout`, and `stderr`.
|
|
124
|
+
- `--request "<METHOD> <path>"` makes a When step that sends one HTTP
|
|
125
|
+
request and returns `status` and `body`.
|
|
126
|
+
- `--then --from <step>.<key>` makes a Then step with one claim: a value
|
|
127
|
+
an earlier step returned, compared with the capture on its line.
|
|
128
|
+
|
|
129
|
+
Rename a capture in the pattern to name what it holds:
|
|
130
|
+
|
|
131
|
+
```sh
|
|
132
|
+
npx nuka scaffold i-run-greet-with --pattern 'I run greet with {name:string}' --command src/cli.ts --description "Run greet in an empty scratch directory" --replace
|
|
133
|
+
npx nuka scaffold the-output-says --pattern 'the output says {text:string}' --then --from i-run-greet-with.stdout --description "greet printed exactly this line" --replace
|
|
134
|
+
npx nuka check
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
```text
|
|
138
|
+
ok: no issues found
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
`--command` runs the entry point with `node`. If your `.ts` files import
|
|
142
|
+
each other with `.js` names, point it at the built program instead, for
|
|
143
|
+
example `--command dist/cli.js`. The README explains why under
|
|
144
|
+
[Beside your unit tests](../../README.md#beside-your-unit-tests). For a
|
|
145
|
+
step that no option covers, write `run` yourself; `nuka steps` and
|
|
146
|
+
`nuka describe <name>` show the vocabulary you already have.
|
|
147
|
+
|
|
148
|
+
## 5. Run it
|
|
149
|
+
|
|
150
|
+
```sh
|
|
151
|
+
npm run test:scenarios
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
npm's first line names your package and its version:
|
|
155
|
+
|
|
156
|
+
```text
|
|
157
|
+
> <name>@<version> test:scenarios
|
|
158
|
+
> nuka run
|
|
159
|
+
|
|
160
|
+
scenario 1/1 features/greet.feature:3 greets by name
|
|
161
|
+
step 1/2 passed 0.1s I run greet with "Ada"
|
|
162
|
+
step 2/2 passed 0.0s the output says "Hello, Ada!"
|
|
163
|
+
steps .nukadoko/runs/run-20261018-232314-j5x1/steps/ 2
|
|
164
|
+
summary .nukadoko/runs/run-20261018-232314-j5x1/summary.md
|
|
165
|
+
run .nukadoko/runs/run-20261018-232314-j5x1/run.json
|
|
166
|
+
1 scenario: 1 passed, 0 failed (0s)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
`nuka run` runs `nuka check` first and stops on an error. When a scenario
|
|
170
|
+
fails, stderr names the step, its error, its step record, and a `do:`
|
|
171
|
+
line such as `nuka run features/greet.feature:3` that reruns that one
|
|
172
|
+
scenario.
|
|
173
|
+
|
|
174
|
+
`nuka run --env <name>` runs against an environment that the
|
|
175
|
+
program in `nukadoko.config.ts` names under `environments`, each with its own
|
|
176
|
+
`url` or `serve`, `envFiles`, and `policy`. An environment with
|
|
177
|
+
`policy: "read-only"` refuses every step declared `mutates: true`
|
|
178
|
+
before it runs. The `--command` scaffold writes `mutates: true`; set
|
|
179
|
+
it to `false` when the program changes nothing outside its scratch
|
|
180
|
+
directory. See [Program](../spec.md#program) and
|
|
181
|
+
[Environments and secrets](../spec.md#environments-and-secrets).
|
|
182
|
+
|
|
183
|
+
## 6. Read the run directory
|
|
184
|
+
|
|
185
|
+
Every `nuka run` writes one directory under `.nukadoko/runs/`:
|
|
186
|
+
|
|
187
|
+
- `run.json` is the run's result: the verdict, the counts, and each
|
|
188
|
+
scenario's record with its rerun command.
|
|
189
|
+
- `summary.md` is the Markdown run summary. On GitHub Actions it also
|
|
190
|
+
goes to the job's summary page.
|
|
191
|
+
- `steps/<id>/record.json` is one step record: its arguments and where
|
|
192
|
+
each came from, its validated result, and what the tool observed (the
|
|
193
|
+
processes a `runCommand` started, the requests the step sent, the files
|
|
194
|
+
it changed, and what it saw but could not measure). Evidence files (a
|
|
195
|
+
trace, screenshots, `http.jsonl`) sit beside it.
|
|
196
|
+
- `scenarios/<id>/` holds a scenario's own evidence, when it wrote any.
|
|
197
|
+
- `sources.json` is the feature text the run parsed, and `exports` lists
|
|
198
|
+
the files `nuka report` wrote from this run under
|
|
199
|
+
`.nukadoko/export/`, which retention removes with the run. A report
|
|
200
|
+
written anywhere else is not listed.
|
|
201
|
+
|
|
202
|
+
By default nukadoko keeps the newest 20 runs (`retention.runs`). `nuka clean`
|
|
203
|
+
deletes them. Do not commit `.nukadoko/`: traces and screenshots are not
|
|
204
|
+
redacted. The full layout is in
|
|
205
|
+
[The state directory](../spec.md#the-state-directory).
|
|
206
|
+
|
|
207
|
+
## 7. Render reports with `nuka report`
|
|
208
|
+
|
|
209
|
+
`nuka report` renders a finished run from its run directory alone. With
|
|
210
|
+
no run directory it uses the newest run.
|
|
211
|
+
|
|
212
|
+
```sh
|
|
213
|
+
npx nuka report --format markdown # the run summary, on stdout
|
|
214
|
+
npx nuka report --format allure # .nukadoko/export/allure-results/
|
|
215
|
+
npx nuka report --format messages --out messages.ndjson # a cucumber-messages stream
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Allure results need Allure 3's CLI to become a report. The commands, and
|
|
219
|
+
why each one takes `--output`, are in
|
|
220
|
+
[Reports fill themselves](../guide.md#reports-fill-themselves).
|
|
221
|
+
|
|
222
|
+
## 8. Add it to CI
|
|
223
|
+
|
|
224
|
+
A CLI or API project adds one step after its unit tests:
|
|
225
|
+
|
|
226
|
+
```yaml
|
|
227
|
+
- run: npm run test:scenarios
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
[docs/ci.md](../ci.md) has the whole workflow, the browser variant, and
|
|
231
|
+
how to upload the run directory and post the run summary on the pull
|
|
232
|
+
request.
|
|
233
|
+
|
|
234
|
+
Commit `features/`, `nukadoko.config.ts`, and the changes to
|
|
235
|
+
`package.json`, `tsconfig.json`, and `.gitignore`.
|
|
236
|
+
|
|
237
|
+
## Where to go next
|
|
238
|
+
|
|
239
|
+
- A coding agent loads the nukadoko skill
|
|
240
|
+
([skills/nukadoko/SKILL.md](../../skills/nukadoko/SKILL.md)).
|
|
241
|
+
`nuka skill path` prints the `skills/` directory of your installed
|
|
242
|
+
version, which holds that copy.
|
|
243
|
+
- A project with a cucumber-js suite brings it in by switching one
|
|
244
|
+
import: [docs/typescript/migration.md](migration.md).
|
|
245
|
+
- What `nuka check` catches before anything runs:
|
|
246
|
+
[Wrong before it runs](../../README.md#wrong-before-it-runs).
|
|
247
|
+
- Every command, config key, and record field: [docs/spec.md](../spec.md).
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
[Japanese](adopting.ja.md)
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# 既存のスイートを取り込む
|
|
2
|
+
|
|
3
|
+
> 原文は doors.md。
|
|
4
|
+
|
|
5
|
+
既存の JavaScript のスイートが TypeScript エンジンに入る 2 つの扉です。
|
|
6
|
+
1 つは cucumber-js の step 定義をそのまま実行する扉、もう 1 つは Playwright Test のスイートが型付き step とコードを共有する扉です。
|
|
7
|
+
スイートを一歩ずつ移す手順は、1 つ目の扉が [migration.ja.md](migration.ja.md)、2 つ目が [migration-playwright-test.ja.md](migration-playwright-test.ja.md) にあります。
|
|
8
|
+
Ruby エンジンには、cucumber-ruby のスイート向けの compat の扉が別にあり([reference.ja.md](../ruby/reference.ja.md))、Playwright Test からの扉はありません。
|
|
9
|
+
|
|
10
|
+
## Compat steps(移行の扉)
|
|
11
|
+
|
|
12
|
+
既存の Cucumber と Playwright のスイートは、import を 1 つ変更して nukadoko を導入できます:
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
// before: import { Given, When, Then } from "@cucumber/cucumber";
|
|
16
|
+
import { Given, When, Then } from "nukadoko/compat";
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- Compat step は既存の pattern 構文と World(`this`)を維持します。
|
|
20
|
+
nukadoko の harness が `page` と `request` を提供し、管理します。
|
|
21
|
+
カスタム World クラスは、`setWorldConstructor` を使って nukadoko の基底クラスを拡張します。
|
|
22
|
+
その World の構築中に throw すると、その scenario だけが失敗します。
|
|
23
|
+
stderr には setup の 1 行が出て、scenario record は failed になり、step record は引用されません。
|
|
24
|
+
同じ run の後続 scenario は実行され、messages の export は完了します。
|
|
25
|
+
API は、よく使われる Given、When、Then、World、Before、After、AfterStep をサポートします。
|
|
26
|
+
新しい需要が生じたときに、このサブセットを拡張します。
|
|
27
|
+
- `Given`、`When`、`Then` は、1 つの登録操作を示す 3 つの名前です。
|
|
28
|
+
キーワードは登録時には意味を持ちません。
|
|
29
|
+
Cucumber と同様に、実行時の意味は scenario 内の位置が決めます。
|
|
30
|
+
pattern は素の cucumber-expressions 文字列または RegExp です。
|
|
31
|
+
named capture の規律は typed step のものであり、ここでは要求しません。
|
|
32
|
+
RegExp のサポートによって、正規表現を使うレガシー glue を受け入れます。
|
|
33
|
+
cucumber-js の両方の呼び出し形、`Given(pattern, fn)` と `Given(pattern, { timeout }, fn)` にそのまま対応し、`timeout` は尊重されます。
|
|
34
|
+
認識できないオプションキーは、登録時に例外を投げます。
|
|
35
|
+
discovery はファイルを import し、各登録をそれを行ったファイルに帰属させます。
|
|
36
|
+
pattern テキストが compat step を識別します。
|
|
37
|
+
`nuka steps` は kind 付きで列挙し、`nuka describe` は契約がないことを示します。
|
|
38
|
+
`nuka do` は名指し実行を拒否します。
|
|
39
|
+
`defineStep` への昇格によって、単体 step の実行が可能になります。
|
|
40
|
+
- compat コードの `defineParameterType` と `config.parameterTypes` は、1 つのレジストリを使います。
|
|
41
|
+
登録を config へ移しても pattern のマッチは変わらないため、チームはこの移動を早く行えます。
|
|
42
|
+
例外は `preferForRegexpMatch` を設定する登録です(後述)。
|
|
43
|
+
config が、それらの引退先です。
|
|
44
|
+
transformer の `this` は、その scenario の World です。
|
|
45
|
+
step と hook が動くのと同じオブジェクトです。
|
|
46
|
+
transformer が返した Promise は、step が走る前に await されます。
|
|
47
|
+
string の pattern でも RegExp の pattern でも同じです。
|
|
48
|
+
compat の登録の `preferForRegexpMatch` は、cucumber-js と同じく、複数の型が一致する RegExp のグループに使う型を選びます。
|
|
49
|
+
`config.parameterTypes` にはこのキーがないため、これを設定する登録は、RegExp の step がそれに頼っている間は compat コードに残ります。
|
|
50
|
+
キーごと config へ移すと config のエラーになり、キーを外して移すと 2 つの型が一致する RegExp のグループは再び失敗します。
|
|
51
|
+
2 つの型が 1 つの正規表現を優先する場合や、ある型が `{int}` のような組み込み型の正規表現を優先する場合は、`parameter-type-invalid` エラーです。
|
|
52
|
+
- 実行は 2 つの形をサポートします。
|
|
53
|
+
自前で Playwright を起動する glue は、trace も page のログもないまま動き続けます。
|
|
54
|
+
World のサブクラスは、その page と request を `this.page = ...` と `this.request = ...` で代入します。
|
|
55
|
+
`this.page` と `this.request` は、`openPage()` や `openRequest()` が保存した値より先に、その代入した値を返します。
|
|
56
|
+
代入した page には trace もスクリーンショットもありません。
|
|
57
|
+
代入した request context を通して step が送ったリクエストは、それでも http.jsonl の `node:http` または `node:https` の行になります(docs/spec.ja.md の「Records」を参照)。
|
|
58
|
+
`await this.openPage()` と `await this.openRequest()` は、harness の計測対象である page と request を返します。
|
|
59
|
+
代入がないとき、対応する `openPage()` または `openRequest()` が解決する前に `this.page` または `this.request` を読むと、例外を投げます。
|
|
60
|
+
混在 scenario の typed step は、同じ context と cookie を共有します。
|
|
61
|
+
table は依存ゼロの薄い `DataTable`(raw / rows / hashes / rowsHash / transpose)として届きます。
|
|
62
|
+
`table.hashes()` を呼ぶ glue が import の差し替えで壊れてはならないからです。
|
|
63
|
+
docstring は素の string のままです。
|
|
64
|
+
Before / After hook は、cucumber-js が受け付ける 3 つの書き方をサポートします。
|
|
65
|
+
その書き方は、`Before(fn)`、`Before({ tags }, fn)`、`Before("@tag", fn)` です。
|
|
66
|
+
`Before` と `After` は、`tags` と `timeout` に加えて `{ name }` を受け付けます。
|
|
67
|
+
その文字列は登録に保存され、空でなければその呼び出しの `hooks` エントリにも載ります。
|
|
68
|
+
Allure の fixture 名、run サマリの行、trace chunk のタイトル、hook 失敗時のメッセージは、その文字列をタイトルに使います。
|
|
69
|
+
どの scenario で走るか、timeout、登録順は変わりません。
|
|
70
|
+
`AfterStep` は `name` を受け付けません。
|
|
71
|
+
cucumber-js の step hook の options にそのフィールドは無いからです。
|
|
72
|
+
hook は cucumber 自身の hook 引数を受け取ります。
|
|
73
|
+
hook は `@tag` または `not @tag` だけで絞り込めます。
|
|
74
|
+
より複雑な式は、静かな誤マッチを防ぐために明示的に失敗します。
|
|
75
|
+
hook は自分の step record を持たず、scenario record の `hooks` 配列に現れます。
|
|
76
|
+
hook 内のネットワーク通信は、どの step の境界にも属しません。
|
|
77
|
+
http.jsonl の行は scenario 全体で共有され続け、個々の hook 呼び出しに紐付けられることはありません。
|
|
78
|
+
ただし Playwright の trace は違います。
|
|
79
|
+
`this.openPage()` に触れた Before/After/AfterStep の個々の呼び出しは、それぞれ自分自身の trace chunk と `actions` のリストを持ち、同じ `hooks` 配列のエントリ上に記録されます。
|
|
80
|
+
`trace`/`actions`/`truncated` は、step 自身の record と同じ形です(docs/spec.ja.md の「Records」を参照)。
|
|
81
|
+
各 chunk は、step の chunk と sibling hook の chunk から独立しています。
|
|
82
|
+
hook の呼び出しには、依然として `sections`/`polls` はありません。
|
|
83
|
+
`section`/`poll` を呼ぶための fixture bag を hook が持たないからです。
|
|
84
|
+
hook 自身が明示的に呼んだものではなく trace chunk 自体から読み出される `actions` だけは、この制約の影響を受けません。
|
|
85
|
+
`AfterStep` は、同じ 3 通りの呼び出し形と `@tag` / `not @tag` のフィルタを共有します。
|
|
86
|
+
Before/After は scenario 全体を挟みますが、`AfterStep` は実行された pickle step ごとに 1 回動きます。
|
|
87
|
+
この scenario がそれより前の step の失敗によってスキップした step は始まってすらいないため、`AfterStep` にとっての「後」はそこには存在せず、その step については何も現れません。
|
|
88
|
+
タグが一致しない hook にも同じ規則を使います。
|
|
89
|
+
`hooks` 配列内の各 `AfterStep` エントリは `step_index` を運びます。
|
|
90
|
+
これは、その record 自身の `steps` 配列の中での実行された step の 0 始まりの index であり、レポートがエントリ同士を区別できるようにするためのものです。
|
|
91
|
+
Allure と cucumber-messages の両方がこれをそのまま運びます。
|
|
92
|
+
hook 引数の `result.status` は、`@cucumber/messages` の `TestStepResultStatus` 文字列値を使います。
|
|
93
|
+
`nukadoko/compat` は、同じ enum を `Status` として re-export します。
|
|
94
|
+
したがって、`result.status === Status.FAILED` と書かれた glue は正しく import され、比較できます。
|
|
95
|
+
`After` と `AfterStep` は `result.duration` も受け取ります。
|
|
96
|
+
これは cucumber の `Duration`(seconds と nanos)で、`result` が表す step 自身の開始から終了までを測ったものです。
|
|
97
|
+
その結果が失敗のとき、`result.message` は executor がすでに記録している失敗の文言で、`error` は失敗が throw だったときの投げられた値です。
|
|
98
|
+
`Before` は `result` も `error` も受け取りません。
|
|
99
|
+
`error` は `After` と `AfterStep` では step が成功したときもキーとして存在し、その値は `undefined` です。
|
|
100
|
+
cucumber-js が `result` を渡すときにはそのキーも代入するからです。
|
|
101
|
+
`AfterStep` は加えて `pickleStep`(直前に走った pickle step)と `testStepId`(その step の step record id)を受け取ります。
|
|
102
|
+
この id は `testCaseStartedId` と同じ種類の身代わりです。
|
|
103
|
+
executor がすでに持っている安定した id であり、cucumber-messages のストリームが後から割り当てる id ではありません。
|
|
104
|
+
`SKIPPED` が一致する場所は 1 つだけです。
|
|
105
|
+
walk が中止した scenario の `After` hook で、その scenario の step は全部は走っていません(docs/spec.ja.md の「人と一緒の walk」を参照)。
|
|
106
|
+
この enum の他のメンバー(`PENDING`/`UNDEFINED`/`AMBIGUOUS`)は決して一致しません。
|
|
107
|
+
nukadoko には、hook 自身の result が運びうる pending、undefined-step、ambiguous-match のいずれの概念もないからです。
|
|
108
|
+
移行した glue は、これらの値を比較する分岐を通らず、この挙動は compat gap ではありません。
|
|
109
|
+
`BeforeAll`/`AfterAll` は、scenario ではなく run 全体を挟みます。
|
|
110
|
+
`{ timeout }` と `{ name }` を受け付け、`tags` と `on` は拒みます。
|
|
111
|
+
`on` は hook を動かすプロセスを選ぶオプションで、nukadoko にはその選択が無いからです。
|
|
112
|
+
World を持たず、scenario が 1 つも選ばれなければ実行されません。
|
|
113
|
+
空でない `name` は、失敗メッセージのタイトルになります。
|
|
114
|
+
これらの hook は scenario record に属さないため、exit code を通じて報告します。
|
|
115
|
+
`setDefaultTimeout` は、自分の timeout を宣言していないものすべてに既定値を与えます。
|
|
116
|
+
負の値は無制限を意味し、cucumber-js と同じです。
|
|
117
|
+
`setDefaultTimeout(-1)` と、step や hook の `{ timeout: -1 }` は制限を切ります。
|
|
118
|
+
0 は制限時間として効きます。
|
|
119
|
+
呼ばないか、負の値で呼べば、step は cucumber の 5 秒という上限を持ち込む代わりに無制限のままになります。
|
|
120
|
+
移行しただけの理由で、遅いスイートを失敗させてしまわないためです。
|
|
121
|
+
- nukadoko は常に World を計測します。
|
|
122
|
+
すべての compat step の step record は、その step が World のどのキーを読み書きしたかをアクセス順で記録します(`this.foo` が隠していたデータフローです)。
|
|
123
|
+
計測面はバッグの own データプロパティです。
|
|
124
|
+
構造上、`#private` の状態は計測に含まれません。
|
|
125
|
+
`defineWorld({ key: zodSchema })` は、キー単位でバリデーションを有効にします。
|
|
126
|
+
schema に失敗した書き込みは step を失敗させ、write として記録されません。
|
|
127
|
+
`class MyWorld extends defineWorld({...})` は `this` に型を付けます。
|
|
128
|
+
cucumber 自身の `attach` / `log` / `link` / `parameters` は予約キーです。
|
|
129
|
+
計測されず、宣言もできず、上書きは黙った破壊の代わりにエラーになります。
|
|
130
|
+
`parameters` は config の `worldParameters` で、デフォルトは `{}` です。
|
|
131
|
+
`page` と `request` はバッグのフィールドではなく、harness の getter です。
|
|
132
|
+
`defineWorld` は step ファイルの import 時に、どちらの名前も拒みます。
|
|
133
|
+
`nuka check` はその拒否を `step-file-import-failed` として報告し、`nuka run` は同じメッセージで止まります。
|
|
134
|
+
メッセージはフィールド名を含みます。
|
|
135
|
+
サブクラスは、これまでどおりそれらを代入できます。
|
|
136
|
+
`await this.openPage()` と `await this.openRequest()` は、これまでどおり harness のオブジェクトを返します。
|
|
137
|
+
- `this.attach` と `this.link` は cucumber-js に従います。
|
|
138
|
+
`attach` は文字列、`Buffer` または `Uint8Array`、readable stream のいずれかを受け取ります。
|
|
139
|
+
media type が `base64:` で始まるとき、その文字列は base64 であり、ファイルには復号したバイトが書かれます。
|
|
140
|
+
第 2 引数はその media type か、`{ mediaType, fileName }` です。
|
|
141
|
+
`fileName` があるときは、それが step record の下に書かれるファイルの名前です。
|
|
142
|
+
media type を省いた文字列または buffer は `text/plain` として書かれます。
|
|
143
|
+
stream は promise を返すので、step はそれを await する必要があります。
|
|
144
|
+
media type のない stream は例外を投げます。
|
|
145
|
+
バイトは stream が終わるまで分からず、型も渡されていないからです。
|
|
146
|
+
`link` は URL を 1 つ、または複数受け取ります。
|
|
147
|
+
各引数は `declared` の link として 1 件ずつ記録され、表示名は付きません。
|
|
148
|
+
- harness はブラウザと request のオブジェクトを所有します。
|
|
149
|
+
したがって、compat step はコードを変更せずに計測済みの step record を得ます。
|
|
150
|
+
この record は status、timing、trace、screenshots、HTTP log を含みます。
|
|
151
|
+
- compat step には、型付きの契約、step record 内でバリデーションされた `result`、単体 step の CLI 実行がありません。
|
|
152
|
+
よく使う step を `defineStep` に昇格させると、これらの性質を 1 step ずつ追加できます。
|
|
153
|
+
- 監査によって、この扉の幅を計測しました。
|
|
154
|
+
公開されている cucumber-js のスイート 8 本を、この扉に対して監査しました。
|
|
155
|
+
glue はテキストとして読み、実行しませんでした。
|
|
156
|
+
当時はどのスイートも import の差し替えだけでは通りませんでしたが、そこで見つかった障害をふさいだことで、8 本のうち 2 本はその後、glue の中に拒まれるものが何もない状態になりました。
|
|
157
|
+
残りが何を必要とするかは [docs/typescript/migration.ja.md](migration.ja.md) に列挙されています。
|
|
158
|
+
監査から 1 つの規則を定めました。
|
|
159
|
+
compat がサポートしない挙動は、import 時または最初の run で失敗する必要があります。
|
|
160
|
+
移行するチームは、大きな声の失敗には対処できますが、静かな失敗は見えません。
|
|
161
|
+
だから、黙って振る舞いを変えてしまう抜けは、機能が欠けていることが食ってきた時間よりも多くの信頼を食います。
|
|
162
|
+
import の失敗と下の所見は、この規則を満たします。
|
|
163
|
+
値の水準の違いはまだいくつか残っています。
|
|
164
|
+
それらは失敗しないので、計測済みのものを 1 つずつ [docs/typescript/migration.ja.md](migration.ja.md) の「既知の限界」に挙げています。
|
|
165
|
+
- 明示的な失敗は、静的な所見と step の実行が必要な失敗に分かれます。
|
|
166
|
+
`nuka check` は、静的な所見だけを報告します。
|
|
167
|
+
**`nuka check` が報告できる失敗**: import が例外を投げる step ファイルは `step-file-import-failed` エラーになります。
|
|
168
|
+
原因には、`nukadoko/compat` が export しない名前の値としての使用、ESM glue 内の CommonJS `require`、深い subpath の import があります。
|
|
169
|
+
単一の `@tag` / `not @tag` を超える hook のタグ式は、`unsupported-hook-tag-expression` エラーになります。
|
|
170
|
+
どちらも、何かが実行される前に、そのファイルのテキストだけから分かります。
|
|
171
|
+
その隣にはさらに 2 つの所見があり、どちらも 1 つのファイルの中身についてではなく discovery 自身が歩く範囲についてのものです。
|
|
172
|
+
`.cjs` または `.cts` のファイルが `featuresDir` の下にあるときの `step-file-unsupported-extension`(nukadoko がそれを import しない理由は前述のdocs/spec.ja.md の「型付き step」を参照)と、歩いた結果として試せるものが何もなかったときの `no-step-files-found` です。
|
|
173
|
+
どちらも、実際に何を見た結果なのかを名指しします。
|
|
174
|
+
所見が嘘のとき、読み手がそれに気づけるようにするためです。
|
|
175
|
+
注記 `pattern-unbound` がスキャンしたディレクトリを名指すのも、同じ理由です。
|
|
176
|
+
`undefined-step` の所見は、引用符の付け忘れも示せます。
|
|
177
|
+
同じ位置に合う登録済み pattern が 1 つあり、その capture がすべて `{...:string}` parameter である場合、所見は step と pattern を名指しし、書き直した Gherkin の行を示します。
|
|
178
|
+
その行を説明できる pattern が 2 つ以上ある場合、どれを選ぶかは書き手が決めるため、このヒントは表示されません。
|
|
179
|
+
**`nuka check` が報告できる失敗には done callback も入ります**。
|
|
180
|
+
コードは `done-callback-arity` です。
|
|
181
|
+
compat の hook が上限を超えるのは、Before、After、AfterStep が引数を 2 つ以上宣言したときと、BeforeAll、AfterAll が引数を 1 つ以上宣言したときです。
|
|
182
|
+
マッチした compat step が上限を超えるのは、関数の引数の数が、その行の capture に table または docstring を足した数を超えるときです。
|
|
183
|
+
その数は関数とマッチした行から決まるので、この所見の結果は 1 通りにしかなりません。
|
|
184
|
+
マッチしていない step については黙ります。
|
|
185
|
+
capture の数は、その step を選んだ行から決まるからです。
|
|
186
|
+
**`nuka run` だけが報告できる失敗**: step や hook が `"pending"` / `"skipped"` を返す場合です。
|
|
187
|
+
その値は、関数が実行中に返すものに依存します。
|
|
188
|
+
import の解析では識別できません。
|
|
189
|
+
**どちらでもない(gap ではない)こと**: 型注釈にしか使われていない、あるいは import はされたが一度も参照されない名前は、nukadoko がそのファイルを import するより前に esbuild によってコンパイル済み出力から取り除かれるため、その import は実行時には実際には一度も起きません。
|
|
190
|
+
glue は書かれたとおりに実行されます。
|
|
191
|
+
`tsc` はその名前を compat が export しているものに対して解決するので、欠けている名前はコンパイルエラーであって実行時のエラーではありません。
|
|
192
|
+
監査がこの分類で見つけた 2 つの名前、`IWorldOptions` と `ITestCaseHookParameter` を export する価値があったのはまさにそのためです。
|
|
193
|
+
`nuka` がそれらの失敗を一度も見なかったとしても、その代償は利用者の実行ではなく利用者の型検査が払っていました。
|
|
194
|
+
- 恒久的な設計規則を、すべての移行作業に適用します。
|
|
195
|
+
動いている compat 資産は、チームが nukadoko を導入したあとや、別の資産を typed step へ移したあとも動く必要があります。
|
|
196
|
+
移行途中の「住まいが 2 つある」状態(support コードに登録された parameter type と config に住む parameter type、World のバッグと typed の result の併存)は、禁止するのではなく受け入れます。
|
|
197
|
+
ただしそれらは必ず 1 つの実体を共有し、分散は隠さず `nuka check` が可視化し、個々の移行の一手は意味を変えないものに限ります(だから早く安全に動かせます)。
|
|
198
|
+
扉は両方向に開きます: import を元に戻せることは維持されます。
|
|
199
|
+
- [docs/typescript/migration.ja.md](migration.ja.md) は、既存の cucumber-js と Playwright のスイートに対する手順を示します。
|
|
200
|
+
[docs/typescript/upgrading.ja.md](upgrading.ja.md) は、既存の nukadoko プロジェクトを新しいリリースへ移す方法を説明します。
|
|
201
|
+
|
|
202
|
+
## 第二の扉: Playwright Test のスイート
|
|
203
|
+
|
|
204
|
+
最初の扉は、cucumber-js の上に組み立てられたスイートで import を変更する方法です。
|
|
205
|
+
Playwright Test に対して直接書かれたスイートには、その import がありません。
|
|
206
|
+
テストは `test("...", async ({ page }) => {...})` を使い、リダイレクトする glue レイヤーもありません。
|
|
207
|
+
このスイートには、別の移行方法が必要です。
|
|
208
|
+
|
|
209
|
+
[docs/typescript/migration-playwright-test.ja.md](migration-playwright-test.ja.md) は、この扉の手順を示します。
|
|
210
|
+
`docs/typescript/migration.ja.md` は、最初の扉を扱います。
|
|
211
|
+
Playwright Test のスイートには compat step、World、Cucumber hook がないため、2 つの文書は異なる読み手に向けたものです。
|
|
212
|
+
|
|
213
|
+
**実装を共有します。**
|
|
214
|
+
操作を spec ファイルから通常の非同期関数へ移します。
|
|
215
|
+
この関数は、Playwright のオブジェクトだけを受け取ります。
|
|
216
|
+
spec と型付き step の `run` は、どちらもこの関数を呼びます。
|
|
217
|
+
各 runner は、自分のファイルだけを読み込みます。
|
|
218
|
+
|
|
219
|
+
```
|
|
220
|
+
e2e/cart.spec.ts ──▶ features/steps/lib/cart.ts ◀── features/steps/add-item.ts
|
|
221
|
+
(Playwright) (plain functions) (nukadoko)
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
矢印は意図的に一方向を向いています。
|
|
225
|
+
Playwright のスイートは nukadoko を import しません。
|
|
226
|
+
移動後も、Playwright とリポジトリ内の関数だけに依存します。
|
|
227
|
+
compat の移行を戻すには、import を元に戻します。
|
|
228
|
+
この移行を戻すには、feature ファイルと step を削除します。
|
|
229
|
+
依存先に nukadoko が含まれないため、Playwright のスイートは変わりません。
|
|
230
|
+
|
|
231
|
+
共有 API の形によって、この構成が成り立ちます。
|
|
232
|
+
`page`、`context`、`request`、`baseURL` は、どちら側でも Playwright のオブジェクトです(docs/spec.ja.md の「Context API」を参照)。
|
|
233
|
+
どちらの呼び出し元も、これらのオブジェクトを受け取る関数を使えます。
|
|
234
|
+
adapter、wrapper、re-export は必要ありません。
|
|
235
|
+
|
|
236
|
+
この API 境界より上にあるものは共有しません。
|
|
237
|
+
spec は `step.run(bag, args)` を直接呼び出してはいけません。
|
|
238
|
+
この呼び出しは、step が Playwright の fixture 名だけを使う間しか動きません。
|
|
239
|
+
step が `call`、`section`、`resultOf`、`requireEnv` を使うと失敗します。
|
|
240
|
+
これらの fixture は、型付き step の価値の多くを提供します。
|
|
241
|
+
「Fixtures」で説明した型付けの制約があるため、spec は fixture map も共有できません。
|
|
242
|
+
|
|
243
|
+
契約は、共有ユニットに置きます。
|
|
244
|
+
step の `args` と `returns` は通常の zod schema です。
|
|
245
|
+
関数のファイルが schema を export し、step が schema を宣言できます:
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
// features/steps/lib/cart.ts
|
|
249
|
+
export const openCartReturns = z.object({ id: z.string() });
|
|
250
|
+
export async function openCart(request: APIRequestContext) { ... }
|
|
251
|
+
|
|
252
|
+
// features/steps/open-cart.ts
|
|
253
|
+
export default defineStep({ returns: openCartReturns, run: ({ request }) => openCart(request) });
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
spec と step は 1 つの定義を import するため、両者の形は一致し続けます。
|
|
257
|
+
共有ファイルは Playwright と zod だけに依存するため、依存の向きは変わりません。
|
|
258
|
+
|
|
259
|
+
この移行によって、nukadoko の 2 つの経路が開きます。
|
|
260
|
+
`nuka run` は feature ファイルに経路を固定し、`nuka do` は各 step を単体で実行します。
|
|
261
|
+
既存のスイートがすでに信頼する操作は、agent が探索に使う語彙になります(docs/spec.ja.md の「単体 step」を参照)。
|
|
262
|
+
|
|
263
|
+
2 つのツリーは、1 つのリポジトリに置けます。
|
|
264
|
+
チームは、両者を並べて配置できます。
|
|
265
|
+
または、spec がすでにあるディレクトリの *内側* に `featuresDir` を配置できます。
|
|
266
|
+
Playwright のスイートが主要な資産である場合、2 つ目の配置は移動を少なくします。
|
|
267
|
+
|
|
268
|
+
```
|
|
269
|
+
e2e/
|
|
270
|
+
cart.spec.ts <- Playwright finds this
|
|
271
|
+
lib/cart.ts <- shared, owned by neither runner
|
|
272
|
+
nukadoko/ <- featuresDir
|
|
273
|
+
cart.feature
|
|
274
|
+
steps/add-item.ts <- Playwright does not find this
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
各 runner は、認識するファイルだけを読み込みます。
|
|
278
|
+
Playwright は、自分の `testMatch` に一致するファイルを集めます。
|
|
279
|
+
step にちなんだ名前の step ファイルは一致しません。
|
|
280
|
+
discovery は、`featuresDir` の下にある各 `.ts`、`.mts`、`.js`、`.mjs` ファイルを import します。
|
|
281
|
+
そのディレクトリの外にある spec は、discovery の範囲外です。
|
|
282
|
+
これらの命名規則と配置規則は衝突しません。
|
|
283
|
+
|
|
284
|
+
nukadoko は、2 つの誤った配置を明示的に報告します。
|
|
285
|
+
|
|
286
|
+
discovery は、`featuresDir` の **内側** にある spec を import します。
|
|
287
|
+
Playwright の `test()` は Playwright runner の外では動かないため、import が失敗します。
|
|
288
|
+
`nuka check` はファイルを名指しし、Playwright のメッセージを含めます。
|
|
289
|
+
`run` と `do` は、他の壊れた glue と同様に実行を拒否します。
|
|
290
|
+
|
|
291
|
+
**spec のように名付けられた** step ファイルは、別の衝突を起こします。
|
|
292
|
+
ファイルの basename が step 名を定義します。
|
|
293
|
+
したがって、`open-cart.spec.ts` は最初の step の pattern を持つ `open-cart.spec` という 2 つ目の step を定義します。
|
|
294
|
+
`nuka check` は `ambiguous-step` を報告し、両方の step を名指しします。
|
|
295
|
+
1 つの pattern が複数の step にマッチすることがエラーです。
|
|
296
|
+
ファイル名を変更すると直ります。
|
|
297
|
+
|
|
298
|
+
どちらの配置でも、共有ファイルは `featuresDir` の外に置きます。
|
|
299
|
+
モジュールは step を定義しないため、discovery が import しても問題はありません。
|
|
300
|
+
しかし、その場所は既存のスイートが共有ファイルを所有することを示します。
|
|
301
|
+
|