@midscene/web 1.17.4 → 1.17.5
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.
- package/dist/es/bridge-mode/io-client.mjs +1 -1
- package/dist/es/bridge-mode/io-server.mjs +2 -2
- package/dist/es/bridge-mode/page-browser-side.mjs +1 -1
- package/dist/es/cli.mjs +1 -1
- package/dist/es/playwright/reporter/index.mjs +4 -59
- package/dist/es/playwright/reporter/index.mjs.map +1 -1
- package/dist/lib/bridge-mode/io-client.js +1 -1
- package/dist/lib/bridge-mode/io-server.js +2 -2
- package/dist/lib/bridge-mode/page-browser-side.js +1 -1
- package/dist/lib/cli.js +1 -1
- package/dist/lib/playwright/reporter/index.js +2 -57
- package/dist/lib/playwright/reporter/index.js.map +1 -1
- package/dist/types/playwright/reporter/index.d.ts +0 -2
- package/dist/types/playwright/reporter/index.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -101,7 +101,7 @@ class BridgeServer {
|
|
|
101
101
|
logMsg('one client connected');
|
|
102
102
|
this.socket = socket;
|
|
103
103
|
const clientVersion = socket.handshake.query.version;
|
|
104
|
-
logMsg(`Bridge connected, cli-side version v1.17.
|
|
104
|
+
logMsg(`Bridge connected, cli-side version v1.17.5, browser-side version v${clientVersion}`);
|
|
105
105
|
socket.on(BridgeEvent.CallResponse, (params)=>{
|
|
106
106
|
const id = params.id;
|
|
107
107
|
const response = params.response;
|
|
@@ -125,7 +125,7 @@ class BridgeServer {
|
|
|
125
125
|
setTimeout(()=>{
|
|
126
126
|
this.onConnect?.();
|
|
127
127
|
const payload = {
|
|
128
|
-
version: "1.17.
|
|
128
|
+
version: "1.17.5"
|
|
129
129
|
};
|
|
130
130
|
socket.emit(BridgeEvent.Connected, payload);
|
|
131
131
|
Promise.resolve().then(()=>{
|
|
@@ -100,7 +100,7 @@ class ExtensionBridgePageBrowserSide extends page {
|
|
|
100
100
|
throw new Error('Connection denied by user');
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
this.onLogMessage(`Bridge connected, cli-side version v${this.bridgeClient.serverVersion}, browser-side version v1.17.
|
|
103
|
+
this.onLogMessage(`Bridge connected, cli-side version v${this.bridgeClient.serverVersion}, browser-side version v1.17.5`, 'log');
|
|
104
104
|
}
|
|
105
105
|
async connect() {
|
|
106
106
|
return await this.setupBridgeClient();
|
package/dist/es/cli.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dirname, join, resolve } from "node:path";
|
|
1
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
3
2
|
import { getReportFileName, printReportMsg } from "@midscene/core/agent";
|
|
4
|
-
import { ReportMergingTool
|
|
3
|
+
import { ReportMergingTool } from "@midscene/core/report";
|
|
5
4
|
import { getMidsceneRunSubDir } from "@midscene/shared/common";
|
|
6
5
|
import { logMsg } from "@midscene/shared/utils";
|
|
7
6
|
import { buildPlaywrightReportTag } from "../report-filename.mjs";
|
|
@@ -41,43 +40,16 @@ class MidsceneReporter {
|
|
|
41
40
|
}
|
|
42
41
|
throw new Error(`Unknown mode: ${this.mode}`);
|
|
43
42
|
}
|
|
44
|
-
getReportPath(testTitle, testId) {
|
|
45
|
-
const fileName = this.getReportFilename(testTitle, testId);
|
|
46
|
-
if ('html-and-external-assets' === this.outputFormat) return join(getMidsceneRunSubDir('report'), fileName, 'index.html');
|
|
47
|
-
return join(getMidsceneRunSubDir('report'), `${fileName}.html`);
|
|
48
|
-
}
|
|
49
43
|
ensureOutputRoot() {
|
|
50
44
|
mkdirSync(getMidsceneRunSubDir('report'), {
|
|
51
45
|
recursive: true
|
|
52
46
|
});
|
|
53
47
|
}
|
|
54
|
-
finalizeSingleReport(reportFilePath, targetPath) {
|
|
55
|
-
if (resolve(reportFilePath) === resolve(targetPath)) return;
|
|
56
|
-
if (isDirectoryModeReport(reportFilePath)) {
|
|
57
|
-
const targetDir = dirname(targetPath);
|
|
58
|
-
mkdirSync(targetDir, {
|
|
59
|
-
recursive: true
|
|
60
|
-
});
|
|
61
|
-
cpSync(dirname(reportFilePath), targetDir, {
|
|
62
|
-
recursive: true,
|
|
63
|
-
force: true
|
|
64
|
-
});
|
|
65
|
-
} else {
|
|
66
|
-
mkdirSync(dirname(targetPath), {
|
|
67
|
-
recursive: true
|
|
68
|
-
});
|
|
69
|
-
copyFileSync(reportFilePath, targetPath);
|
|
70
|
-
}
|
|
71
|
-
try {
|
|
72
|
-
removeReportArtifact(reportFilePath);
|
|
73
|
-
} catch (error) {
|
|
74
|
-
logMsg(`Error deleting report ${reportFilePath}: ${error}`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
48
|
mergeOwnedReports(tool, targetName) {
|
|
78
49
|
return tool.mergeReports(targetName, {
|
|
79
50
|
overwrite: true,
|
|
80
|
-
rmOriginalReports: true
|
|
51
|
+
rmOriginalReports: true,
|
|
52
|
+
outputFormat: this.outputFormat
|
|
81
53
|
});
|
|
82
54
|
}
|
|
83
55
|
collectReportInfo(test, result) {
|
|
@@ -118,19 +90,6 @@ class MidsceneReporter {
|
|
|
118
90
|
}
|
|
119
91
|
if (0 === reportCount) return;
|
|
120
92
|
const targetName = this.getReportFilename();
|
|
121
|
-
if (1 === reportCount) {
|
|
122
|
-
const firstReport = Array.from(this.reportsByTestId.values())[0]?.reports[0];
|
|
123
|
-
if (!firstReport) return;
|
|
124
|
-
if (firstReport.reportFilePath) {
|
|
125
|
-
const targetPath = this.getReportPath();
|
|
126
|
-
this.finalizeSingleReport(firstReport.reportFilePath, targetPath);
|
|
127
|
-
printReportMsg(targetPath);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
const mergedReportPath = this.mergeOwnedReports(tool, targetName);
|
|
131
|
-
if (mergedReportPath) printReportMsg(mergedReportPath);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
93
|
const mergedReportPath = this.mergeOwnedReports(tool, targetName);
|
|
135
94
|
if (mergedReportPath) printReportMsg(mergedReportPath);
|
|
136
95
|
}
|
|
@@ -138,20 +97,6 @@ class MidsceneReporter {
|
|
|
138
97
|
this.ensureOutputRoot();
|
|
139
98
|
for (const [testId, entry] of this.reportsByTestId){
|
|
140
99
|
const targetName = this.getReportFilename(entry.testTitle, testId);
|
|
141
|
-
if (1 === entry.reports.length) {
|
|
142
|
-
const firstReport = entry.reports[0];
|
|
143
|
-
if (firstReport.reportFilePath) {
|
|
144
|
-
const targetPath = this.getReportPath(entry.testTitle, testId);
|
|
145
|
-
this.finalizeSingleReport(firstReport.reportFilePath, targetPath);
|
|
146
|
-
printReportMsg(targetPath);
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
const tool = new ReportMergingTool();
|
|
150
|
-
tool.append(firstReport);
|
|
151
|
-
const reportPath = this.mergeOwnedReports(tool, targetName);
|
|
152
|
-
if (reportPath) printReportMsg(reportPath);
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
100
|
const tool = new ReportMergingTool();
|
|
156
101
|
for (const report of entry.reports)tool.append(report);
|
|
157
102
|
const reportPath = this.mergeOwnedReports(tool, targetName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playwright/reporter/index.mjs","sources":["../../../../src/playwright/reporter/index.ts"],"sourcesContent":["import { copyFileSync, cpSync, existsSync, mkdirSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\nimport type { ReportFileWithAttributes, TestStatus } from '@midscene/core';\nimport { getReportFileName, printReportMsg } from '@midscene/core/agent';\nimport {\n ReportMergingTool,\n isDirectoryModeReport,\n removeReportArtifact,\n} from '@midscene/core/report';\nimport { getMidsceneRunSubDir } from '@midscene/shared/common';\nimport { logMsg } from '@midscene/shared/utils';\nimport type {\n FullConfig,\n Reporter,\n Suite,\n TestCase,\n TestResult,\n} from '@playwright/test/reporter';\nimport { buildPlaywrightReportTag } from '../report-filename';\n\ninterface MidsceneReporterOptions {\n type?: 'merged' | 'separate';\n outputFormat?: 'single-html' | 'html-and-external-assets';\n}\n\nclass MidsceneReporter implements Reporter {\n private mergedFilename?: string;\n private testIdToFilename = new Map<string, string>();\n private reportsByTestId = new Map<\n string,\n {\n testTitle: string;\n reports: ReportFileWithAttributes[];\n }\n >();\n mode?: 'merged' | 'separate';\n outputFormat: 'single-html' | 'html-and-external-assets';\n private hasMultipleProjects = false;\n\n constructor(options: MidsceneReporterOptions = {}) {\n this.mode = MidsceneReporter.getMode(options.type ?? 'merged');\n this.outputFormat = options.outputFormat ?? 'single-html';\n }\n\n private static getMode(reporterType: string): 'merged' | 'separate' {\n if (!reporterType) {\n return 'merged';\n }\n if (reporterType !== 'merged' && reporterType !== 'separate') {\n throw new Error(\n `Unknown reporter type in playwright config: ${reporterType}, only support 'merged' or 'separate'`,\n );\n }\n return reporterType;\n }\n\n private getSeparatedFilename(testTitle: string, testId: string): string {\n if (!this.testIdToFilename.has(testId)) {\n const baseTag = buildPlaywrightReportTag(testTitle, undefined, testId);\n const generatedFilename = getReportFileName(baseTag);\n this.testIdToFilename.set(testId, generatedFilename);\n }\n return this.testIdToFilename.get(testId)!;\n }\n\n private getReportFilename(testTitle?: string, testId?: string): string {\n if (this.mode === 'merged') {\n if (!this.mergedFilename) {\n this.mergedFilename = getReportFileName('playwright-merged');\n }\n return this.mergedFilename;\n }\n if (this.mode === 'separate') {\n if (!testTitle) throw new Error('testTitle is required in separate mode');\n if (!testId) throw new Error('testId is required in separate mode');\n return this.getSeparatedFilename(testTitle, testId);\n }\n throw new Error(`Unknown mode: ${this.mode}`);\n }\n\n private getReportPath(testTitle?: string, testId?: string): string {\n const fileName = this.getReportFilename(testTitle, testId);\n if (this.outputFormat === 'html-and-external-assets') {\n return join(getMidsceneRunSubDir('report'), fileName, 'index.html');\n }\n return join(getMidsceneRunSubDir('report'), `${fileName}.html`);\n }\n\n private ensureOutputRoot(): void {\n mkdirSync(getMidsceneRunSubDir('report'), { recursive: true });\n }\n\n private finalizeSingleReport(\n reportFilePath: string,\n targetPath: string,\n ): void {\n if (resolve(reportFilePath) === resolve(targetPath)) {\n return;\n }\n\n if (isDirectoryModeReport(reportFilePath)) {\n const targetDir = dirname(targetPath);\n mkdirSync(targetDir, { recursive: true });\n cpSync(dirname(reportFilePath), targetDir, {\n recursive: true,\n force: true,\n });\n } else {\n mkdirSync(dirname(targetPath), { recursive: true });\n copyFileSync(reportFilePath, targetPath);\n }\n\n try {\n removeReportArtifact(reportFilePath);\n } catch (error) {\n logMsg(`Error deleting report ${reportFilePath}: ${error}`);\n }\n }\n\n private mergeOwnedReports(\n tool: ReportMergingTool,\n targetName: string,\n ): string | null {\n return tool.mergeReports(targetName, {\n overwrite: true,\n rmOriginalReports: true,\n });\n }\n\n private collectReportInfo(test: TestCase, result: TestResult) {\n const reportAnnotations = test.annotations.filter((annotation) => {\n return (\n annotation.type === 'MIDSCENE_DUMP_ANNOTATION' && annotation.description\n );\n });\n if (reportAnnotations.length === 0 || !this.mode) {\n return;\n }\n\n const retry = result.retry ? `(retry #${result.retry})` : '';\n const testId = `${test.id}${retry}`;\n const projectName = this.hasMultipleProjects\n ? test.parent?.project()?.name\n : undefined;\n const projectSuffix = projectName ? ` [${projectName}]` : '';\n const testTitle = `${test.title}${projectSuffix}${retry}`;\n const reports = reportAnnotations\n .map((annotation) => annotation.description!)\n .filter((reportFilePath) => {\n if (existsSync(reportFilePath)) {\n return true;\n }\n logMsg(\n `Failed to read Midscene report file: ${reportFilePath}`,\n new Error('Report file does not exist'),\n );\n return false;\n })\n .map((reportFilePath): ReportFileWithAttributes => {\n return {\n reportFilePath,\n reportAttributes: {\n testDuration: result.duration,\n testStatus: result.status as TestStatus,\n testTitle,\n testId,\n testDescription: test.parent?.title || '',\n },\n };\n });\n\n if (reports.length === 0) {\n return;\n }\n\n this.reportsByTestId.set(testId, {\n testTitle,\n reports,\n });\n }\n\n private finalizeMergedReport(): void {\n this.ensureOutputRoot();\n const tool = new ReportMergingTool();\n let reportCount = 0;\n for (const entry of this.reportsByTestId.values()) {\n for (const report of entry.reports) {\n tool.append(report);\n reportCount += 1;\n }\n }\n\n if (reportCount === 0) {\n return;\n }\n\n const targetName = this.getReportFilename();\n if (reportCount === 1) {\n const firstReport = Array.from(this.reportsByTestId.values())[0]\n ?.reports[0];\n if (!firstReport) {\n return;\n }\n if (firstReport.reportFilePath) {\n const targetPath = this.getReportPath();\n this.finalizeSingleReport(firstReport.reportFilePath, targetPath);\n printReportMsg(targetPath);\n return;\n }\n\n const mergedReportPath = this.mergeOwnedReports(tool, targetName);\n if (mergedReportPath) {\n printReportMsg(mergedReportPath);\n }\n return;\n }\n\n const mergedReportPath = this.mergeOwnedReports(tool, targetName);\n if (mergedReportPath) {\n printReportMsg(mergedReportPath);\n }\n }\n\n private finalizeSeparateReports(): void {\n this.ensureOutputRoot();\n for (const [testId, entry] of this.reportsByTestId) {\n const targetName = this.getReportFilename(entry.testTitle, testId);\n if (entry.reports.length === 1) {\n const firstReport = entry.reports[0];\n if (firstReport.reportFilePath) {\n const targetPath = this.getReportPath(entry.testTitle, testId);\n this.finalizeSingleReport(firstReport.reportFilePath, targetPath);\n printReportMsg(targetPath);\n continue;\n }\n\n const tool = new ReportMergingTool();\n tool.append(firstReport);\n const reportPath = this.mergeOwnedReports(tool, targetName);\n if (reportPath) {\n printReportMsg(reportPath);\n }\n continue;\n }\n\n const tool = new ReportMergingTool();\n for (const report of entry.reports) {\n tool.append(report);\n }\n const reportPath = this.mergeOwnedReports(tool, targetName);\n if (reportPath) {\n printReportMsg(reportPath);\n }\n }\n }\n\n async onBegin(config: FullConfig, _suite: Suite) {\n this.hasMultipleProjects = (config.projects?.length || 0) > 1;\n }\n\n onTestBegin(_test: TestCase, _result: TestResult) {}\n\n onTestEnd(test: TestCase, result: TestResult) {\n this.collectReportInfo(test, result);\n }\n\n async onEnd() {\n if (this.mode === 'merged') {\n this.finalizeMergedReport();\n return;\n }\n\n if (this.mode === 'separate') {\n this.finalizeSeparateReports();\n }\n }\n}\n\nexport default MidsceneReporter;\n"],"names":["MidsceneReporter","reporterType","Error","testTitle","testId","baseTag","buildPlaywrightReportTag","undefined","generatedFilename","getReportFileName","fileName","join","getMidsceneRunSubDir","mkdirSync","reportFilePath","targetPath","resolve","isDirectoryModeReport","targetDir","dirname","cpSync","copyFileSync","removeReportArtifact","error","logMsg","tool","targetName","test","result","reportAnnotations","annotation","retry","projectName","projectSuffix","reports","existsSync","ReportMergingTool","reportCount","entry","report","firstReport","Array","printReportMsg","mergedReportPath","reportPath","config","_suite","_test","_result","options","Map"],"mappings":";;;;;;;;;;;;;;;;;AAyBA,MAAMA;IAmBJ,OAAe,QAAQC,YAAoB,EAAyB;QAClE,IAAI,CAACA,cACH,OAAO;QAET,IAAIA,AAAiB,aAAjBA,gBAA6BA,AAAiB,eAAjBA,cAC/B,MAAM,IAAIC,MACR,CAAC,4CAA4C,EAAED,aAAa,qCAAqC,CAAC;QAGtG,OAAOA;IACT;IAEQ,qBAAqBE,SAAiB,EAAEC,MAAc,EAAU;QACtE,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAACA,SAAS;YACtC,MAAMC,UAAUC,yBAAyBH,WAAWI,QAAWH;YAC/D,MAAMI,oBAAoBC,kBAAkBJ;YAC5C,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAACD,QAAQI;QACpC;QACA,OAAO,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAACJ;IACnC;IAEQ,kBAAkBD,SAAkB,EAAEC,MAAe,EAAU;QACrE,IAAI,AAAc,aAAd,IAAI,CAAC,IAAI,EAAe;YAC1B,IAAI,CAAC,IAAI,CAAC,cAAc,EACtB,IAAI,CAAC,cAAc,GAAGK,kBAAkB;YAE1C,OAAO,IAAI,CAAC,cAAc;QAC5B;QACA,IAAI,AAAc,eAAd,IAAI,CAAC,IAAI,EAAiB;YAC5B,IAAI,CAACN,WAAW,MAAM,IAAID,MAAM;YAChC,IAAI,CAACE,QAAQ,MAAM,IAAIF,MAAM;YAC7B,OAAO,IAAI,CAAC,oBAAoB,CAACC,WAAWC;QAC9C;QACA,MAAM,IAAIF,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IAEA,MAAM,QAAQC,MAAkB,EAAEC,MAAa,EAAE;QAC/C,IAAI,CAAC,mBAAmB,GAAID,AAAAA,CAAAA,OAAO,QAAQ,EAAE,UAAU,KAAK;IAC9D;IAEA,YAAYE,KAAe,EAAEC,OAAmB,EAAE,CAAC;IAEnD,UAAUrB,IAAc,EAAEC,MAAkB,EAAE;QAC5C,IAAI,CAAC,iBAAiB,CAACD,MAAMC;IAC/B;IAEA,MAAM,QAAQ;QACZ,IAAI,AAAc,aAAd,IAAI,CAAC,IAAI,EAAe,YAC1B,IAAI,CAAC,oBAAoB;QAI3B,IAAI,AAAc,eAAd,IAAI,CAAC,IAAI,EACX,IAAI,CAAC,uBAAuB;IAEhC;IA5OA,YAAYqB,UAAmC,CAAC,CAAC,CAAE;QAbnD,uBAAQ,kBAAR;QACA,uBAAQ,oBAAmB,IAAIC;QAC/B,uBAAQ,mBAAkB,IAAIA;QAO9B;QACA;QACA,uBAAQ,uBAAsB;QAG5B,IAAI,CAAC,IAAI,GAAGlD,iBAAiB,OAAO,CAACiD,QAAQ,IAAI,IAAI;QACrD,IAAI,CAAC,YAAY,GAAGA,QAAQ,YAAY,IAAI;IAC9C;AA0OF;AAEA,iBAAejD"}
|
|
1
|
+
{"version":3,"file":"playwright/reporter/index.mjs","sources":["../../../../src/playwright/reporter/index.ts"],"sourcesContent":["import { existsSync, mkdirSync } from 'node:fs';\nimport type { ReportFileWithAttributes, TestStatus } from '@midscene/core';\nimport { getReportFileName, printReportMsg } from '@midscene/core/agent';\nimport { ReportMergingTool } from '@midscene/core/report';\nimport { getMidsceneRunSubDir } from '@midscene/shared/common';\nimport { logMsg } from '@midscene/shared/utils';\nimport type {\n FullConfig,\n Reporter,\n Suite,\n TestCase,\n TestResult,\n} from '@playwright/test/reporter';\nimport { buildPlaywrightReportTag } from '../report-filename';\n\ninterface MidsceneReporterOptions {\n type?: 'merged' | 'separate';\n outputFormat?: 'single-html' | 'html-and-external-assets';\n}\n\nclass MidsceneReporter implements Reporter {\n private mergedFilename?: string;\n private testIdToFilename = new Map<string, string>();\n private reportsByTestId = new Map<\n string,\n {\n testTitle: string;\n reports: ReportFileWithAttributes[];\n }\n >();\n mode?: 'merged' | 'separate';\n outputFormat: 'single-html' | 'html-and-external-assets';\n private hasMultipleProjects = false;\n\n constructor(options: MidsceneReporterOptions = {}) {\n this.mode = MidsceneReporter.getMode(options.type ?? 'merged');\n this.outputFormat = options.outputFormat ?? 'single-html';\n }\n\n private static getMode(reporterType: string): 'merged' | 'separate' {\n if (!reporterType) {\n return 'merged';\n }\n if (reporterType !== 'merged' && reporterType !== 'separate') {\n throw new Error(\n `Unknown reporter type in playwright config: ${reporterType}, only support 'merged' or 'separate'`,\n );\n }\n return reporterType;\n }\n\n private getSeparatedFilename(testTitle: string, testId: string): string {\n if (!this.testIdToFilename.has(testId)) {\n const baseTag = buildPlaywrightReportTag(testTitle, undefined, testId);\n const generatedFilename = getReportFileName(baseTag);\n this.testIdToFilename.set(testId, generatedFilename);\n }\n return this.testIdToFilename.get(testId)!;\n }\n\n private getReportFilename(testTitle?: string, testId?: string): string {\n if (this.mode === 'merged') {\n if (!this.mergedFilename) {\n this.mergedFilename = getReportFileName('playwright-merged');\n }\n return this.mergedFilename;\n }\n if (this.mode === 'separate') {\n if (!testTitle) throw new Error('testTitle is required in separate mode');\n if (!testId) throw new Error('testId is required in separate mode');\n return this.getSeparatedFilename(testTitle, testId);\n }\n throw new Error(`Unknown mode: ${this.mode}`);\n }\n\n private ensureOutputRoot(): void {\n mkdirSync(getMidsceneRunSubDir('report'), { recursive: true });\n }\n\n private mergeOwnedReports(\n tool: ReportMergingTool,\n targetName: string,\n ): string | null {\n return tool.mergeReports(targetName, {\n overwrite: true,\n rmOriginalReports: true,\n outputFormat: this.outputFormat,\n });\n }\n\n private collectReportInfo(test: TestCase, result: TestResult) {\n const reportAnnotations = test.annotations.filter((annotation) => {\n return (\n annotation.type === 'MIDSCENE_DUMP_ANNOTATION' && annotation.description\n );\n });\n if (reportAnnotations.length === 0 || !this.mode) {\n return;\n }\n\n const retry = result.retry ? `(retry #${result.retry})` : '';\n const testId = `${test.id}${retry}`;\n const projectName = this.hasMultipleProjects\n ? test.parent?.project()?.name\n : undefined;\n const projectSuffix = projectName ? ` [${projectName}]` : '';\n const testTitle = `${test.title}${projectSuffix}${retry}`;\n const reports = reportAnnotations\n .map((annotation) => annotation.description!)\n .filter((reportFilePath) => {\n if (existsSync(reportFilePath)) {\n return true;\n }\n logMsg(\n `Failed to read Midscene report file: ${reportFilePath}`,\n new Error('Report file does not exist'),\n );\n return false;\n })\n .map((reportFilePath): ReportFileWithAttributes => {\n return {\n reportFilePath,\n reportAttributes: {\n testDuration: result.duration,\n testStatus: result.status as TestStatus,\n testTitle,\n testId,\n testDescription: test.parent?.title || '',\n },\n };\n });\n\n if (reports.length === 0) {\n return;\n }\n\n this.reportsByTestId.set(testId, {\n testTitle,\n reports,\n });\n }\n\n private finalizeMergedReport(): void {\n this.ensureOutputRoot();\n const tool = new ReportMergingTool();\n let reportCount = 0;\n for (const entry of this.reportsByTestId.values()) {\n for (const report of entry.reports) {\n tool.append(report);\n reportCount += 1;\n }\n }\n\n if (reportCount === 0) {\n return;\n }\n\n const targetName = this.getReportFilename();\n const mergedReportPath = this.mergeOwnedReports(tool, targetName);\n if (mergedReportPath) {\n printReportMsg(mergedReportPath);\n }\n }\n\n private finalizeSeparateReports(): void {\n this.ensureOutputRoot();\n for (const [testId, entry] of this.reportsByTestId) {\n const targetName = this.getReportFilename(entry.testTitle, testId);\n const tool = new ReportMergingTool();\n for (const report of entry.reports) {\n tool.append(report);\n }\n const reportPath = this.mergeOwnedReports(tool, targetName);\n if (reportPath) {\n printReportMsg(reportPath);\n }\n }\n }\n\n async onBegin(config: FullConfig, _suite: Suite) {\n this.hasMultipleProjects = (config.projects?.length || 0) > 1;\n }\n\n onTestBegin(_test: TestCase, _result: TestResult) {}\n\n onTestEnd(test: TestCase, result: TestResult) {\n this.collectReportInfo(test, result);\n }\n\n async onEnd() {\n if (this.mode === 'merged') {\n this.finalizeMergedReport();\n return;\n }\n\n if (this.mode === 'separate') {\n this.finalizeSeparateReports();\n }\n }\n}\n\nexport default MidsceneReporter;\n"],"names":["MidsceneReporter","reporterType","Error","testTitle","testId","baseTag","buildPlaywrightReportTag","undefined","generatedFilename","getReportFileName","mkdirSync","getMidsceneRunSubDir","tool","targetName","test","result","reportAnnotations","annotation","retry","projectName","projectSuffix","reports","reportFilePath","existsSync","logMsg","ReportMergingTool","reportCount","entry","report","mergedReportPath","printReportMsg","reportPath","config","_suite","_test","_result","options","Map"],"mappings":";;;;;;;;;;;;;;;;AAoBA,MAAMA;IAmBJ,OAAe,QAAQC,YAAoB,EAAyB;QAClE,IAAI,CAACA,cACH,OAAO;QAET,IAAIA,AAAiB,aAAjBA,gBAA6BA,AAAiB,eAAjBA,cAC/B,MAAM,IAAIC,MACR,CAAC,4CAA4C,EAAED,aAAa,qCAAqC,CAAC;QAGtG,OAAOA;IACT;IAEQ,qBAAqBE,SAAiB,EAAEC,MAAc,EAAU;QACtE,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAACA,SAAS;YACtC,MAAMC,UAAUC,yBAAyBH,WAAWI,QAAWH;YAC/D,MAAMI,oBAAoBC,kBAAkBJ;YAC5C,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAACD,QAAQI;QACpC;QACA,OAAO,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAACJ;IACnC;IAEQ,kBAAkBD,SAAkB,EAAEC,MAAe,EAAU;QACrE,IAAI,AAAc,aAAd,IAAI,CAAC,IAAI,EAAe;YAC1B,IAAI,CAAC,IAAI,CAAC,cAAc,EACtB,IAAI,CAAC,cAAc,GAAGK,kBAAkB;YAE1C,OAAO,IAAI,CAAC,cAAc;QAC5B;QACA,IAAI,AAAc,eAAd,IAAI,CAAC,IAAI,EAAiB;YAC5B,IAAI,CAACN,WAAW,MAAM,IAAID,MAAM;YAChC,IAAI,CAACE,QAAQ,M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AAC,iBAAiB,CAACD,MAAMC;IAC/B;IAEA,MAAM,QAAQ;QACZ,IAAI,AAAc,aAAd,IAAI,CAAC,IAAI,EAAe,YAC1B,IAAI,CAAC,oBAAoB;QAI3B,IAAI,AAAc,eAAd,IAAI,CAAC,IAAI,EACX,IAAI,CAAC,uBAAuB;IAEhC;IApKA,YAAYqB,UAAmC,CAAC,CAAC,CAAE;QAbnD,uBAAQ,kBAAR;QACA,uBAAQ,oBAAmB,IAAIC;QAC/B,uBAAQ,mBAAkB,IAAIA;QAO9B;QACA;QACA,uBAAQ,uBAAsB;QAG5B,IAAI,CAAC,IAAI,GAAGrC,iBAAiB,OAAO,CAACoC,QAAQ,IAAI,IAAI;QACrD,IAAI,CAAC,YAAY,GAAGA,QAAQ,YAAY,IAAI;IAC9C;AAkKF;AAEA,iBAAepC"}
|
|
@@ -130,7 +130,7 @@ class BridgeServer {
|
|
|
130
130
|
(0, shared_utils_namespaceObject.logMsg)('one client connected');
|
|
131
131
|
this.socket = socket;
|
|
132
132
|
const clientVersion = socket.handshake.query.version;
|
|
133
|
-
(0, shared_utils_namespaceObject.logMsg)(`Bridge connected, cli-side version v1.17.
|
|
133
|
+
(0, shared_utils_namespaceObject.logMsg)(`Bridge connected, cli-side version v1.17.5, browser-side version v${clientVersion}`);
|
|
134
134
|
socket.on(external_common_js_namespaceObject.BridgeEvent.CallResponse, (params)=>{
|
|
135
135
|
const id = params.id;
|
|
136
136
|
const response = params.response;
|
|
@@ -154,7 +154,7 @@ class BridgeServer {
|
|
|
154
154
|
setTimeout(()=>{
|
|
155
155
|
this.onConnect?.();
|
|
156
156
|
const payload = {
|
|
157
|
-
version: "1.17.
|
|
157
|
+
version: "1.17.5"
|
|
158
158
|
};
|
|
159
159
|
socket.emit(external_common_js_namespaceObject.BridgeEvent.Connected, payload);
|
|
160
160
|
Promise.resolve().then(()=>{
|
|
@@ -138,7 +138,7 @@ class ExtensionBridgePageBrowserSide extends page_js_default() {
|
|
|
138
138
|
throw new Error('Connection denied by user');
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
-
this.onLogMessage(`Bridge connected, cli-side version v${this.bridgeClient.serverVersion}, browser-side version v1.17.
|
|
141
|
+
this.onLogMessage(`Bridge connected, cli-side version v${this.bridgeClient.serverVersion}, browser-side version v1.17.5`, 'log');
|
|
142
142
|
}
|
|
143
143
|
async connect() {
|
|
144
144
|
return await this.setupBridgeClient();
|
package/dist/lib/cli.js
CHANGED
|
@@ -42,7 +42,7 @@ Promise.resolve().then(()=>{
|
|
|
42
42
|
return (0, cli_namespaceObject.runToolsCLI)(tools, 'midscene-web', {
|
|
43
43
|
stripPrefix: 'web_',
|
|
44
44
|
argv: parsedOptions.argv,
|
|
45
|
-
version: "1.17.
|
|
45
|
+
version: "1.17.5",
|
|
46
46
|
extraCommands: (0, core_namespaceObject.createReportCliCommands)()
|
|
47
47
|
});
|
|
48
48
|
}).catch((e)=>{
|
|
@@ -27,7 +27,6 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
27
27
|
default: ()=>reporter
|
|
28
28
|
});
|
|
29
29
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
30
|
-
const external_node_path_namespaceObject = require("node:path");
|
|
31
30
|
const agent_namespaceObject = require("@midscene/core/agent");
|
|
32
31
|
const report_namespaceObject = require("@midscene/core/report");
|
|
33
32
|
const common_namespaceObject = require("@midscene/shared/common");
|
|
@@ -69,43 +68,16 @@ class MidsceneReporter {
|
|
|
69
68
|
}
|
|
70
69
|
throw new Error(`Unknown mode: ${this.mode}`);
|
|
71
70
|
}
|
|
72
|
-
getReportPath(testTitle, testId) {
|
|
73
|
-
const fileName = this.getReportFilename(testTitle, testId);
|
|
74
|
-
if ('html-and-external-assets' === this.outputFormat) return (0, external_node_path_namespaceObject.join)((0, common_namespaceObject.getMidsceneRunSubDir)('report'), fileName, 'index.html');
|
|
75
|
-
return (0, external_node_path_namespaceObject.join)((0, common_namespaceObject.getMidsceneRunSubDir)('report'), `${fileName}.html`);
|
|
76
|
-
}
|
|
77
71
|
ensureOutputRoot() {
|
|
78
72
|
(0, external_node_fs_namespaceObject.mkdirSync)((0, common_namespaceObject.getMidsceneRunSubDir)('report'), {
|
|
79
73
|
recursive: true
|
|
80
74
|
});
|
|
81
75
|
}
|
|
82
|
-
finalizeSingleReport(reportFilePath, targetPath) {
|
|
83
|
-
if ((0, external_node_path_namespaceObject.resolve)(reportFilePath) === (0, external_node_path_namespaceObject.resolve)(targetPath)) return;
|
|
84
|
-
if ((0, report_namespaceObject.isDirectoryModeReport)(reportFilePath)) {
|
|
85
|
-
const targetDir = (0, external_node_path_namespaceObject.dirname)(targetPath);
|
|
86
|
-
(0, external_node_fs_namespaceObject.mkdirSync)(targetDir, {
|
|
87
|
-
recursive: true
|
|
88
|
-
});
|
|
89
|
-
(0, external_node_fs_namespaceObject.cpSync)((0, external_node_path_namespaceObject.dirname)(reportFilePath), targetDir, {
|
|
90
|
-
recursive: true,
|
|
91
|
-
force: true
|
|
92
|
-
});
|
|
93
|
-
} else {
|
|
94
|
-
(0, external_node_fs_namespaceObject.mkdirSync)((0, external_node_path_namespaceObject.dirname)(targetPath), {
|
|
95
|
-
recursive: true
|
|
96
|
-
});
|
|
97
|
-
(0, external_node_fs_namespaceObject.copyFileSync)(reportFilePath, targetPath);
|
|
98
|
-
}
|
|
99
|
-
try {
|
|
100
|
-
(0, report_namespaceObject.removeReportArtifact)(reportFilePath);
|
|
101
|
-
} catch (error) {
|
|
102
|
-
(0, utils_namespaceObject.logMsg)(`Error deleting report ${reportFilePath}: ${error}`);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
76
|
mergeOwnedReports(tool, targetName) {
|
|
106
77
|
return tool.mergeReports(targetName, {
|
|
107
78
|
overwrite: true,
|
|
108
|
-
rmOriginalReports: true
|
|
79
|
+
rmOriginalReports: true,
|
|
80
|
+
outputFormat: this.outputFormat
|
|
109
81
|
});
|
|
110
82
|
}
|
|
111
83
|
collectReportInfo(test, result) {
|
|
@@ -146,19 +118,6 @@ class MidsceneReporter {
|
|
|
146
118
|
}
|
|
147
119
|
if (0 === reportCount) return;
|
|
148
120
|
const targetName = this.getReportFilename();
|
|
149
|
-
if (1 === reportCount) {
|
|
150
|
-
const firstReport = Array.from(this.reportsByTestId.values())[0]?.reports[0];
|
|
151
|
-
if (!firstReport) return;
|
|
152
|
-
if (firstReport.reportFilePath) {
|
|
153
|
-
const targetPath = this.getReportPath();
|
|
154
|
-
this.finalizeSingleReport(firstReport.reportFilePath, targetPath);
|
|
155
|
-
(0, agent_namespaceObject.printReportMsg)(targetPath);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
const mergedReportPath = this.mergeOwnedReports(tool, targetName);
|
|
159
|
-
if (mergedReportPath) (0, agent_namespaceObject.printReportMsg)(mergedReportPath);
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
121
|
const mergedReportPath = this.mergeOwnedReports(tool, targetName);
|
|
163
122
|
if (mergedReportPath) (0, agent_namespaceObject.printReportMsg)(mergedReportPath);
|
|
164
123
|
}
|
|
@@ -166,20 +125,6 @@ class MidsceneReporter {
|
|
|
166
125
|
this.ensureOutputRoot();
|
|
167
126
|
for (const [testId, entry] of this.reportsByTestId){
|
|
168
127
|
const targetName = this.getReportFilename(entry.testTitle, testId);
|
|
169
|
-
if (1 === entry.reports.length) {
|
|
170
|
-
const firstReport = entry.reports[0];
|
|
171
|
-
if (firstReport.reportFilePath) {
|
|
172
|
-
const targetPath = this.getReportPath(entry.testTitle, testId);
|
|
173
|
-
this.finalizeSingleReport(firstReport.reportFilePath, targetPath);
|
|
174
|
-
(0, agent_namespaceObject.printReportMsg)(targetPath);
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
const tool = new report_namespaceObject.ReportMergingTool();
|
|
178
|
-
tool.append(firstReport);
|
|
179
|
-
const reportPath = this.mergeOwnedReports(tool, targetName);
|
|
180
|
-
if (reportPath) (0, agent_namespaceObject.printReportMsg)(reportPath);
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
128
|
const tool = new report_namespaceObject.ReportMergingTool();
|
|
184
129
|
for (const report of entry.reports)tool.append(report);
|
|
185
130
|
const reportPath = this.mergeOwnedReports(tool, targetName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playwright/reporter/index.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../../src/playwright/reporter/index.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { copyFileSync, cpSync, existsSync, mkdirSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\nimport type { ReportFileWithAttributes, TestStatus } from '@midscene/core';\nimport { getReportFileName, printReportMsg } from '@midscene/core/agent';\nimport {\n ReportMergingTool,\n isDirectoryModeReport,\n removeReportArtifact,\n} from '@midscene/core/report';\nimport { getMidsceneRunSubDir } from '@midscene/shared/common';\nimport { logMsg } from '@midscene/shared/utils';\nimport type {\n FullConfig,\n Reporter,\n Suite,\n TestCase,\n TestResult,\n} from '@playwright/test/reporter';\nimport { buildPlaywrightReportTag } from '../report-filename';\n\ninterface MidsceneReporterOptions {\n type?: 'merged' | 'separate';\n outputFormat?: 'single-html' | 'html-and-external-assets';\n}\n\nclass MidsceneReporter implements Reporter {\n private mergedFilename?: string;\n private testIdToFilename = new Map<string, string>();\n private reportsByTestId = new Map<\n string,\n {\n testTitle: string;\n reports: ReportFileWithAttributes[];\n }\n >();\n mode?: 'merged' | 'separate';\n outputFormat: 'single-html' | 'html-and-external-assets';\n private hasMultipleProjects = false;\n\n constructor(options: MidsceneReporterOptions = {}) {\n this.mode = MidsceneReporter.getMode(options.type ?? 'merged');\n this.outputFormat = options.outputFormat ?? 'single-html';\n }\n\n private static getMode(reporterType: string): 'merged' | 'separate' {\n if (!reporterType) {\n return 'merged';\n }\n if (reporterType !== 'merged' && reporterType !== 'separate') {\n throw new Error(\n `Unknown reporter type in playwright config: ${reporterType}, only support 'merged' or 'separate'`,\n );\n }\n return reporterType;\n }\n\n private getSeparatedFilename(testTitle: string, testId: string): string {\n if (!this.testIdToFilename.has(testId)) {\n const baseTag = buildPlaywrightReportTag(testTitle, undefined, testId);\n const generatedFilename = getReportFileName(baseTag);\n this.testIdToFilename.set(testId, generatedFilename);\n }\n return this.testIdToFilename.get(testId)!;\n }\n\n private getReportFilename(testTitle?: string, testId?: string): string {\n if (this.mode === 'merged') {\n if (!this.mergedFilename) {\n this.mergedFilename = getReportFileName('playwright-merged');\n }\n return this.mergedFilename;\n }\n if (this.mode === 'separate') {\n if (!testTitle) throw new Error('testTitle is required in separate mode');\n if (!testId) throw new Error('testId is required in separate mode');\n return this.getSeparatedFilename(testTitle, testId);\n }\n throw new Error(`Unknown mode: ${this.mode}`);\n }\n\n private getReportPath(testTitle?: string, testId?: string): string {\n const fileName = this.getReportFilename(testTitle, testId);\n if (this.outputFormat === 'html-and-external-assets') {\n return join(getMidsceneRunSubDir('report'), fileName, 'index.html');\n }\n return join(getMidsceneRunSubDir('report'), `${fileName}.html`);\n }\n\n private ensureOutputRoot(): void {\n mkdirSync(getMidsceneRunSubDir('report'), { recursive: true });\n }\n\n private finalizeSingleReport(\n reportFilePath: string,\n targetPath: string,\n ): void {\n if (resolve(reportFilePath) === resolve(targetPath)) {\n return;\n }\n\n if (isDirectoryModeReport(reportFilePath)) {\n const targetDir = dirname(targetPath);\n mkdirSync(targetDir, { recursive: true });\n cpSync(dirname(reportFilePath), targetDir, {\n recursive: true,\n force: true,\n });\n } else {\n mkdirSync(dirname(targetPath), { recursive: true });\n copyFileSync(reportFilePath, targetPath);\n }\n\n try {\n removeReportArtifact(reportFilePath);\n } catch (error) {\n logMsg(`Error deleting report ${reportFilePath}: ${error}`);\n }\n }\n\n private mergeOwnedReports(\n tool: ReportMergingTool,\n targetName: string,\n ): string | null {\n return tool.mergeReports(targetName, {\n overwrite: true,\n rmOriginalReports: true,\n });\n }\n\n private collectReportInfo(test: TestCase, result: TestResult) {\n const reportAnnotations = test.annotations.filter((annotation) => {\n return (\n annotation.type === 'MIDSCENE_DUMP_ANNOTATION' && annotation.description\n );\n });\n if (reportAnnotations.length === 0 || !this.mode) {\n return;\n }\n\n const retry = result.retry ? `(retry #${result.retry})` : '';\n const testId = `${test.id}${retry}`;\n const projectName = this.hasMultipleProjects\n ? test.parent?.project()?.name\n : undefined;\n const projectSuffix = projectName ? ` [${projectName}]` : '';\n const testTitle = `${test.title}${projectSuffix}${retry}`;\n const reports = reportAnnotations\n .map((annotation) => annotation.description!)\n .filter((reportFilePath) => {\n if (existsSync(reportFilePath)) {\n return true;\n }\n logMsg(\n `Failed to read Midscene report file: ${reportFilePath}`,\n new Error('Report file does not exist'),\n );\n return false;\n })\n .map((reportFilePath): ReportFileWithAttributes => {\n return {\n reportFilePath,\n reportAttributes: {\n testDuration: result.duration,\n testStatus: result.status as TestStatus,\n testTitle,\n testId,\n testDescription: test.parent?.title || '',\n },\n };\n });\n\n if (reports.length === 0) {\n return;\n }\n\n this.reportsByTestId.set(testId, {\n testTitle,\n reports,\n });\n }\n\n private finalizeMergedReport(): void {\n this.ensureOutputRoot();\n const tool = new ReportMergingTool();\n let reportCount = 0;\n for (const entry of this.reportsByTestId.values()) {\n for (const report of entry.reports) {\n tool.append(report);\n reportCount += 1;\n }\n }\n\n if (reportCount === 0) {\n return;\n }\n\n const targetName = this.getReportFilename();\n if (reportCount === 1) {\n const firstReport = Array.from(this.reportsByTestId.values())[0]\n ?.reports[0];\n if (!firstReport) {\n return;\n }\n if (firstReport.reportFilePath) {\n const targetPath = this.getReportPath();\n this.finalizeSingleReport(firstReport.reportFilePath, targetPath);\n printReportMsg(targetPath);\n return;\n }\n\n const mergedReportPath = this.mergeOwnedReports(tool, targetName);\n if (mergedReportPath) {\n printReportMsg(mergedReportPath);\n }\n return;\n }\n\n const mergedReportPath = this.mergeOwnedReports(tool, targetName);\n if (mergedReportPath) {\n printReportMsg(mergedReportPath);\n }\n }\n\n private finalizeSeparateReports(): void {\n this.ensureOutputRoot();\n for (const [testId, entry] of this.reportsByTestId) {\n const targetName = this.getReportFilename(entry.testTitle, testId);\n if (entry.reports.length === 1) {\n const firstReport = entry.reports[0];\n if (firstReport.reportFilePath) {\n const targetPath = this.getReportPath(entry.testTitle, testId);\n this.finalizeSingleReport(firstReport.reportFilePath, targetPath);\n printReportMsg(targetPath);\n continue;\n }\n\n const tool = new ReportMergingTool();\n tool.append(firstReport);\n const reportPath = this.mergeOwnedReports(tool, targetName);\n if (reportPath) {\n printReportMsg(reportPath);\n }\n continue;\n }\n\n const tool = new ReportMergingTool();\n for (const report of entry.reports) {\n tool.append(report);\n }\n const reportPath = this.mergeOwnedReports(tool, targetName);\n if (reportPath) {\n printReportMsg(reportPath);\n }\n }\n }\n\n async onBegin(config: FullConfig, _suite: Suite) {\n this.hasMultipleProjects = (config.projects?.length || 0) > 1;\n }\n\n onTestBegin(_test: TestCase, _result: TestResult) {}\n\n onTestEnd(test: TestCase, result: TestResult) {\n this.collectReportInfo(test, result);\n }\n\n async onEnd() {\n if (this.mode === 'merged') {\n this.finalizeMergedReport();\n return;\n }\n\n if (this.mode === 'separate') {\n this.finalizeSeparateReports();\n }\n }\n}\n\nexport default MidsceneReporter;\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","MidsceneReporter","reporterType","Error","testTitle","testId","baseTag","buildPlaywrightReportTag","undefined","generatedFilename","getReportFileName","fileName","join","getMidsceneRunSubDir","mkdirSync","reportFilePath","targetPath","resolve","isDirectoryModeReport","targetDir","dirname","cpSync","copyFileSync","removeReportArtifact","error","logMsg","tool","targetName","test","result","reportAnnotations","annotation","retry","projectName","projectSuffix","reports","existsSync","ReportMergingTool","reportCount","entry","report","firstReport","Array","printReportMsg","mergedReportPath","reportPath","config","_suite","_test","_result","options","Map"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;;;;;;;;;;;;;;;;ACmBA,MAAMI;IAmBJ,OAAe,QAAQC,YAAoB,EAAyB;QAClE,IAAI,CAACA,cACH,OAAO;QAET,IAAIA,AAAiB,aAAjBA,gBAA6BA,AAAiB,eAAjBA,cAC/B,MAAM,IAAIC,MACR,CAAC,4CAA4C,EAAED,aAAa,qCAAqC,CAAC;QAGtG,OAAOA;IACT;IAEQ,qBAAqBE,SAAiB,EAAEC,MAAc,EAAU;QACtE,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAACA,SAAS;YACtC,MAAMC,UAAUC,AAAAA,IAAAA,4CAAAA,wBAAAA,AAAAA,EAAyBH,WAAWI,QAAWH;YAC/D,MAAMI,oBAAoBC,AAAAA,IAAAA,sBAAAA,i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AAIkB,YACFF,AAAAA,IAAAA,sBAAAA,cAAAA,AAAAA,EAAeE;gBAEjB;YACF;YAEA,MAAMnB,OAAO,IAAIW,uBAAAA,iBAAiBA;YAClC,KAAK,MAAMG,UAAUD,MAAM,OAAO,CAChCb,KAAK,MAAM,CAACc;YAEd,MAAMK,aAAa,IAAI,CAAC,iBAAiB,CAACnB,MAAMC;YAChD,IAAIkB,YACFF,AAAAA,IAAAA,sBAAAA,cAAAA,AAAAA,EAAeE;QAEnB;IACF;IAEA,MAAM,QAAQC,MAAkB,EAAEC,MAAa,EAAE;QAC/C,IAAI,CAAC,mBAAmB,GAAID,AAAAA,CAAAA,OAAO,QAAQ,EAAE,UAAU,KAAK;IAC9D;IAEA,YAAYE,KAAe,EAAEC,OAAmB,EAAE,CAAC;IAEnD,UAAUrB,IAAc,EAAEC,MAAkB,EAAE;QAC5C,IAAI,CAAC,iBAAiB,CAACD,MAAMC;IAC/B;IAEA,MAAM,QAAQ;QACZ,IAAI,AAAc,aAAd,IAAI,CAAC,IAAI,EAAe,YAC1B,IAAI,CAAC,oBAAoB;QAI3B,IAAI,AAAc,eAAd,IAAI,CAAC,IAAI,EACX,IAAI,CAAC,uBAAuB;IAEhC;IA5OA,YAAYqB,UAAmC,CAAC,CAAC,CAAE;QAbnD,uBAAQ,kBAAR;QACA,uBAAQ,oBAAmB,IAAIC;QAC/B,uBAAQ,mBAAkB,IAAIA;QAO9B;QACA;QACA,uBAAQ,uBAAsB;QAG5B,IAAI,CAAC,IAAI,GAAGlD,iBAAiB,OAAO,CAACiD,QAAQ,IAAI,IAAI;QACrD,IAAI,CAAC,YAAY,GAAGA,QAAQ,YAAY,IAAI;IAC9C;AA0OF;AAEA,iBAAejD"}
|
|
1
|
+
{"version":3,"file":"playwright/reporter/index.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../../src/playwright/reporter/index.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { existsSync, mkdirSync } from 'node:fs';\nimport type { ReportFileWithAttributes, TestStatus } from '@midscene/core';\nimport { getReportFileName, printReportMsg } from '@midscene/core/agent';\nimport { ReportMergingTool } from '@midscene/core/report';\nimport { getMidsceneRunSubDir } from '@midscene/shared/common';\nimport { logMsg } from '@midscene/shared/utils';\nimport type {\n FullConfig,\n Reporter,\n Suite,\n TestCase,\n TestResult,\n} from '@playwright/test/reporter';\nimport { buildPlaywrightReportTag } from '../report-filename';\n\ninterface MidsceneReporterOptions {\n type?: 'merged' | 'separate';\n outputFormat?: 'single-html' | 'html-and-external-assets';\n}\n\nclass MidsceneReporter implements Reporter {\n private mergedFilename?: string;\n private testIdToFilename = new Map<string, string>();\n private reportsByTestId = new Map<\n string,\n {\n testTitle: string;\n reports: ReportFileWithAttributes[];\n }\n >();\n mode?: 'merged' | 'separate';\n outputFormat: 'single-html' | 'html-and-external-assets';\n private hasMultipleProjects = false;\n\n constructor(options: MidsceneReporterOptions = {}) {\n this.mode = MidsceneReporter.getMode(options.type ?? 'merged');\n this.outputFormat = options.outputFormat ?? 'single-html';\n }\n\n private static getMode(reporterType: string): 'merged' | 'separate' {\n if (!reporterType) {\n return 'merged';\n }\n if (reporterType !== 'merged' && reporterType !== 'separate') {\n throw new Error(\n `Unknown reporter type in playwright config: ${reporterType}, only support 'merged' or 'separate'`,\n );\n }\n return reporterType;\n }\n\n private getSeparatedFilename(testTitle: string, testId: string): string {\n if (!this.testIdToFilename.has(testId)) {\n const baseTag = buildPlaywrightReportTag(testTitle, undefined, testId);\n const generatedFilename = getReportFileName(baseTag);\n this.testIdToFilename.set(testId, generatedFilename);\n }\n return this.testIdToFilename.get(testId)!;\n }\n\n private getReportFilename(testTitle?: string, testId?: string): string {\n if (this.mode === 'merged') {\n if (!this.mergedFilename) {\n this.mergedFilename = getReportFileName('playwright-merged');\n }\n return this.mergedFilename;\n }\n if (this.mode === 'separate') {\n if (!testTitle) throw new Error('testTitle is required in separate mode');\n if (!testId) throw new Error('testId is required in separate mode');\n return this.getSeparatedFilename(testTitle, testId);\n }\n throw new Error(`Unknown mode: ${this.mode}`);\n }\n\n private ensureOutputRoot(): void {\n mkdirSync(getMidsceneRunSubDir('report'), { recursive: true });\n }\n\n private mergeOwnedReports(\n tool: ReportMergingTool,\n targetName: string,\n ): string | null {\n return tool.mergeReports(targetName, {\n overwrite: true,\n rmOriginalReports: true,\n outputFormat: this.outputFormat,\n });\n }\n\n private collectReportInfo(test: TestCase, result: TestResult) {\n const reportAnnotations = test.annotations.filter((annotation) => {\n return (\n annotation.type === 'MIDSCENE_DUMP_ANNOTATION' && annotation.description\n );\n });\n if (reportAnnotations.length === 0 || !this.mode) {\n return;\n }\n\n const retry = result.retry ? `(retry #${result.retry})` : '';\n const testId = `${test.id}${retry}`;\n const projectName = this.hasMultipleProjects\n ? test.parent?.project()?.name\n : undefined;\n const projectSuffix = projectName ? ` [${projectName}]` : '';\n const testTitle = `${test.title}${projectSuffix}${retry}`;\n const reports = reportAnnotations\n .map((annotation) => annotation.description!)\n .filter((reportFilePath) => {\n if (existsSync(reportFilePath)) {\n return true;\n }\n logMsg(\n `Failed to read Midscene report file: ${reportFilePath}`,\n new Error('Report file does not exist'),\n );\n return false;\n })\n .map((reportFilePath): ReportFileWithAttributes => {\n return {\n reportFilePath,\n reportAttributes: {\n testDuration: result.duration,\n testStatus: result.status as TestStatus,\n testTitle,\n testId,\n testDescription: test.parent?.title || '',\n },\n };\n });\n\n if (reports.length === 0) {\n return;\n }\n\n this.reportsByTestId.set(testId, {\n testTitle,\n reports,\n });\n }\n\n private finalizeMergedReport(): void {\n this.ensureOutputRoot();\n const tool = new ReportMergingTool();\n let reportCount = 0;\n for (const entry of this.reportsByTestId.values()) {\n for (const report of entry.reports) {\n tool.append(report);\n reportCount += 1;\n }\n }\n\n if (reportCount === 0) {\n return;\n }\n\n const targetName = this.getReportFilename();\n const mergedReportPath = this.mergeOwnedReports(tool, targetName);\n if (mergedReportPath) {\n printReportMsg(mergedReportPath);\n }\n }\n\n private finalizeSeparateReports(): void {\n this.ensureOutputRoot();\n for (const [testId, entry] of this.reportsByTestId) {\n const targetName = this.getReportFilename(entry.testTitle, testId);\n const tool = new ReportMergingTool();\n for (const report of entry.reports) {\n tool.append(report);\n }\n const reportPath = this.mergeOwnedReports(tool, targetName);\n if (reportPath) {\n printReportMsg(reportPath);\n }\n }\n }\n\n async onBegin(config: FullConfig, _suite: Suite) {\n this.hasMultipleProjects = (config.projects?.length || 0) > 1;\n }\n\n onTestBegin(_test: TestCase, _result: TestResult) {}\n\n onTestEnd(test: TestCase, result: TestResult) {\n this.collectReportInfo(test, result);\n }\n\n async onEnd() {\n if (this.mode === 'merged') {\n this.finalizeMergedReport();\n return;\n }\n\n if (this.mode === 'separate') {\n this.finalizeSeparateReports();\n }\n }\n}\n\nexport default MidsceneReporter;\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","MidsceneReporter","reporterType","Error","testTitle","testId","baseTag","buildPlaywrightReportTag","undefined","generatedFilename","getReportFileName","mkdirSync","getMidsceneRunSubDir","tool","targetName","test","result","reportAnnotations","annotation","retry","projectName","projectSuffix","reports","reportFilePath","existsSync","logMsg","ReportMergingTool","reportCount","entry","report","mergedReportPath","printReportMsg","reportPath","config","_suite","_test","_result","options","Map"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ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A,iBAAiBA;YAClC,KAAK,MAAMG,UAAUD,MAAM,OAAO,CAChCf,KAAK,MAAM,CAACgB;YAEd,MAAMG,aAAa,IAAI,CAAC,iBAAiB,CAACnB,MAAMC;YAChD,IAAIkB,YACFD,AAAAA,IAAAA,sBAAAA,cAAAA,AAAAA,EAAeC;QAEnB;IACF;IAEA,MAAM,QAAQC,MAAkB,EAAEC,MAAa,EAAE;QAC/C,IAAI,CAAC,mBAAmB,GAAID,AAAAA,CAAAA,OAAO,QAAQ,EAAE,UAAU,KAAK;IAC9D;IAEA,YAAYE,KAAe,EAAEC,OAAmB,EAAE,CAAC;IAEnD,UAAUrB,IAAc,EAAEC,MAAkB,EAAE;QAC5C,IAAI,CAAC,iBAAiB,CAACD,MAAMC;IAC/B;IAEA,MAAM,QAAQ;QACZ,IAAI,AAAc,aAAd,IAAI,CAAC,IAAI,EAAe,YAC1B,IAAI,CAAC,oBAAoB;QAI3B,IAAI,AAAc,eAAd,IAAI,CAAC,IAAI,EACX,IAAI,CAAC,uBAAuB;IAEhC;IApKA,YAAYqB,UAAmC,CAAC,CAAC,CAAE;QAbnD,uBAAQ,kBAAR;QACA,uBAAQ,oBAAmB,IAAIC;QAC/B,uBAAQ,mBAAkB,IAAIA;QAO9B;QACA;QACA,uBAAQ,uBAAsB;QAG5B,IAAI,CAAC,IAAI,GAAGrC,iBAAiB,OAAO,CAACoC,QAAQ,IAAI,IAAI;QACrD,IAAI,CAAC,YAAY,GAAGA,QAAQ,YAAY,IAAI;IAC9C;AAkKF;AAEA,iBAAepC"}
|
|
@@ -14,9 +14,7 @@ declare class MidsceneReporter implements Reporter {
|
|
|
14
14
|
private static getMode;
|
|
15
15
|
private getSeparatedFilename;
|
|
16
16
|
private getReportFilename;
|
|
17
|
-
private getReportPath;
|
|
18
17
|
private ensureOutputRoot;
|
|
19
|
-
private finalizeSingleReport;
|
|
20
18
|
private mergeOwnedReports;
|
|
21
19
|
private collectReportInfo;
|
|
22
20
|
private finalizeMergedReport;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/playwright/reporter/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/playwright/reporter/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,UAAU,EACX,MAAM,2BAA2B,CAAC;AAGnC,UAAU,uBAAuB;IAC/B,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC;IAC7B,YAAY,CAAC,EAAE,aAAa,GAAG,0BAA0B,CAAC;CAC3D;AAED,cAAM,gBAAiB,YAAW,QAAQ;IACxC,OAAO,CAAC,cAAc,CAAC,CAAS;IAChC,OAAO,CAAC,gBAAgB,CAA6B;IACrD,OAAO,CAAC,eAAe,CAMnB;IACJ,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC;IAC7B,YAAY,EAAE,aAAa,GAAG,0BAA0B,CAAC;IACzD,OAAO,CAAC,mBAAmB,CAAS;gBAExB,OAAO,GAAE,uBAA4B;IAKjD,OAAO,CAAC,MAAM,CAAC,OAAO;IAYtB,OAAO,CAAC,oBAAoB;IAS5B,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,iBAAiB;IAWzB,OAAO,CAAC,iBAAiB;IAoDzB,OAAO,CAAC,oBAAoB;IAsB5B,OAAO,CAAC,uBAAuB;IAezB,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK;IAI/C,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU;IAEhD,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU;IAItC,KAAK;CAUZ;AAED,eAAe,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"Browser use",
|
|
9
9
|
"Android use"
|
|
10
10
|
],
|
|
11
|
-
"version": "1.17.
|
|
11
|
+
"version": "1.17.5",
|
|
12
12
|
"repository": "https://github.com/web-infra-dev/midscene",
|
|
13
13
|
"homepage": "https://midscenejs.com/",
|
|
14
14
|
"main": "./dist/lib/index.js",
|
|
@@ -122,9 +122,9 @@
|
|
|
122
122
|
"socket.io-client": "4.8.1",
|
|
123
123
|
"ws": "^8.18.1",
|
|
124
124
|
"zod": "^3.25.1",
|
|
125
|
-
"@midscene/
|
|
126
|
-
"@midscene/
|
|
127
|
-
"@midscene/
|
|
125
|
+
"@midscene/core": "1.17.5",
|
|
126
|
+
"@midscene/playground": "1.17.5",
|
|
127
|
+
"@midscene/shared": "1.17.5"
|
|
128
128
|
},
|
|
129
129
|
"devDependencies": {
|
|
130
130
|
"@playwright/test": "^1.45.0",
|