@fluxenginejp/sftest 1.3.0 → 1.4.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.
Files changed (89) hide show
  1. package/LICENSE +21 -21
  2. package/dist/cli/sftest.js +2 -2
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.js +3 -1
  5. package/dist/pages/common/BrowserDialogs.d.ts +0 -8
  6. package/dist/pages/common/BrowserDialogs.js +10 -1
  7. package/dist/pages/common/DataImportWizard.d.ts +3 -19
  8. package/dist/pages/common/DataImportWizard.js +11 -8
  9. package/dist/pages/common/ElementStates.d.ts +0 -8
  10. package/dist/pages/common/ElementStates.js +4 -3
  11. package/dist/pages/common/FileRelatedListPage.d.ts +0 -6
  12. package/dist/pages/common/FileRelatedListPage.js +6 -4
  13. package/dist/pages/common/ListViewPage.d.ts +6 -9
  14. package/dist/pages/common/ListViewPage.js +22 -7
  15. package/dist/pages/common/LoginAsPage.d.ts +14 -13
  16. package/dist/pages/common/LoginAsPage.js +63 -8
  17. package/dist/pages/common/PageButtons.d.ts +0 -13
  18. package/dist/pages/common/PageButtons.js +14 -9
  19. package/dist/pages/common/PageLinks.d.ts +24 -0
  20. package/dist/pages/common/PageLinks.js +87 -0
  21. package/dist/pages/common/RecordData.js +2 -1
  22. package/dist/pages/common/RecordDetailPage.d.ts +48 -18
  23. package/dist/pages/common/RecordDetailPage.js +121 -28
  24. package/dist/pages/common/RecordFields.d.ts +81 -20
  25. package/dist/pages/common/RecordFields.js +268 -28
  26. package/dist/pages/common/RecordFormDialog.d.ts +0 -7
  27. package/dist/pages/common/RecordFormDialog.js +23 -10
  28. package/dist/pages/common/RecordPage.d.ts +5 -3
  29. package/dist/pages/common/RecordPage.js +18 -8
  30. package/dist/pages/common/ScreenDialog.d.ts +23 -8
  31. package/dist/pages/common/ScreenDialog.js +80 -3
  32. package/dist/pages/common/fieldSections.d.ts +53 -0
  33. package/dist/pages/common/fieldSections.js +89 -0
  34. package/dist/pages/common/listViewPicker.d.ts +0 -5
  35. package/dist/pages/common/listViewPicker.js +3 -2
  36. package/dist/pages/common/relatedLists.d.ts +0 -5
  37. package/dist/pages/common/relatedLists.js +2 -1
  38. package/dist/pages/common/saveErrors.d.ts +0 -10
  39. package/dist/pages/common/saveErrors.js +2 -3
  40. package/dist/steps/common/apex.steps.js +6 -2
  41. package/dist/steps/common/button.steps.js +14 -8
  42. package/dist/steps/common/common.steps.js +33 -20
  43. package/dist/steps/common/dialog.steps.js +29 -9
  44. package/dist/steps/common/file.steps.js +18 -12
  45. package/dist/steps/common/import.steps.js +22 -5
  46. package/dist/steps/common/record.steps.js +18 -6
  47. package/dist/steps/common/state.steps.js +2 -0
  48. package/dist/steps/common/window.steps.d.ts +1 -0
  49. package/dist/steps/common/window.steps.js +35 -0
  50. package/dist/support/FileDownloads.d.ts +0 -6
  51. package/dist/support/FileDownloads.js +8 -1
  52. package/dist/support/UploadErrors.d.ts +0 -6
  53. package/dist/support/UploadErrors.js +15 -7
  54. package/dist/support/activePages.d.ts +89 -0
  55. package/dist/support/activePages.js +182 -0
  56. package/dist/support/apexBatch.js +6 -6
  57. package/dist/support/consoleReporter.d.ts +142 -0
  58. package/dist/support/consoleReporter.js +381 -0
  59. package/dist/support/executionControl.d.ts +102 -0
  60. package/dist/support/executionControl.js +275 -0
  61. package/dist/support/fileInputs.js +7 -4
  62. package/dist/support/fixtures.d.ts +62 -66
  63. package/dist/support/fixtures.js +87 -47
  64. package/dist/support/globalSetup.js +30 -20
  65. package/dist/support/loginState.d.ts +31 -0
  66. package/dist/support/loginState.js +26 -0
  67. package/dist/support/mismatch.d.ts +7 -0
  68. package/dist/support/mismatch.js +22 -9
  69. package/dist/support/operationTargets.d.ts +22 -0
  70. package/dist/support/operationTargets.js +26 -0
  71. package/dist/support/playwrightConfig.d.ts +5 -13
  72. package/dist/support/playwrightConfig.js +11 -2
  73. package/dist/support/settings.d.ts +4 -0
  74. package/dist/support/settings.js +61 -21
  75. package/dist/support/sf.d.ts +14 -0
  76. package/dist/support/sf.js +89 -4
  77. package/dist/support/sobjects.js +5 -4
  78. package/dist/support/stepArguments.d.ts +38 -0
  79. package/dist/support/stepArguments.js +74 -0
  80. package/docs/CHANGELOG.md +209 -169
  81. package/docs/EXTENSIONS.html +540 -0
  82. package/docs/SPEC.html +5761 -1490
  83. package/package.json +82 -81
  84. package/readme.md +95 -96
  85. package/sftest.config.jsonc +5 -0
  86. package/templates/env +8 -8
  87. package/templates/gitignore +7 -7
  88. package/templates/playwright.config.ts +17 -17
  89. package/templates/vscode-settings.json +4 -4
@@ -0,0 +1,381 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.messageLines = messageLines;
7
+ exports.formatDuration = formatDuration;
8
+ exports.stepText = stepText;
9
+ /**
10
+ * 実行中の経過を、シナリオとステップごとに1行ずつ標準出力に表示する Playwright のレポーター(20261015-011)。
11
+ *
12
+ * Playwright の既定の表示(line レポーター)は、1行を上書きしながら表示し、失敗の最後にスタックトレースとコードの抜粋を表示する。
13
+ * このレポーターは、どこまで実行されたか、どこで異常があったかを分かるように、次のとおり表示する。
14
+ * - シナリオの開始: 番号・機能・シナリオ名。
15
+ * - ステップ(背景を含む、シナリオに書いたステップ)の終了ごと: 結果(OK・NG・不一致)と所要時間。
16
+ * - 失敗したステップの下: エラーのメッセージだけ(スタックトレース・コードの抜粋・呼び出しの記録は出さない)。
17
+ * - シナリオの終了: 結果と所要時間。ステップの外の失敗(終了時の判定・後片付け)や、制限時間の超過も示す。
18
+ * - 最後: 件数と、詳しい結果(HTML レポート)の開き方。
19
+ * 詳しいエラー(スタックトレースなど)は、HTML レポートで確認する。
20
+ *
21
+ * @author Fluxengine.co.jp
22
+ */
23
+ const node_path_1 = __importDefault(require("node:path"));
24
+ /** エラーのメッセージとして表示する最大の行数。 */
25
+ const MAX_MESSAGE_LINES = 12;
26
+ /**
27
+ * エラーのメッセージから、利用者に示す部分だけを取り出す。
28
+ *
29
+ * 色の制御文字を除き、Playwright の呼び出しの記録(Call log 以降)とスタックトレース(at で始まる行)を除く。
30
+ *
31
+ * @param error - Playwright のエラー。
32
+ * @returns 表示する行(最大 MAX_MESSAGE_LINES 行)。
33
+ */
34
+ function messageLines(error) {
35
+ const text = (error?.message ?? error?.value ?? '').replace(/\u001b\[[0-9;]*m/g, '');
36
+ const lines = [];
37
+ for (const raw of text.split(/\r?\n/)) {
38
+ const line = raw.trimEnd();
39
+ if (/^\s*Call log:/i.test(line))
40
+ break; // expect.poll では「Call Log:」と書かれる。
41
+ if (/^\s+at /.test(line))
42
+ continue;
43
+ if (!line.trim() && (!lines.length || !lines[lines.length - 1].trim()))
44
+ continue;
45
+ // 分類名([テスト結果NG] など)の前の例外名(ExecutionFailure: など)も除き、分類名から示す(20261018-009)。
46
+ lines.push(line.replace(/^[A-Za-z]*(?:Error|Failure): (?=\[(?:テスト結果NG|シナリオ不正|実行時エラー)\] )/, '').replace(/^Error: /, ''));
47
+ }
48
+ while (lines.length && !lines[lines.length - 1].trim())
49
+ lines.pop();
50
+ if (lines.length > MAX_MESSAGE_LINES)
51
+ return [...lines.slice(0, MAX_MESSAGE_LINES), '…(続きは HTML レポートで確認してください)'];
52
+ return lines;
53
+ }
54
+ /**
55
+ * 所要時間を「1.2秒」「2分3秒」の形にする。
56
+ *
57
+ * @param ms - ミリ秒。
58
+ * @returns 表示用の文字。
59
+ */
60
+ function formatDuration(ms) {
61
+ if (ms < 60_000)
62
+ return `${(ms / 1000).toFixed(1)}秒`;
63
+ const total = Math.round(ms / 1000);
64
+ return `${Math.floor(total / 60)}分${total % 60}秒`;
65
+ }
66
+ /**
67
+ * ステップの題名を、シナリオに書いたとおりの「キーワード ステップの文」の形にする。
68
+ *
69
+ * playwright-bdd の題名は、キーワード(前提・もし・ならば・かつ・しかし)と文が空白なしでつながっているため、間に空白を入れる。
70
+ *
71
+ * @param title - ステップの題名。
72
+ * @returns 表示用の文字。
73
+ */
74
+ function stepText(title) {
75
+ return title.replace(/^(前提|もし|ならば|かつ|しかし|\*)\s*/, '$1 ');
76
+ }
77
+ /**
78
+ * シナリオに書いたステップ(Gherkin のステップ)かを返す。
79
+ *
80
+ * playwright-bdd は、各ステップを test.step(題名はキーワードとステップの文)として実行する。シナリオのステップはテストの直下で、
81
+ * 背景のステップは前処理(test.beforeEach「背景」。hook)の中で実行する(20261016-005)。そのため、祖先に test.step を持たない
82
+ * test.step をシナリオのステップとする(ステップの中で呼ばれる処理の test.step は対象にしない)。
83
+ *
84
+ * @param step - Playwright のステップ。
85
+ * @returns シナリオのステップ(背景を含む)なら true。
86
+ */
87
+ function isScenarioStep(step) {
88
+ if (step.category !== 'test.step')
89
+ return false;
90
+ for (let p = step.parent; p; p = p.parent)
91
+ if (p.category === 'test.step')
92
+ return false;
93
+ return true;
94
+ }
95
+ /**
96
+ * 背景のステップ(前処理の中のシナリオのステップ)かを返す(20261016-005)。
97
+ *
98
+ * @param step - シナリオのステップ。
99
+ * @returns 祖先に前処理(hook)があれば true。
100
+ */
101
+ function isBackgroundStep(step) {
102
+ for (let p = step.parent; p; p = p.parent)
103
+ if (p.category === 'hook')
104
+ return true;
105
+ return false;
106
+ }
107
+ /**
108
+ * ステップの中で、検査の不一致として記録されたもの(support/mismatch.ts の recordMismatch)を集める。
109
+ * ステップの中で受け止めて処理した待機の失敗などは、不一致に数えない。
110
+ *
111
+ * @param step - シナリオのステップ。
112
+ * @returns 不一致のエラー。
113
+ */
114
+ function recordedMismatches(step) {
115
+ const found = [];
116
+ const walk = (s) => {
117
+ if (s.error && /toBeRecordedMismatch/.test(s.title))
118
+ found.push(s.error);
119
+ for (const child of s.steps)
120
+ walk(child);
121
+ };
122
+ for (const child of step.steps)
123
+ walk(child);
124
+ return found;
125
+ }
126
+ /** 実行中の経過を、ステップごとに1行ずつ表示するレポーター。 */
127
+ class ConsoleReporter {
128
+ total = 0;
129
+ started = 0;
130
+ numbers = new Map();
131
+ /** シナリオごとの、ステップの下に表示したエラーのメッセージ(ステップの外の失敗と重ねて表示しないため)。 */
132
+ shown = new Map();
133
+ /** ステップのエラー(記録した不一致を除く)で中断したシナリオ。 */
134
+ stopped = new Set();
135
+ /** シナリオごとの、最後に示した区切り((背景)・(シナリオ))。背景のないシナリオは区切りを示さない(20261016-005)。 */
136
+ parts = new Map();
137
+ counts = { passed: 0, failed: 0, expectedFailed: 0, unexpectedPassed: 0, timedOut: 0, skipped: 0, interrupted: 0 };
138
+ failedTitles = [];
139
+ reportCommand;
140
+ startedAt = Date.now();
141
+ /**
142
+ * 設定を受け取る。
143
+ *
144
+ * @param options - レポーターの設定。
145
+ */
146
+ constructor(options = {}) {
147
+ this.reportCommand = options.reportCommand ?? 'npx sftest report';
148
+ this.listOnly = options._mode === 'list';
149
+ }
150
+ /**
151
+ * --list のとき、シナリオを実行せず一覧だけを表示する(20261016-003)。
152
+ * このレポーターが画面に書くため、Playwright は一覧の表示用のレポーターを加えない。そのため、ここで一覧を表示する。
153
+ */
154
+ listOnly;
155
+ /** 標準出力に書くレポーターであることを Playwright に知らせる(既定の line レポーターを加えさせない)。 */
156
+ printsToStdio() {
157
+ return true;
158
+ }
159
+ /**
160
+ * 実行の開始。シナリオの件数を表示する。
161
+ *
162
+ * @param _config - 設定。
163
+ * @param suite - 実行するシナリオの全体。
164
+ */
165
+ onBegin(config, suite) {
166
+ const tests = suite.allTests();
167
+ this.total = tests.length;
168
+ this.startedAt = Date.now();
169
+ if (this.listOnly) {
170
+ // --list: 番号・機能 › シナリオ・生成したテストの位置を1行ずつ示し、件数とファイルの数で終える(実行はしない)。
171
+ this.write('実行の対象のシナリオ(--list のため、実行はしません):');
172
+ const files = new Set();
173
+ tests.forEach((test, i) => {
174
+ const location = `${node_path_1.default.relative(config.rootDir, test.location.file).replace(/\\/g, '/')}:${test.location.line}`;
175
+ this.write(` [${i + 1}] ${this.titleOf(test)}(${location})`);
176
+ files.add(test.location.file);
177
+ });
178
+ this.write(`合計: ${this.total} 件のシナリオ(${files.size} ファイル)`);
179
+ return;
180
+ }
181
+ this.write(`${this.total} 件のシナリオを実行します。`);
182
+ }
183
+ /**
184
+ * シナリオの開始。番号・機能・シナリオ名を表示する。
185
+ *
186
+ * @param test - シナリオ。
187
+ */
188
+ onTestBegin(test) {
189
+ this.started += 1;
190
+ this.numbers.set(test, this.started);
191
+ this.shown.set(test, new Set());
192
+ this.write('');
193
+ this.write(`[${this.started}/${this.total}] ${this.titleOf(test)}`);
194
+ }
195
+ /**
196
+ * ステップの終了。シナリオのステップだけ、結果と所要時間を1行で表示し、失敗・不一致の場合はメッセージを続けて表示する。
197
+ *
198
+ * @param test - シナリオ。
199
+ * @param _result - シナリオの結果。
200
+ * @param step - 終了したステップ。
201
+ */
202
+ onStepEnd(test, _result, step) {
203
+ if (!isScenarioStep(step))
204
+ return;
205
+ // 背景のステップの前に「(背景)」、背景の後のシナリオのステップの前に「(シナリオ)」を1回ずつ示す(20261016-005)。
206
+ const part = isBackgroundStep(step) ? '(背景)' : this.parts.get(test) ? '(シナリオ)' : undefined;
207
+ if (part && this.parts.get(test) !== part) {
208
+ this.write(` ${part}`);
209
+ this.parts.set(test, part);
210
+ }
211
+ // 記録した不一致は、ステップのエラーにもなる(expect.soft)。ステップのエラーが記録した不一致のどれかと同じなら、
212
+ // 中断ではなく不一致として表示する(後続のステップへ進む)。それ以外のエラーは、そのステップで中断した。
213
+ const mismatches = recordedMismatches(step);
214
+ const key = (error) => messageLines(error).join('\n');
215
+ const mismatchOnly = mismatches.length > 0 && (!step.error || mismatches.some((m) => key(m) === key(step.error)));
216
+ const mark = mismatchOnly ? '不一致' : step.error ? 'NG ' : 'OK ';
217
+ this.write(` ${mark} ${stepText(step.title)}(${formatDuration(step.duration)})`);
218
+ if (mismatchOnly) {
219
+ for (const error of mismatches)
220
+ this.writeError(test, error);
221
+ }
222
+ else if (step.error) {
223
+ this.writeError(test, step.error);
224
+ this.stopped.add(test);
225
+ }
226
+ }
227
+ /**
228
+ * テストの中から標準出力に書かれた内容(開始前の計測など)を、そのまま表示する。
229
+ *
230
+ * @param chunk - 書かれた内容。
231
+ */
232
+ onStdOut(chunk) {
233
+ process.stdout.write(chunk);
234
+ }
235
+ /**
236
+ * テストの中から標準エラーに書かれた内容を、そのまま表示する。
237
+ *
238
+ * @param chunk - 書かれた内容。
239
+ */
240
+ onStdErr(chunk) {
241
+ process.stderr.write(chunk);
242
+ }
243
+ /**
244
+ * シナリオの終了。ステップの外の失敗と、シナリオの結果を表示する。
245
+ *
246
+ * @param test - シナリオ。
247
+ * @param result - シナリオの結果。
248
+ */
249
+ onTestEnd(test, result) {
250
+ const shown = this.shown.get(test) ?? new Set();
251
+ const outside = result.errors.filter((error) => !shown.has(messageLines(error).join('\n')));
252
+ if (this.stopped.has(test) && result.status !== 'timedOut')
253
+ this.write(' (このステップで中断し、以降のステップは実行していません)');
254
+ if (result.status === 'timedOut') {
255
+ this.write(` NG シナリオの制限時間(${formatDuration(test.timeout)})を超えました。実行中のステップを止めました。`);
256
+ }
257
+ for (const error of outside) {
258
+ // 制限時間の超過は上で日本語で示したため、Playwright の英語のメッセージは重ねて表示しない。
259
+ if (result.status === 'timedOut' && /Test timeout of \d+ms exceeded/.test(error.message ?? ''))
260
+ continue;
261
+ this.write(' NG シナリオの終了時');
262
+ this.writeError(test, error);
263
+ }
264
+ const label = this.resultLabel(test, result);
265
+ this.write(` → ${label}(${formatDuration(result.duration)})`);
266
+ }
267
+ /**
268
+ * 実行全体にかかわるエラー(全体の前処理の失敗など)を、メッセージだけ表示する。
269
+ *
270
+ * @param error - エラー。
271
+ */
272
+ onError(error) {
273
+ this.write('');
274
+ this.write('NG 実行の途中でエラーが発生しました');
275
+ for (const line of messageLines(error))
276
+ this.write(` ${line}`);
277
+ }
278
+ /**
279
+ * 実行の終了。件数と、失敗したシナリオ、詳しい結果の開き方を表示する。
280
+ *
281
+ * @param result - 実行全体の結果。
282
+ */
283
+ onEnd(result) {
284
+ if (this.listOnly)
285
+ return; // --list は実行していないため、結果の行を出さない。
286
+ const c = this.counts;
287
+ const parts = [`成功 ${c.passed} 件`];
288
+ if (c.expectedFailed)
289
+ parts.push(`期待どおりの失敗(@fail) ${c.expectedFailed} 件`);
290
+ if (c.failed)
291
+ parts.push(`失敗 ${c.failed} 件`);
292
+ if (c.timedOut)
293
+ parts.push(`制限時間の超過 ${c.timedOut} 件`);
294
+ if (c.unexpectedPassed)
295
+ parts.push(`失敗を期待したのに成功 ${c.unexpectedPassed} 件`);
296
+ if (c.interrupted)
297
+ parts.push(`中止 ${c.interrupted} 件`);
298
+ if (c.skipped)
299
+ parts.push(`実行しなかった ${c.skipped} 件`);
300
+ this.write('');
301
+ this.write(`結果: ${parts.join('、')}(全 ${this.total} 件、${formatDuration(Date.now() - this.startedAt)})${result.status === 'interrupted' ? '。途中で中止しました' : ''}`);
302
+ if (this.failedTitles.length) {
303
+ this.write('期待と異なったシナリオ:');
304
+ for (const title of this.failedTitles)
305
+ this.write(` ${title}`);
306
+ }
307
+ this.write(`詳しい結果(画面キャプチャー・エラーの詳細): ${this.reportCommand}`);
308
+ }
309
+ /**
310
+ * シナリオの結果を数え、表示用の文字を返す。
311
+ *
312
+ * @param test - シナリオ。
313
+ * @param result - シナリオの結果。
314
+ * @returns 表示用の文字。
315
+ */
316
+ resultLabel(test, result) {
317
+ const number = this.numbers.get(test);
318
+ const unexpected = (label) => {
319
+ this.failedTitles.push(`[${number}] ${this.titleOf(test)}(${label})`);
320
+ return label;
321
+ };
322
+ if (result.status === 'skipped') {
323
+ this.counts.skipped += 1;
324
+ return '実行しなかった';
325
+ }
326
+ if (result.status === 'interrupted') {
327
+ this.counts.interrupted += 1;
328
+ return unexpected('中止');
329
+ }
330
+ // 制限時間の超過は、@fail のシナリオでも期待と異なる結果とする(Playwright も失敗として数える)。期待した失敗の分岐より前に判定する。
331
+ if (result.status === 'timedOut') {
332
+ this.counts.timedOut += 1;
333
+ return unexpected('制限時間の超過');
334
+ }
335
+ if (test.expectedStatus === 'failed') {
336
+ if (result.status === 'passed') {
337
+ this.counts.unexpectedPassed += 1;
338
+ return unexpected('失敗を期待したのに成功');
339
+ }
340
+ this.counts.expectedFailed += 1;
341
+ return '期待どおりの失敗(@fail)';
342
+ }
343
+ if (result.status === 'passed') {
344
+ this.counts.passed += 1;
345
+ return '成功';
346
+ }
347
+ this.counts.failed += 1;
348
+ return unexpected('失敗');
349
+ }
350
+ /**
351
+ * シナリオの表示名(機能 › シナリオ)を返す。
352
+ *
353
+ * @param test - シナリオ。
354
+ * @returns 表示名。
355
+ */
356
+ titleOf(test) {
357
+ const feature = test.parent?.title;
358
+ return feature ? `${feature} › ${test.title}` : test.title;
359
+ }
360
+ /**
361
+ * エラーのメッセージを、ステップの下に字下げして表示し、表示済みとして覚える。
362
+ *
363
+ * @param test - シナリオ。
364
+ * @param error - エラー。
365
+ */
366
+ writeError(test, error) {
367
+ const lines = messageLines(error);
368
+ this.shown.get(test)?.add(lines.join('\n'));
369
+ for (const line of lines)
370
+ this.write(` ${line}`);
371
+ }
372
+ /**
373
+ * 1行を標準出力に書く。
374
+ *
375
+ * @param line - 書く行。
376
+ */
377
+ write(line) {
378
+ process.stdout.write(`${line}\n`);
379
+ }
380
+ }
381
+ exports.default = ConsoleReporter;
@@ -0,0 +1,102 @@
1
+ /** テスト結果と実行できない原因の分類(公開仕様書4.3)。 */
2
+ export type FailureCategory = 'test-ng' | 'scenario-invalid' | 'runtime-error';
3
+ /** 中断する範囲を決める実行工程。 */
4
+ export type ExecutionPhase = 'configuration' | 'test-setup' | 'scenario-setup' | 'step' | 'scenario-teardown' | 'test-teardown';
5
+ /** 分類と工程に基づく共通の判断。個別ステップ名には依存しない。 */
6
+ export type FailureDisposition = 'record-ng' | 'abort-scenario' | 'abort-test';
7
+ /** 拡張側と本体側が別のモジュールとして読み込まれても共有する、明示的な通知の目印。 */
8
+ declare const FAILURE_BRAND: unique symbol;
9
+ /**
10
+ * 分類と原因を保持する失敗。シナリオ間で共有する状態は持たない。
11
+ *
12
+ * NGの通知自体は例外としても扱えるが、実行境界は共通方針に従って記録へ変換する。
13
+ * 元のメッセージはdetail、元の例外はcauseに保持する。
14
+ */
15
+ export declare class ExecutionFailure extends Error {
16
+ readonly category: FailureCategory;
17
+ readonly detail: string;
18
+ readonly [FAILURE_BRAND] = true;
19
+ /**
20
+ * 分類名を表示に付け、元の原因を保持する。
21
+ *
22
+ * @param category - 通知元が確定した分類。
23
+ * @param detail - 対象・期待条件・観測した結果、または実行できない理由。
24
+ * @param options - 元の例外をcauseとして引き継ぐ指定。省略時は原因の指定なし。
25
+ */
26
+ constructor(category: FailureCategory, detail: string, options?: ErrorOptions);
27
+ }
28
+ /** 分類と発生工程を確定した判断。記録・中断を行う実行境界へ渡す。 */
29
+ export interface FailureDecision {
30
+ failure: ExecutionFailure;
31
+ phase: ExecutionPhase;
32
+ disposition: FailureDisposition;
33
+ }
34
+ /**
35
+ * 未分類の例外を実行時エラーへ変換する。分類済みの例外は同じものを返す。
36
+ *
37
+ * メッセージやmatcherResultから分類を推測しない。expectの互換処理は呼出元で明示する。
38
+ *
39
+ * @param error - 操作・検査または実行境界で受け取った例外。
40
+ * @returns 分類を識別でき、元の例外をcauseに保持する失敗。
41
+ */
42
+ export declare function classifyFailure(error: unknown): ExecutionFailure;
43
+ /**
44
+ * 分類されていない例外に分類を付けた失敗を作る。分類済みの例外は同じものを返す(分類を付け直さない)。
45
+ *
46
+ * 発生元が原因を知っている場合(対象を確かめる expect の不成立をシナリオ不正にする場合など)に使う。元の name・スタック・
47
+ * matcherResult を、作る失敗そのものに移し、元の例外は cause に残す(classifyFailure と同じ)。
48
+ *
49
+ * @param category - 付ける分類。
50
+ * @param error - 元の例外。
51
+ * @returns 分類を持つ失敗。
52
+ */
53
+ export declare function withCategory(category: FailureCategory, error: unknown): ExecutionFailure;
54
+ /**
55
+ * 別の読み込み元から届いた失敗も、共有する目印と契約の項目で識別する。
56
+ *
57
+ * @param error - 調べる通知。
58
+ * @returns 明示的な分類の目印と、必要な項目を持つ場合はtrue。
59
+ */
60
+ export declare function isExecutionFailure(error: unknown): error is ExecutionFailure;
61
+ /**
62
+ * 継続を許さない開始・終了工程の同期処理に、共通の中断方針を適用する。
63
+ *
64
+ * @param phase - ステップ以外の発生工程。
65
+ * @param run - 設定の検証、または開始・終了の処理。
66
+ * @returns 正常に完了した処理の戻り値。
67
+ * @throws 分類を保持した失敗。ステップ以外からのNG通知は実行時エラーとなる。
68
+ */
69
+ export declare function runRequired<T>(phase: Exclude<ExecutionPhase, 'step'>, run: () => T): T;
70
+ /**
71
+ * 失敗の分類と発生工程から、記録・シナリオ中断・テスト全体の中断を判断する。
72
+ *
73
+ * 検査を行うステップ以外からNGが通知された場合は、契約の不備を実行時エラーとする。
74
+ * 終了工程でも原因を分類したまま返し、必要な片付けや一次原因の保持は実行境界が担う。
75
+ *
76
+ * @param error - 分類済みの失敗、または分類がまだない例外。
77
+ * @param phase - 失敗が発生した工程。
78
+ * @returns 発生工程と、分類を保持した共通の判断。
79
+ */
80
+ export declare function decideFailure(error: unknown, phase: ExecutionPhase): FailureDecision;
81
+ /**
82
+ * 共通の判断を適用し、NGを記録するか、分類済みの失敗を投げる。
83
+ *
84
+ * NGの記録先が失敗した場合は、その原因を実行時エラーとして投げる。記録失敗を成功扱いにしない。
85
+ *
86
+ * @param error - 通知された失敗。
87
+ * @param phase - 発生した工程。
88
+ * @param recordNg - NGを実行結果に残す同期処理。中断を指示する判断では呼ばない。
89
+ * @throws 共通方針が中断を指示した場合、またはNGを記録できない場合。
90
+ */
91
+ export declare function applyFailure(error: unknown, phase: ExecutionPhase, recordNg: (failure: ExecutionFailure) => void): void;
92
+ /**
93
+ * 非同期の処理を実行し、通知された失敗へ共通方針を適用する。
94
+ *
95
+ * @param phase - この処理の発生工程。
96
+ * @param run - 操作・検査、または開始・終了の処理。
97
+ * @param recordNg - NGを実行結果に残す同期処理。
98
+ * @returns 処理が完了した時点、またはNGを記録した時点で解決する。
99
+ * @throws シナリオ不正・実行時エラー、契約の不備、またはNGの記録失敗。
100
+ */
101
+ export declare function runControlled(phase: ExecutionPhase, run: () => Promise<void>, recordNg: (failure: ExecutionFailure) => void): Promise<void>;
102
+ export {};