@midscene/core 0.16.9 → 0.16.10
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/chunk-QIM376LA.js +263 -0
- package/dist/es/index.js +1 -1
- package/dist/es/utils.js +1 -1
- package/dist/lib/chunk-QIM376LA.js +263 -0
- package/dist/lib/index.js +4 -4
- package/dist/lib/utils.js +2 -2
- package/package.json +2 -2
- package/dist/es/chunk-KINAY5TJ.js +0 -263
- package/dist/lib/chunk-KINAY5TJ.js +0 -263
- /package/dist/es/{chunk-KINAY5TJ.js.map → chunk-QIM376LA.js.map} +0 -0
- /package/dist/lib/{chunk-KINAY5TJ.js.map → chunk-QIM376LA.js.map} +0 -0
package/dist/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkQIM376LAjs = require('./chunk-QIM376LA.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -156,7 +156,7 @@ ${_optionalChain([this, 'access', _7 => _7.latestErrorTask, 'call', _8 => _8(),
|
|
|
156
156
|
}
|
|
157
157
|
dump() {
|
|
158
158
|
const dumpData = {
|
|
159
|
-
sdkVersion:
|
|
159
|
+
sdkVersion: _chunkQIM376LAjs.getVersion.call(void 0, ),
|
|
160
160
|
model_name: _env.getAIConfig.call(void 0, _env.MIDSCENE_MODEL_NAME) || "",
|
|
161
161
|
logTime: Date.now(),
|
|
162
162
|
name: this.name,
|
|
@@ -194,7 +194,7 @@ function emitInsightDump(data, dumpSubscriber) {
|
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
const baseData = {
|
|
197
|
-
sdkVersion:
|
|
197
|
+
sdkVersion: _chunkQIM376LAjs.getVersion.call(void 0, ),
|
|
198
198
|
logTime: Date.now(),
|
|
199
199
|
model_name: _env.getAIConfig.call(void 0, _env.MIDSCENE_MODEL_NAME) || "",
|
|
200
200
|
model_description: modelDescription
|
|
@@ -455,6 +455,6 @@ var src_default = Insight;
|
|
|
455
455
|
|
|
456
456
|
|
|
457
457
|
|
|
458
|
-
exports.AiAssert = _chunkFYD4T7QDjs.AiAssert; exports.AiLocateElement = _chunkFYD4T7QDjs.AiLocateElement; exports.Executor = Executor; exports.Insight = Insight; exports.MIDSCENE_MODEL_NAME = _env.MIDSCENE_MODEL_NAME; exports.default = src_default; exports.describeUserPage = _chunkFYD4T7QDjs.describeUserPage; exports.getAIConfig = _env.getAIConfig; exports.getVersion =
|
|
458
|
+
exports.AiAssert = _chunkFYD4T7QDjs.AiAssert; exports.AiLocateElement = _chunkFYD4T7QDjs.AiLocateElement; exports.Executor = Executor; exports.Insight = Insight; exports.MIDSCENE_MODEL_NAME = _env.MIDSCENE_MODEL_NAME; exports.default = src_default; exports.describeUserPage = _chunkFYD4T7QDjs.describeUserPage; exports.getAIConfig = _env.getAIConfig; exports.getVersion = _chunkQIM376LAjs.getVersion; exports.plan = _chunkFYD4T7QDjs.plan;
|
|
459
459
|
|
|
460
460
|
//# sourceMappingURL=index.js.map
|
package/dist/lib/utils.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _chunkQIM376LAjs = require('./chunk-QIM376LA.js');
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
|
|
@@ -29,4 +29,4 @@ var _chunkKINAY5TJjs = require('./chunk-KINAY5TJ.js');
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
exports.getLogDir =
|
|
32
|
+
exports.getLogDir = _chunkQIM376LAjs.getLogDir; exports.getTmpDir = _chunkQIM376LAjs.getTmpDir; exports.getTmpFile = _chunkQIM376LAjs.getTmpFile; exports.getVersion = _chunkQIM376LAjs.getVersion; exports.groupedActionDumpFileExt = _chunkQIM376LAjs.groupedActionDumpFileExt; exports.overlapped = _chunkQIM376LAjs.overlapped; exports.replaceStringWithFirstAppearance = _chunkQIM376LAjs.replaceStringWithFirstAppearance; exports.replacerForPageObject = _chunkQIM376LAjs.replacerForPageObject; exports.reportHTMLContent = _chunkQIM376LAjs.reportHTMLContent; exports.sleep = _chunkQIM376LAjs.sleep; exports.stringifyDumpData = _chunkQIM376LAjs.stringifyDumpData; exports.uploadTestInfoToServer = _chunkQIM376LAjs.uploadTestInfoToServer; exports.writeDumpReport = _chunkQIM376LAjs.writeDumpReport; exports.writeLogFile = _chunkQIM376LAjs.writeLogFile;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/core",
|
|
3
3
|
"description": "Automate browser actions, extract data, and perform assertions using AI. It offers JavaScript SDK, Chrome extension, and support for scripting in YAML. See https://midscenejs.com/ for details.",
|
|
4
|
-
"version": "0.16.
|
|
4
|
+
"version": "0.16.10",
|
|
5
5
|
"repository": "https://github.com/web-infra-dev/midscene",
|
|
6
6
|
"homepage": "https://midscenejs.com/",
|
|
7
7
|
"jsnext:source": "./src/index.ts",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"langsmith": "0.3.7",
|
|
45
45
|
"openai": "4.81.0",
|
|
46
46
|
"socks-proxy-agent": "8.0.4",
|
|
47
|
-
"@midscene/shared": "0.16.
|
|
47
|
+
"@midscene/shared": "0.16.10"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@modern-js/module-tools": "2.60.6",
|
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
// src/utils.ts
|
|
2
|
-
import { execSync } from "child_process";
|
|
3
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
4
|
-
import { tmpdir } from "os";
|
|
5
|
-
import * as path from "path";
|
|
6
|
-
import { dirname } from "path";
|
|
7
|
-
import {
|
|
8
|
-
defaultRunDirName,
|
|
9
|
-
getMidsceneRunSubDir,
|
|
10
|
-
logDir
|
|
11
|
-
} from "@midscene/shared/common";
|
|
12
|
-
import {
|
|
13
|
-
MIDSCENE_DEBUG_MODE,
|
|
14
|
-
MIDSCENE_OPENAI_INIT_CONFIG_JSON,
|
|
15
|
-
getAIConfig,
|
|
16
|
-
getAIConfigInJson
|
|
17
|
-
} from "@midscene/shared/env";
|
|
18
|
-
import { getRunningPkgInfo } from "@midscene/shared/fs";
|
|
19
|
-
import { assert } from "@midscene/shared/utils";
|
|
20
|
-
import { ifInBrowser, uuid } from "@midscene/shared/utils";
|
|
21
|
-
var logEnvReady = false;
|
|
22
|
-
var groupedActionDumpFileExt = "web-dump.json";
|
|
23
|
-
function getLogDir() {
|
|
24
|
-
return logDir;
|
|
25
|
-
}
|
|
26
|
-
var reportTpl = "REPLACE_ME_WITH_REPORT_HTML";
|
|
27
|
-
function getReportTpl() {
|
|
28
|
-
return reportTpl;
|
|
29
|
-
}
|
|
30
|
-
function replaceStringWithFirstAppearance(str, target, replacement) {
|
|
31
|
-
const index = str.indexOf(target);
|
|
32
|
-
return str.slice(0, index) + replacement + str.slice(index + target.length);
|
|
33
|
-
}
|
|
34
|
-
function reportHTMLContent(dumpData, reportPath) {
|
|
35
|
-
const tpl = getReportTpl();
|
|
36
|
-
if (!tpl) {
|
|
37
|
-
console.warn("reportTpl is not set, will not write report");
|
|
38
|
-
return "";
|
|
39
|
-
}
|
|
40
|
-
const dumpPlaceholder = "{{dump}}";
|
|
41
|
-
if (!tpl.includes(dumpPlaceholder)) {
|
|
42
|
-
console.warn("Template does not contain {{dump}} placeholder");
|
|
43
|
-
return "";
|
|
44
|
-
}
|
|
45
|
-
const placeholderIndex = tpl.indexOf(dumpPlaceholder);
|
|
46
|
-
const firstPart = tpl.substring(0, placeholderIndex);
|
|
47
|
-
const secondPart = tpl.substring(placeholderIndex + dumpPlaceholder.length);
|
|
48
|
-
const writeToFile = reportPath && !ifInBrowser;
|
|
49
|
-
let resultContent = "";
|
|
50
|
-
const appendOrWrite = (content) => {
|
|
51
|
-
if (writeToFile) {
|
|
52
|
-
writeFileSync(reportPath, `${content}
|
|
53
|
-
`, {
|
|
54
|
-
flag: "a"
|
|
55
|
-
});
|
|
56
|
-
} else {
|
|
57
|
-
resultContent += `${content}
|
|
58
|
-
`;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
if (writeToFile) {
|
|
62
|
-
writeFileSync(reportPath, firstPart, { flag: "w" });
|
|
63
|
-
} else {
|
|
64
|
-
resultContent = firstPart;
|
|
65
|
-
}
|
|
66
|
-
if (Array.isArray(dumpData) && dumpData.length === 0 || typeof dumpData === "undefined") {
|
|
67
|
-
const dumpContent = '<script type="midscene_web_dump" type="application/json"></script>';
|
|
68
|
-
appendOrWrite(dumpContent);
|
|
69
|
-
} else if (typeof dumpData === "string") {
|
|
70
|
-
const dumpContent = (
|
|
71
|
-
// biome-ignore lint/style/useTemplate: <explanation> do not use template string here, will cause bundle error
|
|
72
|
-
'<script type="midscene_web_dump" type="application/json">\n' + dumpData + "\n</script>"
|
|
73
|
-
);
|
|
74
|
-
appendOrWrite(dumpContent);
|
|
75
|
-
} else {
|
|
76
|
-
for (let i = 0; i < dumpData.length; i++) {
|
|
77
|
-
const { dumpString, attributes } = dumpData[i];
|
|
78
|
-
const attributesArr = Object.keys(attributes || {}).map((key) => {
|
|
79
|
-
return `${key}="${encodeURIComponent(attributes[key])}"`;
|
|
80
|
-
});
|
|
81
|
-
const dumpContent = (
|
|
82
|
-
// biome-ignore lint/style/useTemplate: <explanation> do not use template string here, will cause bundle error
|
|
83
|
-
'<script type="midscene_web_dump" type="application/json" ' + attributesArr.join(" ") + ">\n" + dumpString + "\n</script>"
|
|
84
|
-
);
|
|
85
|
-
appendOrWrite(dumpContent);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (writeToFile) {
|
|
89
|
-
writeFileSync(reportPath, secondPart, { flag: "a" });
|
|
90
|
-
return reportPath;
|
|
91
|
-
}
|
|
92
|
-
resultContent += secondPart;
|
|
93
|
-
return resultContent;
|
|
94
|
-
}
|
|
95
|
-
function writeDumpReport(fileName, dumpData) {
|
|
96
|
-
if (ifInBrowser) {
|
|
97
|
-
console.log("will not write report in browser");
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
const __dirname = dirname(__filename);
|
|
101
|
-
const midscenePkgInfo = getRunningPkgInfo(__dirname);
|
|
102
|
-
if (!midscenePkgInfo) {
|
|
103
|
-
console.warn("midscenePkgInfo not found, will not write report");
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
const reportPath = path.join(
|
|
107
|
-
getMidsceneRunSubDir("report"),
|
|
108
|
-
`${fileName}.html`
|
|
109
|
-
);
|
|
110
|
-
reportHTMLContent(dumpData, reportPath);
|
|
111
|
-
if (process.env.MIDSCENE_DEBUG_LOG_JSON) {
|
|
112
|
-
writeFileSync(
|
|
113
|
-
`${reportPath}.json`,
|
|
114
|
-
typeof dumpData === "string" ? dumpData : JSON.stringify(dumpData, null, 2)
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
return reportPath;
|
|
118
|
-
}
|
|
119
|
-
function writeLogFile(opts) {
|
|
120
|
-
if (ifInBrowser) {
|
|
121
|
-
return "/mock/report.html";
|
|
122
|
-
}
|
|
123
|
-
const { fileName, fileExt, fileContent, type = "dump" } = opts;
|
|
124
|
-
const targetDir = getMidsceneRunSubDir(type);
|
|
125
|
-
if (!logEnvReady) {
|
|
126
|
-
assert(targetDir, "logDir should be set before writing dump file");
|
|
127
|
-
const gitIgnorePath = path.join(targetDir, "../../.gitignore");
|
|
128
|
-
const gitPath = path.join(targetDir, "../../.git");
|
|
129
|
-
let gitIgnoreContent = "";
|
|
130
|
-
if (existsSync(gitPath)) {
|
|
131
|
-
if (existsSync(gitIgnorePath)) {
|
|
132
|
-
gitIgnoreContent = readFileSync(gitIgnorePath, "utf-8");
|
|
133
|
-
}
|
|
134
|
-
if (!gitIgnoreContent.includes(`${defaultRunDirName}/`)) {
|
|
135
|
-
writeFileSync(
|
|
136
|
-
gitIgnorePath,
|
|
137
|
-
`${gitIgnoreContent}
|
|
138
|
-
# Midscene.js dump files
|
|
139
|
-
${defaultRunDirName}/dump
|
|
140
|
-
${defaultRunDirName}/report
|
|
141
|
-
${defaultRunDirName}/tmp
|
|
142
|
-
${defaultRunDirName}/log
|
|
143
|
-
`,
|
|
144
|
-
"utf-8"
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
logEnvReady = true;
|
|
149
|
-
}
|
|
150
|
-
const filePath = path.join(targetDir, `${fileName}.${fileExt}`);
|
|
151
|
-
if (type !== "dump") {
|
|
152
|
-
writeFileSync(filePath, fileContent);
|
|
153
|
-
}
|
|
154
|
-
if (opts?.generateReport) {
|
|
155
|
-
return writeDumpReport(fileName, fileContent);
|
|
156
|
-
}
|
|
157
|
-
return filePath;
|
|
158
|
-
}
|
|
159
|
-
function getTmpDir() {
|
|
160
|
-
try {
|
|
161
|
-
const runningPkgInfo = getRunningPkgInfo();
|
|
162
|
-
if (!runningPkgInfo) {
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
const { name } = runningPkgInfo;
|
|
166
|
-
const tmpPath = path.join(tmpdir(), name);
|
|
167
|
-
mkdirSync(tmpPath, { recursive: true });
|
|
168
|
-
return tmpPath;
|
|
169
|
-
} catch (e) {
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
function getTmpFile(fileExtWithoutDot) {
|
|
174
|
-
if (ifInBrowser) {
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
const tmpDir = getTmpDir();
|
|
178
|
-
const filename = `${uuid()}.${fileExtWithoutDot}`;
|
|
179
|
-
return path.join(tmpDir, filename);
|
|
180
|
-
}
|
|
181
|
-
function overlapped(container, target) {
|
|
182
|
-
return container.left < target.left + target.width && container.left + container.width > target.left && container.top < target.top + target.height && container.top + container.height > target.top;
|
|
183
|
-
}
|
|
184
|
-
async function sleep(ms) {
|
|
185
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
186
|
-
}
|
|
187
|
-
function replacerForPageObject(key, value) {
|
|
188
|
-
if (value && value.constructor?.name === "Page") {
|
|
189
|
-
return "[Page object]";
|
|
190
|
-
}
|
|
191
|
-
if (value && value.constructor?.name === "Browser") {
|
|
192
|
-
return "[Browser object]";
|
|
193
|
-
}
|
|
194
|
-
return value;
|
|
195
|
-
}
|
|
196
|
-
function stringifyDumpData(data, indents) {
|
|
197
|
-
return JSON.stringify(data, replacerForPageObject, indents);
|
|
198
|
-
}
|
|
199
|
-
function getVersion() {
|
|
200
|
-
return "0.16.9";
|
|
201
|
-
}
|
|
202
|
-
function debugLog(...message) {
|
|
203
|
-
const debugMode = getAIConfig(MIDSCENE_DEBUG_MODE);
|
|
204
|
-
if (debugMode) {
|
|
205
|
-
console.log("[Midscene]", ...message);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
var lastReportedRepoUrl = "";
|
|
209
|
-
function uploadTestInfoToServer({ testUrl }) {
|
|
210
|
-
let repoUrl = "";
|
|
211
|
-
let userEmail = "";
|
|
212
|
-
const extraConfig = getAIConfigInJson(MIDSCENE_OPENAI_INIT_CONFIG_JSON);
|
|
213
|
-
const serverUrl = extraConfig?.REPORT_SERVER_URL;
|
|
214
|
-
try {
|
|
215
|
-
repoUrl = execSync("git config --get remote.origin.url").toString().trim();
|
|
216
|
-
userEmail = execSync("git config --get user.email").toString().trim();
|
|
217
|
-
} catch (error) {
|
|
218
|
-
debugLog("Failed to get git info:", error);
|
|
219
|
-
}
|
|
220
|
-
if (serverUrl && (repoUrl && repoUrl !== lastReportedRepoUrl || !repoUrl && testUrl)) {
|
|
221
|
-
debugLog("Uploading test info to server", {
|
|
222
|
-
serverUrl,
|
|
223
|
-
repoUrl,
|
|
224
|
-
testUrl,
|
|
225
|
-
userEmail
|
|
226
|
-
});
|
|
227
|
-
fetch(serverUrl, {
|
|
228
|
-
method: "POST",
|
|
229
|
-
headers: {
|
|
230
|
-
"Content-Type": "application/json"
|
|
231
|
-
},
|
|
232
|
-
body: JSON.stringify({
|
|
233
|
-
repo_url: repoUrl,
|
|
234
|
-
test_url: testUrl,
|
|
235
|
-
user_email: userEmail
|
|
236
|
-
})
|
|
237
|
-
}).then((response) => response.json()).then((data) => {
|
|
238
|
-
debugLog("Successfully uploaded test info to server:", data);
|
|
239
|
-
}).catch(
|
|
240
|
-
(error) => debugLog("Failed to upload test info to server:", error)
|
|
241
|
-
);
|
|
242
|
-
lastReportedRepoUrl = repoUrl;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
export {
|
|
247
|
-
groupedActionDumpFileExt,
|
|
248
|
-
getLogDir,
|
|
249
|
-
replaceStringWithFirstAppearance,
|
|
250
|
-
reportHTMLContent,
|
|
251
|
-
writeDumpReport,
|
|
252
|
-
writeLogFile,
|
|
253
|
-
getTmpDir,
|
|
254
|
-
getTmpFile,
|
|
255
|
-
overlapped,
|
|
256
|
-
sleep,
|
|
257
|
-
replacerForPageObject,
|
|
258
|
-
stringifyDumpData,
|
|
259
|
-
getVersion,
|
|
260
|
-
uploadTestInfoToServer
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
//# sourceMappingURL=chunk-KINAY5TJ.js.map
|
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/utils.ts
|
|
2
|
-
var _child_process = require('child_process');
|
|
3
|
-
var _fs = require('fs');
|
|
4
|
-
var _os = require('os');
|
|
5
|
-
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var _common = require('@midscene/shared/common');
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var _env = require('@midscene/shared/env');
|
|
18
|
-
var _fs3 = require('@midscene/shared/fs');
|
|
19
|
-
var _utils = require('@midscene/shared/utils');
|
|
20
|
-
|
|
21
|
-
var logEnvReady = false;
|
|
22
|
-
var groupedActionDumpFileExt = "web-dump.json";
|
|
23
|
-
function getLogDir() {
|
|
24
|
-
return _common.logDir;
|
|
25
|
-
}
|
|
26
|
-
var reportTpl = "REPLACE_ME_WITH_REPORT_HTML";
|
|
27
|
-
function getReportTpl() {
|
|
28
|
-
return reportTpl;
|
|
29
|
-
}
|
|
30
|
-
function replaceStringWithFirstAppearance(str, target, replacement) {
|
|
31
|
-
const index = str.indexOf(target);
|
|
32
|
-
return str.slice(0, index) + replacement + str.slice(index + target.length);
|
|
33
|
-
}
|
|
34
|
-
function reportHTMLContent(dumpData, reportPath) {
|
|
35
|
-
const tpl = getReportTpl();
|
|
36
|
-
if (!tpl) {
|
|
37
|
-
console.warn("reportTpl is not set, will not write report");
|
|
38
|
-
return "";
|
|
39
|
-
}
|
|
40
|
-
const dumpPlaceholder = "{{dump}}";
|
|
41
|
-
if (!tpl.includes(dumpPlaceholder)) {
|
|
42
|
-
console.warn("Template does not contain {{dump}} placeholder");
|
|
43
|
-
return "";
|
|
44
|
-
}
|
|
45
|
-
const placeholderIndex = tpl.indexOf(dumpPlaceholder);
|
|
46
|
-
const firstPart = tpl.substring(0, placeholderIndex);
|
|
47
|
-
const secondPart = tpl.substring(placeholderIndex + dumpPlaceholder.length);
|
|
48
|
-
const writeToFile = reportPath && !_utils.ifInBrowser;
|
|
49
|
-
let resultContent = "";
|
|
50
|
-
const appendOrWrite = (content) => {
|
|
51
|
-
if (writeToFile) {
|
|
52
|
-
_fs.writeFileSync.call(void 0, reportPath, `${content}
|
|
53
|
-
`, {
|
|
54
|
-
flag: "a"
|
|
55
|
-
});
|
|
56
|
-
} else {
|
|
57
|
-
resultContent += `${content}
|
|
58
|
-
`;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
if (writeToFile) {
|
|
62
|
-
_fs.writeFileSync.call(void 0, reportPath, firstPart, { flag: "w" });
|
|
63
|
-
} else {
|
|
64
|
-
resultContent = firstPart;
|
|
65
|
-
}
|
|
66
|
-
if (Array.isArray(dumpData) && dumpData.length === 0 || typeof dumpData === "undefined") {
|
|
67
|
-
const dumpContent = '<script type="midscene_web_dump" type="application/json"></script>';
|
|
68
|
-
appendOrWrite(dumpContent);
|
|
69
|
-
} else if (typeof dumpData === "string") {
|
|
70
|
-
const dumpContent = (
|
|
71
|
-
// biome-ignore lint/style/useTemplate: <explanation> do not use template string here, will cause bundle error
|
|
72
|
-
'<script type="midscene_web_dump" type="application/json">\n' + dumpData + "\n</script>"
|
|
73
|
-
);
|
|
74
|
-
appendOrWrite(dumpContent);
|
|
75
|
-
} else {
|
|
76
|
-
for (let i = 0; i < dumpData.length; i++) {
|
|
77
|
-
const { dumpString, attributes } = dumpData[i];
|
|
78
|
-
const attributesArr = Object.keys(attributes || {}).map((key) => {
|
|
79
|
-
return `${key}="${encodeURIComponent(attributes[key])}"`;
|
|
80
|
-
});
|
|
81
|
-
const dumpContent = (
|
|
82
|
-
// biome-ignore lint/style/useTemplate: <explanation> do not use template string here, will cause bundle error
|
|
83
|
-
'<script type="midscene_web_dump" type="application/json" ' + attributesArr.join(" ") + ">\n" + dumpString + "\n</script>"
|
|
84
|
-
);
|
|
85
|
-
appendOrWrite(dumpContent);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (writeToFile) {
|
|
89
|
-
_fs.writeFileSync.call(void 0, reportPath, secondPart, { flag: "a" });
|
|
90
|
-
return reportPath;
|
|
91
|
-
}
|
|
92
|
-
resultContent += secondPart;
|
|
93
|
-
return resultContent;
|
|
94
|
-
}
|
|
95
|
-
function writeDumpReport(fileName, dumpData) {
|
|
96
|
-
if (_utils.ifInBrowser) {
|
|
97
|
-
console.log("will not write report in browser");
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
const __dirname = _path.dirname.call(void 0, __filename);
|
|
101
|
-
const midscenePkgInfo = _fs3.getRunningPkgInfo.call(void 0, __dirname);
|
|
102
|
-
if (!midscenePkgInfo) {
|
|
103
|
-
console.warn("midscenePkgInfo not found, will not write report");
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
const reportPath = path.join(
|
|
107
|
-
_common.getMidsceneRunSubDir.call(void 0, "report"),
|
|
108
|
-
`${fileName}.html`
|
|
109
|
-
);
|
|
110
|
-
reportHTMLContent(dumpData, reportPath);
|
|
111
|
-
if (process.env.MIDSCENE_DEBUG_LOG_JSON) {
|
|
112
|
-
_fs.writeFileSync.call(void 0,
|
|
113
|
-
`${reportPath}.json`,
|
|
114
|
-
typeof dumpData === "string" ? dumpData : JSON.stringify(dumpData, null, 2)
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
return reportPath;
|
|
118
|
-
}
|
|
119
|
-
function writeLogFile(opts) {
|
|
120
|
-
if (_utils.ifInBrowser) {
|
|
121
|
-
return "/mock/report.html";
|
|
122
|
-
}
|
|
123
|
-
const { fileName, fileExt, fileContent, type = "dump" } = opts;
|
|
124
|
-
const targetDir = _common.getMidsceneRunSubDir.call(void 0, type);
|
|
125
|
-
if (!logEnvReady) {
|
|
126
|
-
_utils.assert.call(void 0, targetDir, "logDir should be set before writing dump file");
|
|
127
|
-
const gitIgnorePath = path.join(targetDir, "../../.gitignore");
|
|
128
|
-
const gitPath = path.join(targetDir, "../../.git");
|
|
129
|
-
let gitIgnoreContent = "";
|
|
130
|
-
if (_fs.existsSync.call(void 0, gitPath)) {
|
|
131
|
-
if (_fs.existsSync.call(void 0, gitIgnorePath)) {
|
|
132
|
-
gitIgnoreContent = _fs.readFileSync.call(void 0, gitIgnorePath, "utf-8");
|
|
133
|
-
}
|
|
134
|
-
if (!gitIgnoreContent.includes(`${_common.defaultRunDirName}/`)) {
|
|
135
|
-
_fs.writeFileSync.call(void 0,
|
|
136
|
-
gitIgnorePath,
|
|
137
|
-
`${gitIgnoreContent}
|
|
138
|
-
# Midscene.js dump files
|
|
139
|
-
${_common.defaultRunDirName}/dump
|
|
140
|
-
${_common.defaultRunDirName}/report
|
|
141
|
-
${_common.defaultRunDirName}/tmp
|
|
142
|
-
${_common.defaultRunDirName}/log
|
|
143
|
-
`,
|
|
144
|
-
"utf-8"
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
logEnvReady = true;
|
|
149
|
-
}
|
|
150
|
-
const filePath = path.join(targetDir, `${fileName}.${fileExt}`);
|
|
151
|
-
if (type !== "dump") {
|
|
152
|
-
_fs.writeFileSync.call(void 0, filePath, fileContent);
|
|
153
|
-
}
|
|
154
|
-
if (_optionalChain([opts, 'optionalAccess', _ => _.generateReport])) {
|
|
155
|
-
return writeDumpReport(fileName, fileContent);
|
|
156
|
-
}
|
|
157
|
-
return filePath;
|
|
158
|
-
}
|
|
159
|
-
function getTmpDir() {
|
|
160
|
-
try {
|
|
161
|
-
const runningPkgInfo = _fs3.getRunningPkgInfo.call(void 0, );
|
|
162
|
-
if (!runningPkgInfo) {
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
const { name } = runningPkgInfo;
|
|
166
|
-
const tmpPath = path.join(_os.tmpdir.call(void 0, ), name);
|
|
167
|
-
_fs.mkdirSync.call(void 0, tmpPath, { recursive: true });
|
|
168
|
-
return tmpPath;
|
|
169
|
-
} catch (e) {
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
function getTmpFile(fileExtWithoutDot) {
|
|
174
|
-
if (_utils.ifInBrowser) {
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
const tmpDir = getTmpDir();
|
|
178
|
-
const filename = `${_utils.uuid.call(void 0, )}.${fileExtWithoutDot}`;
|
|
179
|
-
return path.join(tmpDir, filename);
|
|
180
|
-
}
|
|
181
|
-
function overlapped(container, target) {
|
|
182
|
-
return container.left < target.left + target.width && container.left + container.width > target.left && container.top < target.top + target.height && container.top + container.height > target.top;
|
|
183
|
-
}
|
|
184
|
-
async function sleep(ms) {
|
|
185
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
186
|
-
}
|
|
187
|
-
function replacerForPageObject(key, value) {
|
|
188
|
-
if (value && _optionalChain([value, 'access', _2 => _2.constructor, 'optionalAccess', _3 => _3.name]) === "Page") {
|
|
189
|
-
return "[Page object]";
|
|
190
|
-
}
|
|
191
|
-
if (value && _optionalChain([value, 'access', _4 => _4.constructor, 'optionalAccess', _5 => _5.name]) === "Browser") {
|
|
192
|
-
return "[Browser object]";
|
|
193
|
-
}
|
|
194
|
-
return value;
|
|
195
|
-
}
|
|
196
|
-
function stringifyDumpData(data, indents) {
|
|
197
|
-
return JSON.stringify(data, replacerForPageObject, indents);
|
|
198
|
-
}
|
|
199
|
-
function getVersion() {
|
|
200
|
-
return "0.16.9";
|
|
201
|
-
}
|
|
202
|
-
function debugLog(...message) {
|
|
203
|
-
const debugMode = _env.getAIConfig.call(void 0, _env.MIDSCENE_DEBUG_MODE);
|
|
204
|
-
if (debugMode) {
|
|
205
|
-
console.log("[Midscene]", ...message);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
var lastReportedRepoUrl = "";
|
|
209
|
-
function uploadTestInfoToServer({ testUrl }) {
|
|
210
|
-
let repoUrl = "";
|
|
211
|
-
let userEmail = "";
|
|
212
|
-
const extraConfig = _env.getAIConfigInJson.call(void 0, _env.MIDSCENE_OPENAI_INIT_CONFIG_JSON);
|
|
213
|
-
const serverUrl = _optionalChain([extraConfig, 'optionalAccess', _6 => _6.REPORT_SERVER_URL]);
|
|
214
|
-
try {
|
|
215
|
-
repoUrl = _child_process.execSync.call(void 0, "git config --get remote.origin.url").toString().trim();
|
|
216
|
-
userEmail = _child_process.execSync.call(void 0, "git config --get user.email").toString().trim();
|
|
217
|
-
} catch (error) {
|
|
218
|
-
debugLog("Failed to get git info:", error);
|
|
219
|
-
}
|
|
220
|
-
if (serverUrl && (repoUrl && repoUrl !== lastReportedRepoUrl || !repoUrl && testUrl)) {
|
|
221
|
-
debugLog("Uploading test info to server", {
|
|
222
|
-
serverUrl,
|
|
223
|
-
repoUrl,
|
|
224
|
-
testUrl,
|
|
225
|
-
userEmail
|
|
226
|
-
});
|
|
227
|
-
fetch(serverUrl, {
|
|
228
|
-
method: "POST",
|
|
229
|
-
headers: {
|
|
230
|
-
"Content-Type": "application/json"
|
|
231
|
-
},
|
|
232
|
-
body: JSON.stringify({
|
|
233
|
-
repo_url: repoUrl,
|
|
234
|
-
test_url: testUrl,
|
|
235
|
-
user_email: userEmail
|
|
236
|
-
})
|
|
237
|
-
}).then((response) => response.json()).then((data) => {
|
|
238
|
-
debugLog("Successfully uploaded test info to server:", data);
|
|
239
|
-
}).catch(
|
|
240
|
-
(error) => debugLog("Failed to upload test info to server:", error)
|
|
241
|
-
);
|
|
242
|
-
lastReportedRepoUrl = repoUrl;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
exports.groupedActionDumpFileExt = groupedActionDumpFileExt; exports.getLogDir = getLogDir; exports.replaceStringWithFirstAppearance = replaceStringWithFirstAppearance; exports.reportHTMLContent = reportHTMLContent; exports.writeDumpReport = writeDumpReport; exports.writeLogFile = writeLogFile; exports.getTmpDir = getTmpDir; exports.getTmpFile = getTmpFile; exports.overlapped = overlapped; exports.sleep = sleep; exports.replacerForPageObject = replacerForPageObject; exports.stringifyDumpData = stringifyDumpData; exports.getVersion = getVersion; exports.uploadTestInfoToServer = uploadTestInfoToServer;
|
|
262
|
-
|
|
263
|
-
//# sourceMappingURL=chunk-KINAY5TJ.js.map
|
|
File without changes
|
|
File without changes
|