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

Function runInlineTestScript

e2e/utils.ts:55–87  ·  view source on GitHub ↗
(
  context: BrowserContext,
  extensionId: string,
  code: string,
  targetUrl: string,
  timeoutMs: number
)

Source from the content-addressed store, hash-verified

53
54/** Run inline script code on the target page and collect console results */
55export async function runInlineTestScript(
56 context: BrowserContext,
57 extensionId: string,
58 code: string,
59 targetUrl: string,
60 timeoutMs: number
61): Promise<{ passed: number; failed: number; logs: string[] }> {
62 await installScriptByCode(context, extensionId, code);
63 autoApprovePermissions(context);
64
65 const page = await context.newPage();
66 const logs: string[] = [];
67 let passed = -1;
68 let failed = -1;
69
70 page.on("console", (msg) => {
71 const text = msg.text();
72 logs.push(text);
73 const passMatch = text.match(/通过[::]\s*(\d+)/);
74 const failMatch = text.match(/失败[::]\s*(\d+)/);
75 if (passMatch) passed = parseInt(passMatch[1], 10);
76 if (failMatch) failed = parseInt(failMatch[1], 10);
77 });
78
79 await page.goto(targetUrl, { waitUntil: "domcontentloaded" });
80 await expect
81 .poll(() => passed >= 0 && failed >= 0, { timeout: timeoutMs, intervals: [100, 250, 500, 1_000] })
82 .toBe(true)
83 .catch(() => undefined);
84
85 await page.close();
86 return { passed, failed, logs };
87}
88
89/** Open the options page and wait for it to load */
90export async function openOptionsPage(context: BrowserContext, extensionId: string): Promise<Page> {

Callers 3

runTestScriptFunction · 0.85

Calls 6

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

Tested by

no test coverage detected