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,176 @@
|
|
|
1
|
+
# TypeScript エンジン
|
|
2
|
+
|
|
3
|
+
> 原文は reference.md。
|
|
4
|
+
|
|
5
|
+
npm パッケージで step、fixture、config をどう書くかをまとめます。
|
|
6
|
+
feature ファイル、claim、run、record の意味はどちらのエンジンでも同じで、[spec](../spec.ja.md) に一度だけ書いてあります。
|
|
7
|
+
[Ruby エンジンのページ](../ruby/reference.ja.md) は同じ見出しを同じ順に並べているので、2 つを並べて読めます。
|
|
8
|
+
|
|
9
|
+
## インストールとコマンド
|
|
10
|
+
|
|
11
|
+
Node は 22 系なら 22.18 以降、それ以外なら 23.6 以降が要ります。
|
|
12
|
+
`.ts` ファイルをフラグなしで実行できる版です。
|
|
13
|
+
nukadoko は devDependency で、プロジェクトは `npx nuka` で実行します。
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install -D nukadoko
|
|
17
|
+
npx nuka init
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`init` は `package.json` に `test:scenarios` script も追加します。
|
|
21
|
+
人も CI も、この 1 つのコマンドを実行します。
|
|
22
|
+
`tsconfig.json` の `include` には steps と config を追加し、`.ts` ファイルを名指しする import を `tsc` が受け付けるためのコンパイラオプションも追加します。
|
|
23
|
+
CommonJS の場合と `--allure` フラグは [Setup details](../guide.ja.md#setup-details) にあります。
|
|
24
|
+
|
|
25
|
+
Playwright は省略できる peer dependency で、`page` か `request` を使う step だけが必要とします。
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
npm install -D -E playwright@1.63.0
|
|
29
|
+
npx playwright install chromium
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 設定
|
|
33
|
+
|
|
34
|
+
`nuka init` は `nukadoko.config.ts` を書きます。
|
|
35
|
+
default export は `defineConfig({ ... })` で、オプションを検査し、型を付けます。
|
|
36
|
+
各オプションは、それが決めるものと一緒に説明しています。
|
|
37
|
+
`program` と `fixtures` はこのページの下に、`featuresDir` と `parameterTypes` は [spec](../spec.ja.md) の「型付き step」にあります。
|
|
38
|
+
|
|
39
|
+
## step を定義する
|
|
40
|
+
|
|
41
|
+
`features/steps/` の下に、1 ファイルに 1 つの step を kebab-case の名前で置きます。
|
|
42
|
+
ファイル名が step の名前です。
|
|
43
|
+
default export は `defineStep({ ... })` です。
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { defineStep, z } from "nukadoko";
|
|
47
|
+
import assert from "node:assert/strict";
|
|
48
|
+
|
|
49
|
+
export default defineStep({
|
|
50
|
+
description: "Create an item through the API so a later step can read it",
|
|
51
|
+
pattern: "an item named {name:string} exists",
|
|
52
|
+
args: z.object({ name: z.string().describe("The item's name") }),
|
|
53
|
+
returns: z.object({
|
|
54
|
+
id: z.number().describe("The id the API assigned"),
|
|
55
|
+
body: z.object({ id: z.number(), name: z.string() }).describe("The item as the API answered it"),
|
|
56
|
+
}),
|
|
57
|
+
async run({ baseURL }, { name }) {
|
|
58
|
+
const res = await fetch(`${baseURL}/items`, { method: "POST", body: JSON.stringify({ name }) });
|
|
59
|
+
assert.equal(res.status, 201, `creating "${name}": status`);
|
|
60
|
+
const item = (await res.json()) as { id: number; name: string };
|
|
61
|
+
return { id: item.id, body: item };
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`mutates: false` は、何も変えない step であることを宣言します。
|
|
67
|
+
step ファイルは、別の step を `.ts` まで含めたファイル名で import します。
|
|
68
|
+
Node が型を取り除いて実行するので、`enum`、`namespace`、コンストラクタの parameter property は読み込めません([spec](../spec.ja.md#型付き-step) の「型付き step」)。
|
|
69
|
+
|
|
70
|
+
`nuka scaffold --command` が書く step は、エントリポイントを `node` そのもので実行します。
|
|
71
|
+
そのため、`.ts` ファイルどうしが `.js` の specifier で import し合うプロジェクトでは、エントリポイントはビルドした後のプログラム(たとえば `--command dist/cli.js`)で、`"pretest:scenarios": "npm run build"` があれば、clone した直後のチェックアウトでも green になります。
|
|
72
|
+
`.ts` のエントリポイントが import する `.js` ファイルがなく、その横に `.ts` ファイルがあるときは、scaffold が拒否します。
|
|
73
|
+
|
|
74
|
+
## フィールドとスキーマ
|
|
75
|
+
|
|
76
|
+
`args` と `returns` は zod の object です。
|
|
77
|
+
`z` は `nukadoko` から re-export しているので、プロジェクトが zod を入れる必要はありません。
|
|
78
|
+
`nuka describe` は各スキーマを `z.toJSONSchema` で JSON Schema にして出します。
|
|
79
|
+
|
|
80
|
+
## キャプチャ、テーブル、doc string
|
|
81
|
+
|
|
82
|
+
pattern の `{key:type}` は、args のキー `key` を埋めます。
|
|
83
|
+
データテーブルは `string[][]` として、doc string は `string` として、そのキーに届きます。
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
args: z.object({
|
|
87
|
+
todos: z
|
|
88
|
+
.array(z.array(z.string()))
|
|
89
|
+
.describe("The data table's rows, one todo per row, the title in the first cell"),
|
|
90
|
+
}),
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Claims
|
|
94
|
+
|
|
95
|
+
Then の step は、`run` の代わりに `claims` と、system を読む `observe` を宣言します。
|
|
96
|
+
各 claim は nukadoko が判定します([spec](../spec.ja.md#claims) の「Claims」)。
|
|
97
|
+
|
|
98
|
+
## 連鎖(`from`)
|
|
99
|
+
|
|
100
|
+
`from: { id: [startJob, "id"] }` は、`startJob` という step がこの scenario で先に返した値で `id` を埋めます。
|
|
101
|
+
step を import して書くので、名前を変えると型エラーになります。
|
|
102
|
+
`startJob.returns.shape.id` で、返す側のスキーマをそのキーに使い回せます。
|
|
103
|
+
|
|
104
|
+
## Parts
|
|
105
|
+
|
|
106
|
+
`parts: [createTodo, completeById]` は `run` が呼んでよい step を並べ、`await call(createTodo, { title })` はその 1 つを args と returns を検査しながら実行します([spec](../spec.ja.md#parts) の「Parts」)。
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
parts: [createTodo, completeById],
|
|
110
|
+
async run({ call }, args) {
|
|
111
|
+
const created = await call(createTodo, { title: args.title });
|
|
112
|
+
const completed = await call(completeById, { id: created.id });
|
|
113
|
+
return { id: completed.id, done: completed.done };
|
|
114
|
+
},
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Fixtures
|
|
118
|
+
|
|
119
|
+
config の `defineFixtures` で、プロジェクトの fixture を足します。
|
|
120
|
+
fixture は、名前を挙げた fixture と `use` 関数を受け取り、`await use(value)` のあとが後片付けです。
|
|
121
|
+
組み込みと同じ名前の fixture は、すべての step でその組み込みに置き換わります。
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import { defineConfig, defineFixtures } from "nukadoko";
|
|
125
|
+
|
|
126
|
+
export default defineConfig({
|
|
127
|
+
fixtures: defineFixtures({
|
|
128
|
+
page: async ({ page }, use) => {
|
|
129
|
+
await page.addInitScript(() => {
|
|
130
|
+
(window as unknown as { wrapped: string }).wrapped = "by the project";
|
|
131
|
+
});
|
|
132
|
+
await use(page);
|
|
133
|
+
},
|
|
134
|
+
}),
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Context
|
|
139
|
+
|
|
140
|
+
`run` と `observe` の第 1 引数は分割代入で受け、そこに書いた名前が step の必要とする fixture です。
|
|
141
|
+
名前は `page`、`context`、`pageAs`、`request`、`env`、`requireEnv`、`baseURL`、`services`、`setupResult`、`scratch`、`section`、`poll`、`evidence`、`resultOf`、`call` です。
|
|
142
|
+
`nuka check` は本体を呼ばずにこの分割代入を読みます([spec](../spec.ja.md#context-api) の「Context API」)。
|
|
143
|
+
`scratch.dir()` は新しいディレクトリを返し、scenario が終わると消えます。
|
|
144
|
+
|
|
145
|
+
## ポーリングと待ち
|
|
146
|
+
|
|
147
|
+
Then の step の `poll: { timeout_ms: 3000, settled: [...] }` は、続けて 2 回読んだ値ですべての claim が成り立つか、時間が切れるまで、`observe` を読み直します。
|
|
148
|
+
|
|
149
|
+
## プログラム
|
|
150
|
+
|
|
151
|
+
テスト対象のプログラムは config の `program` で、プログラムの起動のしかたを返す関数です。
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
export default defineConfig({
|
|
155
|
+
program: () => ({ serve: { command: "node src/server.ts", ready: "/items" }, env: { PORT: "{port}" } }),
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
フィールドは [spec](../spec.ja.md#テスト対象のプログラム) の「テスト対象のプログラム」にあります。
|
|
160
|
+
|
|
161
|
+
## Compat steps(移行の扉)
|
|
162
|
+
|
|
163
|
+
cucumber-js のスイートは、import を 1 つ `nukadoko/compat` に変えるだけで、step 定義をそのままにして取り込めます。
|
|
164
|
+
compat step の名前はパターンで(`compat: <pattern>`)、契約はなく、それぞれ自分の step record を持って動きます。
|
|
165
|
+
その hook はシナリオの World の上で動き、シナリオの record の `hooks` に 1 項目ずつ入ります。
|
|
166
|
+
扉が受け付けるものは [doors.ja.md](doors.ja.md) に、スイートを移す手順は [migration.ja.md](migration.ja.md) にあります。
|
|
167
|
+
|
|
168
|
+
## 型とツール
|
|
169
|
+
|
|
170
|
+
`tsc` が config と step を検査します。
|
|
171
|
+
`tsconfig.json` が `rewriteRelativeImportExtensions` も `allowImportingTsExtensions` も書いていなければ、`nuka init` が前者を足すので、`.ts` を含む import の名前が通ります。
|
|
172
|
+
`"erasableSyntaxOnly": true` にすると、Node が取り除けない書き方を `tsc` が拒みます。
|
|
173
|
+
|
|
174
|
+
## このエンジンにないもの
|
|
175
|
+
|
|
176
|
+
`nuka sig` は Steep のための RBS を書くコマンドで、Ruby エンジンにだけあります。
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# The TypeScript engine
|
|
2
|
+
|
|
3
|
+
How a step, a fixture, and a config are written for the npm package.
|
|
4
|
+
What a feature file, a claim, a run, and a record mean is the same in both
|
|
5
|
+
engines, and [the spec](../spec.md) says it once. The
|
|
6
|
+
[Ruby engine's page](../ruby/reference.md) has the same headings in the
|
|
7
|
+
same order, so the two can be read side by side.
|
|
8
|
+
|
|
9
|
+
## Install and command
|
|
10
|
+
|
|
11
|
+
Node 22.18 or later on the 22 line, or 23.6 or later: the releases that
|
|
12
|
+
run a `.ts` file without a flag. nukadoko is a devDependency, and the
|
|
13
|
+
project runs it with `npx nuka`:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install -D nukadoko
|
|
17
|
+
npx nuka init
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`init` also adds a `test:scenarios` script to `package.json` (the one
|
|
21
|
+
command a person or CI runs), and the steps and the config to the
|
|
22
|
+
`include` of `tsconfig.json`, with the compiler option that lets `tsc`
|
|
23
|
+
accept an import that names a `.ts` file. The CommonJS case and the
|
|
24
|
+
`--allure` flag are in [Setup details](../guide.md#setup-details).
|
|
25
|
+
|
|
26
|
+
Playwright is an optional peer dependency, needed only by a step that
|
|
27
|
+
uses `page` or `request`:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npm install -D -E playwright@1.63.0
|
|
31
|
+
npx playwright install chromium
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Configuration
|
|
35
|
+
|
|
36
|
+
`nuka init` writes `nukadoko.config.ts`. Its default export is
|
|
37
|
+
`defineConfig({ ... })`, which checks the options and gives them types.
|
|
38
|
+
Each option is described with what it sets: `program` and `fixtures`
|
|
39
|
+
below, and `featuresDir` and `parameterTypes` under "Typed steps" in
|
|
40
|
+
[the spec](../spec.md#typed-steps).
|
|
41
|
+
|
|
42
|
+
## Defining a step
|
|
43
|
+
|
|
44
|
+
One step per file under `features/steps/`, named in kebab-case; the file
|
|
45
|
+
name is the step name. The default export is `defineStep({ ... })`:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { defineStep, z } from "nukadoko";
|
|
49
|
+
import assert from "node:assert/strict";
|
|
50
|
+
|
|
51
|
+
export default defineStep({
|
|
52
|
+
description: "Create an item through the API so a later step can read it",
|
|
53
|
+
pattern: "an item named {name:string} exists",
|
|
54
|
+
args: z.object({ name: z.string().describe("The item's name") }),
|
|
55
|
+
returns: z.object({
|
|
56
|
+
id: z.number().describe("The id the API assigned"),
|
|
57
|
+
body: z.object({ id: z.number(), name: z.string() }).describe("The item as the API answered it"),
|
|
58
|
+
}),
|
|
59
|
+
async run({ baseURL }, { name }) {
|
|
60
|
+
const res = await fetch(`${baseURL}/items`, { method: "POST", body: JSON.stringify({ name }) });
|
|
61
|
+
assert.equal(res.status, 201, `creating "${name}": status`);
|
|
62
|
+
const item = (await res.json()) as { id: number; name: string };
|
|
63
|
+
return { id: item.id, body: item };
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`mutates: false` declares a step that changes nothing. A step file
|
|
69
|
+
imports another by its own file name, `.ts` included. Node strips the
|
|
70
|
+
types, so an `enum`, a `namespace`, and a constructor parameter property
|
|
71
|
+
do not load ("Typed steps" in [the spec](../spec.md#typed-steps)).
|
|
72
|
+
|
|
73
|
+
A step that `nuka scaffold --command` writes runs the entry point with
|
|
74
|
+
`node` itself. In a project whose `.ts` files import each other with `.js`
|
|
75
|
+
specifiers, the entry point is the built program (for example `--command
|
|
76
|
+
dist/cli.js`), and `"pretest:scenarios": "npm run build"` keeps a fresh
|
|
77
|
+
checkout green; the scaffold refuses a `.ts` entry point that imports a
|
|
78
|
+
`.js` file which is absent while its `.ts` sibling is present.
|
|
79
|
+
|
|
80
|
+
## Fields and schemas
|
|
81
|
+
|
|
82
|
+
`args` and `returns` are zod objects. `z` is re-exported from `nukadoko`,
|
|
83
|
+
so the project needs no zod of its own. `nuka describe` publishes each
|
|
84
|
+
schema as JSON Schema, through `z.toJSONSchema`.
|
|
85
|
+
|
|
86
|
+
## Captures, tables, and doc strings
|
|
87
|
+
|
|
88
|
+
Each `{key:type}` in the pattern fills the args key `key`. A data table
|
|
89
|
+
reaches its key as `string[][]`, and a doc string as a `string`:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
args: z.object({
|
|
93
|
+
todos: z
|
|
94
|
+
.array(z.array(z.string()))
|
|
95
|
+
.describe("The data table's rows, one todo per row, the title in the first cell"),
|
|
96
|
+
}),
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Claims
|
|
100
|
+
|
|
101
|
+
A Then step declares `claims` and an `observe` that reads the system, in
|
|
102
|
+
place of `run`. nukadoko judges each claim ("Claims" in
|
|
103
|
+
[the spec](../spec.md#claims)).
|
|
104
|
+
|
|
105
|
+
## Chaining (`from`)
|
|
106
|
+
|
|
107
|
+
`from: { id: [startJob, "id"] }` fills `id` with what the step `startJob`
|
|
108
|
+
returned earlier in the scenario. The step is imported, so a rename is a
|
|
109
|
+
type error. `startJob.returns.shape.id` reuses the producer's schema for
|
|
110
|
+
the key.
|
|
111
|
+
|
|
112
|
+
## Parts
|
|
113
|
+
|
|
114
|
+
`parts: [createTodo, completeById]` lists the steps `run` may call, and
|
|
115
|
+
`await call(createTodo, { title })` runs one with its args and returns
|
|
116
|
+
checked ("Parts" in [the spec](../spec.md#parts)):
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
parts: [createTodo, completeById],
|
|
120
|
+
async run({ call }, args) {
|
|
121
|
+
const created = await call(createTodo, { title: args.title });
|
|
122
|
+
const completed = await call(completeById, { id: created.id });
|
|
123
|
+
return { id: completed.id, done: completed.done };
|
|
124
|
+
},
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Fixtures
|
|
128
|
+
|
|
129
|
+
`defineFixtures` in the config adds a project fixture. The fixture
|
|
130
|
+
receives the fixtures it names and a `use` function; what follows
|
|
131
|
+
`await use(value)` is its teardown. A fixture named like a builtin
|
|
132
|
+
replaces it for every step:
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
import { defineConfig, defineFixtures } from "nukadoko";
|
|
136
|
+
|
|
137
|
+
export default defineConfig({
|
|
138
|
+
fixtures: defineFixtures({
|
|
139
|
+
page: async ({ page }, use) => {
|
|
140
|
+
await page.addInitScript(() => {
|
|
141
|
+
(window as unknown as { wrapped: string }).wrapped = "by the project";
|
|
142
|
+
});
|
|
143
|
+
await use(page);
|
|
144
|
+
},
|
|
145
|
+
}),
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Context
|
|
150
|
+
|
|
151
|
+
The first argument of `run` and `observe` is destructured, and the names
|
|
152
|
+
it takes are the fixtures the step needs: `page`, `context`, `pageAs`,
|
|
153
|
+
`request`, `env`, `requireEnv`, `baseURL`, `services`, `setupResult`,
|
|
154
|
+
`scratch`, `section`,
|
|
155
|
+
`poll`, `evidence`, `resultOf`, and `call`. `nuka check` reads the pattern without
|
|
156
|
+
calling the body ("Context API" in [the spec](../spec.md#context-api)).
|
|
157
|
+
`scratch.dir()` returns a fresh directory, removed when the scenario ends.
|
|
158
|
+
|
|
159
|
+
## Polling and waiting
|
|
160
|
+
|
|
161
|
+
`poll: { timeout_ms: 3000, settled: [...] }` on a Then step reads
|
|
162
|
+
`observe` again until every claim holds on two readings in a row, or the
|
|
163
|
+
time runs out.
|
|
164
|
+
|
|
165
|
+
## Program
|
|
166
|
+
|
|
167
|
+
The program under test is `program` in the config, a function that
|
|
168
|
+
returns how the program starts:
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
export default defineConfig({
|
|
172
|
+
program: () => ({ serve: { command: "node src/server.ts", ready: "/items" }, env: { PORT: "{port}" } }),
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Its fields are under "Program" in [the spec](../spec.md#program).
|
|
177
|
+
|
|
178
|
+
## Compat steps (the migration door)
|
|
179
|
+
|
|
180
|
+
A cucumber-js suite comes in with its step definitions as they are, after
|
|
181
|
+
one import changes to `nukadoko/compat`. A compat step is named by its
|
|
182
|
+
pattern, `compat: <pattern>`, has no contract, and runs with a step record
|
|
183
|
+
of its own; its hooks run on the scenario's World and are entries in the
|
|
184
|
+
scenario record's `hooks`. [doors.md](doors.md) says what the door takes,
|
|
185
|
+
and [migration.md](migration.md) how a suite moves across.
|
|
186
|
+
|
|
187
|
+
## Types and tooling
|
|
188
|
+
|
|
189
|
+
`tsc` checks the config and the steps. `nuka init` adds
|
|
190
|
+
`rewriteRelativeImportExtensions` to `tsconfig.json` when it names neither
|
|
191
|
+
that option nor `allowImportingTsExtensions`, so the `.ts` import names
|
|
192
|
+
pass. `"erasableSyntaxOnly": true` makes `tsc` refuse what Node cannot
|
|
193
|
+
strip.
|
|
194
|
+
|
|
195
|
+
## Not in this engine
|
|
196
|
+
|
|
197
|
+
`nuka sig` writes RBS for Steep and exists only in the Ruby engine.
|