@midscene/test 1.17.5-beta-20261102094111.0 → 1.17.6

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.
@@ -8,7 +8,7 @@ import { createHash, randomUUID } from "node:crypto";
8
8
  import { JSON_SCHEMA, load } from "js-yaml";
9
9
  import { mkdir, writeFile } from "node:fs/promises";
10
10
  import { setMaxListeners } from "node:events";
11
- import { TestRunReportAssembler, calculateTestRunHealth } from "@midscene/core/report";
11
+ import { ReportSession, TestRunReportAssembler, calculateTestRunHealth } from "@midscene/core/report";
12
12
  import { getDebug, runWithConsoleLogScope } from "@midscene/shared/logger";
13
13
  import "node:util";
14
14
  import { globalConfigManager } from "@midscene/shared/env";
@@ -1137,6 +1137,9 @@ async function prepareTestRun(options) {
1137
1137
  onEvent: options.onEvent
1138
1138
  };
1139
1139
  }
1140
+ function renderTestBadge(summary) {
1141
+ return `![Midscene Test: ${summary.passed} passed, ${summary.failed} failed](https://badge.midscenejs.com/e2e?pass=${summary.passed}&fail=${summary.failed}&style=large)`;
1142
+ }
1140
1143
  const result_markdown_text = (value)=>value.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;').replaceAll('|', '&#124;').replaceAll('[', '&#91;').replaceAll(']', '&#93;').replaceAll('*', '&#42;').replaceAll('_', '&#95;').replaceAll('`', '&#96;').replaceAll('\\', '&#92;').replace(/[\r\n]+/g, ' ');
1141
1144
  const duration = (ms)=>{
1142
1145
  const seconds = Math.round(ms / 1000);
@@ -1149,6 +1152,8 @@ function renderTestResultMarkdown(dump, options = {}) {
1149
1152
  const lines = [
1150
1153
  '## Midscene Test',
1151
1154
  '',
1155
+ renderTestBadge(summary),
1156
+ '',
1152
1157
  `${outcome} · ${duration(dump.durationMs)}`,
1153
1158
  ''
1154
1159
  ];
@@ -1880,6 +1885,10 @@ const latestById = (items, id)=>[
1880
1885
  ];
1881
1886
  const notRunSuite = (prepared, reason)=>prepared.documents.flatMap((document)=>document.cases.map((item)=>asNotRun(document.documentId, item, prepared.project.name, reason)));
1882
1887
  async function runPreparedTestProject(plan) {
1888
+ const reports = new ReportSession(join(plan.runDir, 'records'));
1889
+ return reports.run(()=>runWithReportSession(plan, reports));
1890
+ }
1891
+ async function runWithReportSession(plan, reports) {
1883
1892
  const { startedAt, runId, projectRoot, configPath, resultDir, runDir, summaryPath, reportDir, definition, projects: preparedProjects } = plan;
1884
1893
  const progress = plan.onProgress;
1885
1894
  const totalDocuments = preparedProjects.reduce((total, prepared)=>total + prepared.documents.length, 0);
@@ -2089,6 +2098,10 @@ async function runPreparedTestProject(plan) {
2089
2098
  } : {},
2090
2099
  result: completedResult
2091
2100
  }));
2101
+ let extraSources = [];
2102
+ await publish('write-report', reports.directory, async ()=>{
2103
+ extraSources = await reports.finish();
2104
+ });
2092
2105
  const writeReport = ()=>publish('write-report', reportDir, async ()=>{
2093
2106
  if (!plan.reportEnabled) return;
2094
2107
  const reportPath = await new TestRunReportAssembler().assembleAsync({
@@ -2096,7 +2109,13 @@ async function runPreparedTestProject(plan) {
2096
2109
  outputFormat: plan.definition.output.reportFormat,
2097
2110
  reportFileName: `midscene-e2e-${runId}`,
2098
2111
  overwrite: false,
2099
- sources: collectTestRunReportSources(completedResult),
2112
+ sources: [
2113
+ ...collectTestRunReportSources(completedResult),
2114
+ ...extraSources.map((source)=>({
2115
+ ...source,
2116
+ scopeId: runId
2117
+ }))
2118
+ ],
2100
2119
  buildRunnerDump: (index)=>{
2101
2120
  reportIndex = index;
2102
2121
  const dump = buildTestRunReportDump(completedResult, index);
@@ -2137,6 +2156,7 @@ async function runPreparedTestProject(plan) {
2137
2156
  markdownPath
2138
2157
  };
2139
2158
  });
2159
+ if (completedResult.reportPath && !hasInfrastructureError) await publish('write-result', reports.directory, ()=>reports.prune());
2140
2160
  await writeSummary();
2141
2161
  if (hasInfrastructureError) throw new WorkflowExecutionFailure(completedResult, infrastructureErrors);
2142
2162
  return completedResult;