You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(core): add merge action to report-tool CLI (#2497)
* feat(core): add merge action to report-tool CLI
Add a `merge` action to the generic `report-tool` command so multiple
HTML reports produced by separate CLI invocations can be combined into
a single report without writing custom scripts. Expose the matching
`mergeReportFiles` helper from `@midscene/core` as a JS SDK so the
same workflow is reachable in code.
- `report-tool --action merge` accepts `--htmlPaths` (JSON array or
comma-separated list) plus optional `--outputDir`, `--outputName`,
and `--overwrite`. Source paths may be HTML files or directories
containing `index.html`.
- `ReportMergingTool.mergeReports` now accepts an optional `outputDir`
override; default behavior (write under `midscene_run/report`) is
unchanged, so existing callers (Playwright reporter, etc.) are not
affected.
- The CLI auto-derives `testTitle` / `testDescription` from each
source report's `groupName` / `groupDescription`, so users do not
have to supply per-report metadata.
- Update EN/ZH `consume-report-file` docs with CLI and SDK examples.
* refactor(shared): accumulate repeated CLI flags into arrays
Repeated `--key value` (or `--key=value`) flags now collect into a
string array via `parseCliArgs`, so command schemas can opt into
yargs-style multi-value inputs without ad-hoc CSV/JSON splitting.
* refactor(core): switch report-tool merge to repeated --htmlReport flag
Replace the JSON/CSV `--htmlPaths` argument with the more idiomatic
`--htmlReport` flag, accumulating repeated occurrences into an array
via the shared `parseCliArgs` helper. The handler also accepts a
single string value, and the merge action now reads from `htmlReport`.
Adds an end-to-end test that drives the merge action through
`runToolsCLI` argv to exercise parsing + schema validation + handler
in one path.
* docs(site): document repeated --htmlReport flag for report-tool merge
Update the bilingual report-file consumption guide to show the new
yargs-style invocation with one `--htmlReport` per source report.
* docs(site): remove summary paragraph from report parsing docs (#2536)
---------
Co-authored-by: yuyutaotao <167746126+yuyutaotao@users.noreply.github.com>
Repeat `--htmlReport` once per source report. `--outputDir` and `--outputName` are optional; when omitted, the merged file is written to the default Midscene report directory with an auto-generated name. Pass `--overwrite` to replace an existing merged file.
74
+
64
75
## Parse With The JavaScript SDK
65
76
66
-
If you prefer to control report parsing in code, use `splitReportFile`and `reportFileToMarkdown` from `@midscene/core`.
77
+
If you prefer to control report parsing in code, use `splitReportFile`, `reportFileToMarkdown`, and `mergeReportFiles` from `@midscene/core`.
`splitReportFile`and `reportFileToMarkdown` serve different outputs:
109
+
`splitReportFile`, `reportFileToMarkdown`, and `mergeReportFiles` serve different outputs:
85
110
86
111
-`splitReportFile` generates JSON files for the original structured objects (one `*.execution.json` per execution). The JSON keeps the raw `ReportActionDump`-style data and exports screenshots alongside it. The returned `executionJsonFiles` and `screenshotFiles` are lists of generated file paths.
87
112
-`reportFileToMarkdown` converts the same report into human-readable Markdown and exports the screenshots referenced by that Markdown. The returned `markdownFiles` contains the generated Markdown file paths.
113
+
-`mergeReportFiles` combines several report files into one merged HTML report. It is a thin wrapper over [`ReportMergingTool`](./api#new-reportmergingtool) that derives `testTitle`/`testDescription` from each source report's `groupName` automatically. Use it when you run multiple CLI actions or tests and want to consolidate their reports.
88
114
89
-
Use `splitReportFile` when you want the most complete, programmatic raw data. Use `reportFileToMarkdown` when you want readable content for summarization or downstream content generation.
'Transform Midscene report artifacts, including splitting executions and converting to markdown.',
291
+
'Transform Midscene report artifacts, including splitting executions, converting to markdown, and merging multiple reports.',
207
292
schema: {
208
293
action: z
209
-
.enum(['split','to-markdown'])
294
+
.enum(['split','to-markdown','merge-html'])
210
295
.optional()
211
296
.describe(
212
-
'Report action to run. Supports: split, to-markdown. Defaults to split.',
297
+
'Report action to run. Supports: split, to-markdown, merge-html. Defaults to split.',
213
298
),
214
299
htmlPath: z
215
300
.string()
216
301
.optional()
217
-
.describe('Input report HTML path (e.g. ./report/index.html)'),
302
+
.describe(
303
+
'Input report HTML path (e.g. ./report/index.html). Used by split and to-markdown.',
304
+
),
305
+
htmlReport: z
306
+
.union([z.string(),z.array(z.string())])
307
+
.optional()
308
+
.describe(
309
+
'Input report HTML path for the merge action. Repeat the flag to merge multiple reports (e.g. --htmlReport ./a/index.html --htmlReport ./b.html).',
310
+
),
218
311
outputDir: z
219
312
.string()
220
313
.optional()
221
-
.describe('Output directory for generated report artifacts'),
314
+
.describe(
315
+
'Output directory for generated report artifacts. For merge, defaults to the Midscene report directory.',
316
+
),
317
+
outputName: z
318
+
.string()
319
+
.optional()
320
+
.describe(
321
+
'Output report file/directory name (without .html) for the merge action. Defaults to an auto-generated name.',
322
+
),
323
+
overwrite: z
324
+
.union([z.boolean(),z.string()])
325
+
.optional()
326
+
.describe(
327
+
'Overwrite the existing merged report file if present (merge action only).',
328
+
),
222
329
},
223
330
handler: async(args)=>{
224
331
const{
225
332
action ='split',
226
333
htmlPath,
334
+
htmlReport,
227
335
outputDir,
336
+
outputName,
337
+
overwrite,
228
338
}=argsas{
229
339
action?: string;
230
340
htmlPath?: string;
341
+
htmlReport?: unknown;
231
342
outputDir?: string;
343
+
outputName?: string;
344
+
overwrite?: unknown;
232
345
};
233
-
if(action!=='split'&&action!=='to-markdown'){
346
+
if(
347
+
action!=='split'&&
348
+
action!=='to-markdown'&&
349
+
action!=='merge-html'
350
+
){
234
351
thrownewError(
235
-
`report-tool: unsupported --action value "${action}". Currently supported: split, to-markdown`,
352
+
`report-tool: unsupported --action value "${action}". Currently supported: split, to-markdown, merge-html`,
236
353
);
237
354
}
238
355
356
+
if(action==='merge-html'){
357
+
constpaths=normalizeHtmlReportArg(htmlReport);
358
+
if(!paths||paths.length===0){
359
+
thrownewError(
360
+
'report-tool: --htmlReport is required for action "merge-html". Repeat --htmlReport for each report (e.g. --htmlReport ./a/index.html --htmlReport ./b.html).',
0 commit comments