/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@web/test-runner-commands@0.9.0/browser/commands.mjs
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
const PARAM_SESSION_ID="wtr-session-id",sessionId=new URL(window.location.href).searchParams.get("wtr-session-id");function isObject(e){return null!=e&&"object"==typeof e}export async function executeServerCommand(e,t,n){if("string"!=typeof sessionId)throw new Error("Unable to execute server commands in a browser not controlled by the test runner. Use the debug option from the watch menu to debug in a controlled browser.");let o;try{const e=await import("/__web-dev-server__web-socket.js");({sendMessageWaitForResponse:o}=e)}catch(e){throw new Error("Could not setup web socket connection. Are you executing this test through Web Test Runner?")}try{const r=await o({type:"wtr-command",sessionId:sessionId,command:e,payload:t});if(!r.executed){let t;throw t=n?`Unknown command ${e}. Add the ${n} to your config.`:`Unknown command ${e}. Did you install a plugin to handle this command?`,new Error(t)}return r.result}catch(n){throw new Error(`Error while executing command ${e}${t?` with payload ${JSON.stringify(t)}`:""}: ${n.message}`)}}export function setViewport(e){return executeServerCommand("set-viewport",e)}export function emulateMedia(e){return executeServerCommand("emulate-media",e)}export function setUserAgent(e){return executeServerCommand("set-user-agent",e)}export function sendKeys(e){return executeServerCommand("send-keys",e)}export function selectOption(e){return executeServerCommand("select-option",e)}export function sendMouse(e){return executeServerCommand("send-mouse",e)}export function resetMouse(e){return executeServerCommand("reset-mouse",e)}export function a11ySnapshot(e){return executeServerCommand("a11y-snapshot",e)}export function writeFile(e){return executeServerCommand("write-file",e,"filePlugin from @web/test-runner-commands")}export function readFile(e){return executeServerCommand("read-file",e,"filePlugin from @web/test-runner-commands")}export function removeFile(e){return executeServerCommand("remove-file",e,"filePlugin from @web/test-runner-commands")}export function findAccessibilityNode(e,t){if(t(e))return e;for(const n of e.children||[]){const e=findAccessibilityNode(n,t);if(e)return e}return null}let snapshotConfig,cachedSnapshots;export async function getSnapshotConfig(){return snapshotConfig||(snapshotConfig=await executeServerCommand("get-snapshot-config",void 0,"snapshotPlugin from @web/test-runner-commands")),snapshotConfig}const ESCAPE_REGEX=/snapshots\[[^\]]+] = (\n)?(?<content>`[^`]*`)/gm,escapeContent=e=>([...e.matchAll(ESCAPE_REGEX)].forEach((({groups:{content:t}})=>{e=e.replaceAll(t,encodeURIComponent(t))})),e);export async function getSnapshots({cache:e=!0}={}){if(e&&cachedSnapshots)return cachedSnapshots;const t=await executeServerCommand("get-snapshots",void 0,"snapshotPlugin from @web/test-runner-commands");if("string"!=typeof t?.content)throw new Error("Expected a result as string");const n=`${escapeContent(t.content)}/* ${Math.random()} */`,o=await import(`data:text/javascript;charset=utf-8,${n}`);if(!o||!isObject(o.snapshots))throw new Error("Expected snapshot result to be a module that exports an object.");return cachedSnapshots=o.snapshots,cachedSnapshots}export async function getSnapshot(e){if(!isObject(e))throw new Error("You must provide a payload object");if("string"!=typeof e.name)throw new Error("You must provide a snapshot name");return(await getSnapshots(e))[e.name]}export async function saveSnapshot(e){if(!isObject(e))throw new Error("You must provide a payload object");if("string"!=typeof e.name)throw new Error("You must provide a snapshot name");if(void 0!==e.content&&"string"!=typeof e.content)throw new Error("You must provide a snapshot content");return(await getSnapshots())[e.name]=e.content,executeServerCommand("save-snapshot",e,"snapshotPlugin from @web/test-runner-commands")}export function removeSnapshot(e){if(!isObject(e))throw new Error("You must provide a payload object");if("string"!=typeof e.name)throw new Error("You must provide a snapshot name");return saveSnapshot({...e,content:void 0})}export async function compareSnapshot({name:e,content:t}){const n=await getSnapshot({name:e});if(n){if((await getSnapshotConfig()).updateSnapshots){if(n===t)return}else if(n!==t)throw new Error(`Snapshots for ${e} are not equal. \n\nStored:\n${n}\n\nNew:\n${t}`)}await saveSnapshot({name:e,content:t})}
//# sourceMappingURL=/sm/6a52f0149a80d79138ee18fc1f84dde92c099b69ab4d4d2a02219f2a329255bb.map