Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

1.7 KB
Raw Blame
<!doctype html>
<meta charset="utf-8">
<script src="/wpt/resources/testharness.js"></script>
<script src="/wpt/resources/testharnessreport.js"></script>
<script src="/wpt/resources/moli-wpt-adapter.js"></script>
<script>
function next_message(worker) {
  return new Promise(function (resolve, reject) {
    worker.addEventListener("message", resolve, { once: true });
    worker.addEventListener("error", function (event) {
      reject(new Error("Worker error: " + event.message));
    }, { once: true });
  });
}

promise_test(async function () {
  const workerUrl = new URL(
    "/wpt/ported/worker/resources/worker-module-json-main.js",
    location.href,
  ).href;
  const worker = new Worker(workerUrl, { type: "module" });

  try {
    const message = await next_message(worker);
    assert_equals(message.data.error, undefined, "JSON module worker should not fail");
    assert_equals(message.data.httpName, "http-json", "HTTP JSON default export should be parsed");
    assert_equals(message.data.httpNested, 7, "HTTP JSON nested values should be visible");
    assert_equals(message.data.httpArray, "alpha|beta", "HTTP JSON arrays should be preserved");
    assert_equals(message.data.dataName, "data-json", "data: JSON module should be parsed");
    assert_equals(message.data.dataFlag, true, "data: JSON booleans should be preserved");
    assert_equals(message.data.namespaceDefaultName, "http-json", "namespace import should expose the JSON default export");
    assert_equals(message.data.importScriptsType, "function", "module workers should expose WorkerGlobalScope.importScripts");
  } finally {
    worker.terminate();
  }
}, "Dedicated module workers import JSON modules with import attributes");
</script>