MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / runTestScript

Function runTestScript

e2e/gm-api.spec.ts:229–267  ·  view source on GitHub ↗
(
  context: BrowserContext,
  extensionId: string,
  scriptFile: string,
  targetUrl: string,
  timeoutMs: number,
  options?: { patchCode?: (code: string) => string }
)

Source from the content-addressed store, hash-verified

227}
228
229async function runTestScript(
230 context: BrowserContext,
231 extensionId: string,
232 scriptFile: string,
233 targetUrl: string,
234 timeoutMs: number,
235 options?: { patchCode?: (code: string) => string }
236): Promise<{ passed: number; failed: number; logs: string[] }> {
237 let code = fs.readFileSync(path.join(__dirname, `../example/tests/${scriptFile}`), "utf-8");
238 code = patchScriptCode(code);
239 code = patchTargetMatchCode(code, targetUrl);
240 code = options?.patchCode ? options.patchCode(code) : code;
241
242 await installScriptByCode(context, extensionId, code);
243 autoApprovePermissions(context);
244
245 const page = await context.newPage();
246 const logs: string[] = [];
247 let passed = -1;
248 let failed = -1;
249
250 page.on("console", (msg) => {
251 const text = msg.text();
252 logs.push(text);
253 const passMatch = text.match(/(通过|Passed)[::]\s*(\d+)/);
254 const failMatch = text.match(/(失败|Failed)[::]\s*(\d+)/);
255 if (passMatch) passed = parseInt(passMatch[2], 10);
256 if (failMatch) failed = parseInt(failMatch[2], 10);
257 });
258
259 await page.goto(targetUrl, { waitUntil: "domcontentloaded" });
260 await expect
261 .poll(() => passed >= 0 && failed >= 0, { timeout: timeoutMs, intervals: [100, 250, 500, 1_000] })
262 .toBe(true)
263 .catch(() => undefined);
264
265 await page.close();
266 return { passed, failed, logs };
267}
268
269test.describe("GM API", () => {
270 let gmApiMockServer: GMApiMockServer;

Callers 1

gm-api.spec.tsFile · 0.70

Calls 8

installScriptByCodeFunction · 0.90
patchTargetMatchCodeFunction · 0.85
pushMethod · 0.80
patchScriptCodeFunction · 0.70
autoApprovePermissionsFunction · 0.70
closeMethod · 0.65
onMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected