mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-02 22:03:07 +00:00
70 lines
21 KiB
HTML
70 lines
21 KiB
HTML
<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>@waku/browser-tests | Documentation</title><meta name="description" content="Documentation for Documentation"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search" data-base=".."><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">Documentation</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../index.html">Documentation</a></li><li><a href="_waku_browser_tests.html">@waku/browser-tests</a></li></ul><h1>Module @waku/browser-tests</h1></div><section class="tsd-panel tsd-typography"><a id="md:waku-browser-tests" class="tsd-anchor"></a><h1><a href="#md:waku-browser-tests">Waku Browser Tests</a></h1><p>This project provides a system for testing the Waku SDK in a browser environment.</p>
|
|
<a id="md:architecture" class="tsd-anchor"></a><h2><a href="#md:architecture">Architecture</a></h2><p>The system consists of:</p>
|
|
<ol>
|
|
<li><strong>Headless Web App</strong>: A simple web application (in the <code>@waku/headless-tests</code> package) that loads the Waku SDK and exposes shared API functions.</li>
|
|
<li><strong>Express Server</strong>: A server that communicates with the headless app using Playwright.</li>
|
|
<li><strong>Shared API</strong>: TypeScript functions shared between the server and web app.</li>
|
|
</ol>
|
|
<a id="md:setup" class="tsd-anchor"></a><h2><a href="#md:setup">Setup</a></h2><ol>
|
|
<li>Install dependencies:</li>
|
|
</ol>
|
|
<pre><code class="language-bash"><span class="hl-4"># Install main dependencies</span><br/><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">install</span><br/><br/><span class="hl-4"># Install headless app dependencies</span><br/><span class="hl-0">cd</span><span class="hl-1"> </span><span class="hl-2">../headless-tests</span><br/><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">install</span><br/><span class="hl-0">cd</span><span class="hl-1"> </span><span class="hl-2">../browser-tests</span>
|
|
</code><button>Copy</button></pre>
|
|
<ol start="2">
|
|
<li>Build the application:</li>
|
|
</ol>
|
|
<pre><code class="language-bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">run</span><span class="hl-1"> </span><span class="hl-2">build</span>
|
|
</code><button>Copy</button></pre>
|
|
<p>This will:</p>
|
|
<ul>
|
|
<li>Build the headless web app using webpack</li>
|
|
<li>Compile the TypeScript server code</li>
|
|
</ul>
|
|
<a id="md:running" class="tsd-anchor"></a><h2><a href="#md:running">Running</a></h2><p>Start the server with:</p>
|
|
<pre><code class="language-bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">run</span><span class="hl-1"> </span><span class="hl-2">start:server</span>
|
|
</code><button>Copy</button></pre>
|
|
<p>This will:</p>
|
|
<ol>
|
|
<li>Serve the headless app on port 8080</li>
|
|
<li>Start a headless browser to load the app</li>
|
|
<li>Expose API endpoints to interact with Waku</li>
|
|
</ol>
|
|
<a id="md:api-endpoints" class="tsd-anchor"></a><h2><a href="#md:api-endpoints">API Endpoints</a></h2><ul>
|
|
<li><code>GET /info</code>: Get information about the Waku node</li>
|
|
<li><code>GET /debug/v1/info</code>: Get debug information from the Waku node</li>
|
|
<li><code>POST /push</code>: Push a message to the Waku network (legacy)</li>
|
|
<li><code>POST /lightpush/v1/message</code>: Push a message to the Waku network (Waku REST API compatible)</li>
|
|
<li><code>POST /admin/v1/create-node</code>: Create a new Waku node (requires networkConfig)</li>
|
|
<li><code>POST /admin/v1/start-node</code>: Start the Waku node</li>
|
|
<li><code>POST /admin/v1/stop-node</code>: Stop the Waku node</li>
|
|
<li><code>POST /admin/v1/peers</code>: Dial to specified peers (Waku REST API compatible)</li>
|
|
<li><code>GET /filter/v2/messages/:contentTopic</code>: Subscribe to messages on a specific content topic using Server-Sent Events (Waku REST API compatible)</li>
|
|
<li><code>GET /filter/v1/messages/:contentTopic</code>: Retrieve stored messages from a content topic (Waku REST API compatible)</li>
|
|
</ul>
|
|
<a id="md:example-pushing-a-message-with-the-legacy-endpoint" class="tsd-anchor"></a><h3><a href="#md:example-pushing-a-message-with-the-legacy-endpoint">Example: Pushing a message with the legacy endpoint</a></h3><pre><code class="language-bash"><span class="hl-0">curl</span><span class="hl-1"> </span><span class="hl-5">-X</span><span class="hl-1"> </span><span class="hl-2">POST</span><span class="hl-1"> </span><span class="hl-2">http://localhost:3000/push</span><span class="hl-1"> </span><span class="hl-10">\</span><br/><span class="hl-1"> </span><span class="hl-5">-H</span><span class="hl-1"> </span><span class="hl-2">"Content-Type: application/json"</span><span class="hl-1"> </span><span class="hl-10">\</span><br/><span class="hl-1"> </span><span class="hl-5">-d</span><span class="hl-1"> </span><span class="hl-2">'{"contentTopic": "/toy-chat/2/huilong/proto", "payload": [1, 2, 3]}'</span>
|
|
</code><button>Copy</button></pre>
|
|
<a id="md:example-pushing-a-message-with-the-waku-rest-api-compatible-endpoint" class="tsd-anchor"></a><h3><a href="#md:example-pushing-a-message-with-the-waku-rest-api-compatible-endpoint">Example: Pushing a message with the Waku REST API compatible endpoint</a></h3><pre><code class="language-bash"><span class="hl-0">curl</span><span class="hl-1"> </span><span class="hl-5">-X</span><span class="hl-1"> </span><span class="hl-2">POST</span><span class="hl-1"> </span><span class="hl-2">http://localhost:3000/lightpush/v1/message</span><span class="hl-1"> </span><span class="hl-10">\</span><br/><span class="hl-1"> </span><span class="hl-5">-H</span><span class="hl-1"> </span><span class="hl-2">"Content-Type: application/json"</span><span class="hl-1"> </span><span class="hl-10">\</span><br/><span class="hl-1"> </span><span class="hl-5">-d</span><span class="hl-1"> </span><span class="hl-2">'{</span><br/><span class="hl-2"> "pubsubTopic": "/waku/2/rs/0/0",</span><br/><span class="hl-2"> "message": {</span><br/><span class="hl-2"> "payload": "SGVsbG8sIFdha3Uh",</span><br/><span class="hl-2"> "contentTopic": "/toy-chat/2/huilong/proto",</span><br/><span class="hl-2"> "timestamp": 1712135330213797632</span><br/><span class="hl-2"> }</span><br/><span class="hl-2"> }'</span>
|
|
</code><button>Copy</button></pre>
|
|
<a id="md:example-executing-a-function" class="tsd-anchor"></a><h3><a href="#md:example-executing-a-function">Example: Executing a function</a></h3><pre><code class="language-bash"><span class="hl-0">curl</span><span class="hl-1"> </span><span class="hl-5">-X</span><span class="hl-1"> </span><span class="hl-2">POST</span><span class="hl-1"> </span><span class="hl-2">http://localhost:3000/execute</span><span class="hl-1"> </span><span class="hl-10">\</span><br/><span class="hl-1"> </span><span class="hl-5">-H</span><span class="hl-1"> </span><span class="hl-2">"Content-Type: application/json"</span><span class="hl-1"> </span><span class="hl-10">\</span><br/><span class="hl-1"> </span><span class="hl-5">-d</span><span class="hl-1"> </span><span class="hl-2">'{"functionName": "getPeerInfo", "params": []}'</span>
|
|
</code><button>Copy</button></pre>
|
|
<a id="md:example-creating-a-waku-node" class="tsd-anchor"></a><h3><a href="#md:example-creating-a-waku-node">Example: Creating a Waku node</a></h3><pre><code class="language-bash"><span class="hl-0">curl</span><span class="hl-1"> </span><span class="hl-5">-X</span><span class="hl-1"> </span><span class="hl-2">POST</span><span class="hl-1"> </span><span class="hl-2">http://localhost:3000/admin/v1/create-node</span><span class="hl-1"> </span><span class="hl-10">\</span><br/><span class="hl-1"> </span><span class="hl-5">-H</span><span class="hl-1"> </span><span class="hl-2">"Content-Type: application/json"</span><span class="hl-1"> </span><span class="hl-10">\</span><br/><span class="hl-1"> </span><span class="hl-5">-d</span><span class="hl-1"> </span><span class="hl-2">'{</span><br/><span class="hl-2"> "defaultBootstrap": true,</span><br/><span class="hl-2"> "networkConfig": {</span><br/><span class="hl-2"> "clusterId": 1,</span><br/><span class="hl-2"> "shards": [0, 1]</span><br/><span class="hl-2"> }</span><br/><span class="hl-2"> }'</span>
|
|
</code><button>Copy</button></pre>
|
|
<a id="md:example-starting-and-stopping-a-waku-node" class="tsd-anchor"></a><h3><a href="#md:example-starting-and-stopping-a-waku-node">Example: Starting and stopping a Waku node</a></h3><pre><code class="language-bash"><span class="hl-4"># Start the node</span><br/><span class="hl-0">curl</span><span class="hl-1"> </span><span class="hl-5">-X</span><span class="hl-1"> </span><span class="hl-2">POST</span><span class="hl-1"> </span><span class="hl-2">http://localhost:3000/admin/v1/start-node</span><br/><br/><span class="hl-4"># Stop the node</span><br/><span class="hl-0">curl</span><span class="hl-1"> </span><span class="hl-5">-X</span><span class="hl-1"> </span><span class="hl-2">POST</span><span class="hl-1"> </span><span class="hl-2">http://localhost:3000/admin/v1/stop-node</span>
|
|
</code><button>Copy</button></pre>
|
|
<a id="md:example-dialing-to-specific-peers-with-the-waku-rest-api-compatible-endpoint" class="tsd-anchor"></a><h3><a href="#md:example-dialing-to-specific-peers-with-the-waku-rest-api-compatible-endpoint">Example: Dialing to specific peers with the Waku REST API compatible endpoint</a></h3><pre><code class="language-bash"><span class="hl-0">curl</span><span class="hl-1"> </span><span class="hl-5">-X</span><span class="hl-1"> </span><span class="hl-2">POST</span><span class="hl-1"> </span><span class="hl-2">http://localhost:3000/admin/v1/peers</span><span class="hl-1"> </span><span class="hl-10">\</span><br/><span class="hl-1"> </span><span class="hl-5">-H</span><span class="hl-1"> </span><span class="hl-2">"Content-Type: application/json"</span><span class="hl-1"> </span><span class="hl-10">\</span><br/><span class="hl-1"> </span><span class="hl-5">-d</span><span class="hl-1"> </span><span class="hl-2">'{</span><br/><span class="hl-2"> "peerMultiaddrs": [</span><br/><span class="hl-2"> "/ip4/127.0.0.1/tcp/8000/p2p/16Uiu2HAm4v8KuHUH6Cwz3upPeQbkyxQJsFGPdt7kHtkN8F79QiE6"]</span><br/><span class="hl-2"> ]</span><br/><span class="hl-2"> }'</span>
|
|
</code><button>Copy</button></pre>
|
|
<a id="md:example-dialing-to-specific-peers-with-the-execute-endpoint" class="tsd-anchor"></a><h3><a href="#md:example-dialing-to-specific-peers-with-the-execute-endpoint">Example: Dialing to specific peers with the execute endpoint</a></h3><pre><code class="language-bash"><span class="hl-0">curl</span><span class="hl-1"> </span><span class="hl-5">-X</span><span class="hl-1"> </span><span class="hl-2">POST</span><span class="hl-1"> </span><span class="hl-2">http://localhost:3000/execute</span><span class="hl-1"> </span><span class="hl-10">\</span><br/><span class="hl-1"> </span><span class="hl-5">-H</span><span class="hl-1"> </span><span class="hl-2">"Content-Type: application/json"</span><span class="hl-1"> </span><span class="hl-10">\</span><br/><span class="hl-1"> </span><span class="hl-5">-d</span><span class="hl-1"> </span><span class="hl-2">'{</span><br/><span class="hl-2"> "functionName": "dialPeers", </span><br/><span class="hl-2"> "params": [</span><br/><span class="hl-2"> ["/ip4/127.0.0.1/tcp/8000/p2p/16Uiu2HAm4v8KuHUH6Cwz3upPeQbkyxQJsFGPdt7kHtkN8F79QiE6"]</span><br/><span class="hl-2"> ]</span><br/><span class="hl-2"> }'</span>
|
|
</code><button>Copy</button></pre>
|
|
<a id="md:example-subscribing-to-a-content-topic-with-the-filter-endpoint" class="tsd-anchor"></a><h3><a href="#md:example-subscribing-to-a-content-topic-with-the-filter-endpoint">Example: Subscribing to a content topic with the filter endpoint</a></h3><pre><code class="language-bash"><span class="hl-4"># Open a persistent connection to receive messages as Server-Sent Events</span><br/><span class="hl-0">curl</span><span class="hl-1"> </span><span class="hl-5">-N</span><span class="hl-1"> </span><span class="hl-2">http://localhost:3000/filter/v2/messages/%2Ftoy-chat%2F2%2Fhuilong%2Fproto</span><br/><br/><span class="hl-4"># You can also specify clustering options</span><br/><span class="hl-0">curl</span><span class="hl-1"> </span><span class="hl-5">-N</span><span class="hl-1"> </span><span class="hl-2">"http://localhost:3000/filter/v2/messages/%2Ftoy-chat%2F2%2Fhuilong%2Fproto?clusterId=0&shard=0"</span>
|
|
</code><button>Copy</button></pre>
|
|
<a id="md:example-retrieving-stored-messages-from-a-content-topic" class="tsd-anchor"></a><h3><a href="#md:example-retrieving-stored-messages-from-a-content-topic">Example: Retrieving stored messages from a content topic</a></h3><pre><code class="language-bash"><span class="hl-4"># Get the most recent 20 messages</span><br/><span class="hl-0">curl</span><span class="hl-1"> </span><span class="hl-2">http://localhost:3000/filter/v1/messages/%2Ftoy-chat%2F2%2Fhuilong%2Fproto</span><br/><br/><span class="hl-4"># Get messages with pagination and time filtering</span><br/><span class="hl-0">curl</span><span class="hl-1"> </span><span class="hl-2">"http://localhost:3000/filter/v1/messages/%2Ftoy-chat%2F2%2Fhuilong%2Fproto?pageSize=10&startTime=1712000000000&endTime=1713000000000&ascending=true"</span>
|
|
</code><button>Copy</button></pre>
|
|
<a id="md:extending" class="tsd-anchor"></a><h2><a href="#md:extending">Extending</a></h2><p>To add new functionality:</p>
|
|
<ol>
|
|
<li>Add your function to <code>src/api/shared.ts</code></li>
|
|
<li>Add your function to the <code>API</code> object in <code>src/api/shared.ts</code></li>
|
|
<li>Use it via the server endpoints</li>
|
|
</ol>
|
|
<a id="md:example-dialing-to-specific-peers" class="tsd-anchor"></a><h3><a href="#md:example-dialing-to-specific-peers">Example: Dialing to specific peers</a></h3><pre><code class="language-bash"><span class="hl-0">curl</span><span class="hl-1"> </span><span class="hl-5">-X</span><span class="hl-1"> </span><span class="hl-2">POST</span><span class="hl-1"> </span><span class="hl-2">http://localhost:3000/execute</span><span class="hl-1"> </span><span class="hl-10">\</span><br/><span class="hl-1"> </span><span class="hl-5">-H</span><span class="hl-1"> </span><span class="hl-2">"Content-Type: application/json"</span><span class="hl-1"> </span><span class="hl-10">\</span><br/><span class="hl-1"> </span><span class="hl-5">-d</span><span class="hl-1"> </span><span class="hl-2">'{</span><br/><span class="hl-2"> "functionName": "dialPeers", </span><br/><span class="hl-2"> "params": [</span><br/><span class="hl-2"> ["/ip4/127.0.0.1/tcp/8000/p2p/16Uiu2HAm4v8KuHUH6Cwz3upPeQbkyxQJsFGPdt7kHtkN8F79QiE6"]</span><br/><span class="hl-2"> ]</span><br/><span class="hl-2"> }'</span>
|
|
</code><button>Copy</button></pre>
|
|
</section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-index-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><h4 class="uppercase">Member Visibility</h4><form><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-private" name="private"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Private</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li></ul></form></div><div class="tsd-theme-toggle"><h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-index-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#md:waku-browser-tests"><span>Waku <wbr/>Browser <wbr/>Tests</span></a><ul><li><a href="#md:architecture"><span>Architecture</span></a></li><li><a href="#md:setup"><span>Setup</span></a></li><li><a href="#md:running"><span>Running</span></a></li><li><a href="#md:api-endpoints"><span>API <wbr/>Endpoints</span></a></li><li><ul><li><a href="#md:example-pushing-a-message-with-the-legacy-endpoint"><span>Example: <wbr/>Pushing a message with the legacy endpoint</span></a></li><li><a href="#md:example-pushing-a-message-with-the-waku-rest-api-compatible-endpoint"><span>Example: <wbr/>Pushing a message with the <wbr/>Waku REST API compatible endpoint</span></a></li><li><a href="#md:example-executing-a-function"><span>Example: <wbr/>Executing a function</span></a></li><li><a href="#md:example-creating-a-waku-node"><span>Example: <wbr/>Creating a <wbr/>Waku node</span></a></li><li><a href="#md:example-starting-and-stopping-a-waku-node"><span>Example: <wbr/>Starting and stopping a <wbr/>Waku node</span></a></li><li><a href="#md:example-dialing-to-specific-peers-with-the-waku-rest-api-compatible-endpoint"><span>Example: <wbr/>Dialing to specific peers with the <wbr/>Waku REST API compatible endpoint</span></a></li><li><a href="#md:example-dialing-to-specific-peers-with-the-execute-endpoint"><span>Example: <wbr/>Dialing to specific peers with the execute endpoint</span></a></li><li><a href="#md:example-subscribing-to-a-content-topic-with-the-filter-endpoint"><span>Example: <wbr/>Subscribing to a content topic with the filter endpoint</span></a></li><li><a href="#md:example-retrieving-stored-messages-from-a-content-topic"><span>Example: <wbr/>Retrieving stored messages from a content topic</span></a></li></ul></li><li><a href="#md:extending"><span>Extending</span></a></li><li><ul><li><a href="#md:example-dialing-to-specific-peers"><span>Example: <wbr/>Dialing to specific peers</span></a></li></ul></li></ul></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="../index.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1"></use></svg><span>Documentation</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base=".."><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html> |