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

Function selfTestScript

e2e/resource-update.spec.ts:74–106  ·  view source on GitHub ↗
(opts: {
  name: string;
  matchHost: string;
  requireUrls?: string[];
  resourceUrl?: string;
  port: number;
})

Source from the content-addressed store, hash-verified

72}
73
74function selfTestScript(opts: {
75 name: string;
76 matchHost: string;
77 requireUrls?: string[];
78 resourceUrl?: string;
79 port: number;
80}): string {
81 const requires = (opts.requireUrls || []).map((u) => `// @require ${u}`).join("\n");
82 const resourceLine = opts.resourceUrl ? `// @resource cfg ${opts.resourceUrl}` : "";
83 const grants = opts.resourceUrl ? "// @grant GM_getResourceText" : "// @grant none";
84 return `// ==UserScript==
85// @name ${opts.name}
86// @namespace https://e2e.test
87// @version 1.0.0
88// @description resource e2e
89// @match http://${opts.matchHost}:${opts.port}/*
90${requires}
91${resourceLine}
92${grants}
93// @noframes
94// ==/UserScript==
95
96(function () {
97 var out = {
98 libVersion: (typeof window.__LIB_VERSION__ !== "undefined") ? window.__LIB_VERSION__ : null,
99 lib2: (typeof window.__LIB2_OK__ !== "undefined") ? window.__LIB2_OK__ : null,
100 bodyRan: true,
101 };
102 ${opts.resourceUrl ? 'try { out.res = GM_getResourceText("cfg"); } catch (e) { out.resErr = String(e); }' : ""}
103 console.log("${SENTINEL}" + JSON.stringify(out));
104})();
105`;
106}
107
108test.describe("Resource update & concurrency (#1193)", () => {
109 let server: MockServer;

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected