Skip to main content
Module

x/superoak/docs/index.html

HTTP assertions for Oak made easy via SuperDeno. ๐Ÿฟ ๐Ÿฆ•
Go to Latest
File
<!doctype html><html class="default no-js"><head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>superoak</title> <meta name="description" content="Documentation for superoak"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="assets/css/main.css"></head><body><header> <div class="tsd-page-toolbar"> <div class="container"> <div class="table-wrap"> <div class="table-cell" id="tsd-search" data-index="assets/js/search.json" data-base="."> <div class="field"> <label for="tsd-search-field" class="tsd-widget search no-caption">Search</label> <input id="tsd-search-field" type="text" /> </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">superoak</a> </div> <div class="table-cell" id="tsd-widgets"> <div id="tsd-filter"> <a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a> <div class="tsd-filter-group"> <div class="tsd-select" id="tsd-filter-visibility"> <span class="tsd-select-label">All</span> <ul class="tsd-select-list"> <li data-value="public">Public</li> <li data-value="protected">Public/Protected</li> <li data-value="private" class="selected">All</li> </ul> </div> <input type="checkbox" id="tsd-filter-inherited" checked /> <label class="tsd-widget" for="tsd-filter-inherited">Inherited</label> <input type="checkbox" id="tsd-filter-only-exported" /> <label class="tsd-widget" for="tsd-filter-only-exported">Only exported</label> </div> </div> <a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a> </div> </div> </div> </div> <div class="tsd-page-title"> <div class="container"> <ul class="tsd-breadcrumb"> <li> <a href="globals.html">Globals</a> </li> </ul> <h1>superoak</h1> </div> </div></header><div class="container container-main"> <div class="row"> <div class="col-8 col-content"> <div class="tsd-panel tsd-typography"> <p align="center"> <a href="https://www.linkedin.com/in/hannah-morten-b1218017a/"><img height="200" style="height: 200px;" src="https://github.com/asos-craigmorten/superoak/raw/main/.github/icon.png" alt="Super Oak standing in the rain at night โ€“ stoically facing the dark battle that is software engineering"></a> <h1 align="center">SuperOak</h1> </p> <p align="center"> HTTP assertions for Deno's Oak web framework made easy via <a href="https://github.com/asos-craigmorten/superdeno">SuperDeno</a>. </p> <p align="center"> <a href="https://github.com/asos-craigmorten/superoak/tags/"><img src="https://img.shields.io/github/tag/asos-craigmorten/superoak" alt="Current version" /></a> <img src="https://github.com/asos-craigmorten/superoak/workflows/Test/badge.svg" alt="Current test status" /> <a href="https://doc.deno.land/https/deno.land/x/superoak/mod.ts"><img src="https://doc.deno.land/badge.svg" alt="SuperOak docs" /></a> <a href="http://makeapullrequest.com"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs are welcome" /></a> <a href="https://github.com/asos-craigmorten/superoak/issues/"><img src="https://img.shields.io/github/issues/asos-craigmorten/superoak" alt="SuperOak issues" /></a> <img src="https://img.shields.io/github/stars/asos-craigmorten/superoak" alt="SuperOak stars" /> <img src="https://img.shields.io/github/forks/asos-craigmorten/superoak" alt="SuperOak forks" /> <img src="https://img.shields.io/github/license/asos-craigmorten/superoak" alt="SuperOak license" /> <a href="https://GitHub.com/asos-craigmorten/superoak/graphs/commit-activity"><img src="https://img.shields.io/badge/Maintained%3F-yes-green.svg" alt="SuperOak is maintained" /></a> <a href="http://hits.dwyl.com/asos-craigmorten/superoak"><img src="http://hits.dwyl.com/asos-craigmorten/superoak.svg" alt="SuperOak repository visit count" /></a> </p> <hr> <a href="#table-of-contents" id="table-of-contents" style="color: inherit; text-decoration: none;"> <h2>Table of Contents</h2> </a> <ul> <li><a href="#about">About</a></li> <li><a href="#installation">Installation</a></li> <li><a href="#example">Example</a></li> <li><a href="#documentation">Documentation</a></li> <li><a href="#api">API</a></li> <li><a href="#notes">Notes</a></li> <li><a href="#contributing">Contributing</a></li> <li><a href="#license">License</a></li> </ul> <a href="#about" id="about" style="color: inherit; text-decoration: none;"> <h2>About</h2> </a> <p>This module aims to provide a high-level abstraction for testing HTTP in Deno&#39;s Oak web framework. This is a wrapper compatibility layer around <a href="https://github.com/asos-craigmorten/superdeno">SuperDeno</a> to reduce some of the boilerplate needed to setup Oak integration + functional tests.</p> <a href="#installation" id="installation" style="color: inherit; text-decoration: none;"> <h2>Installation</h2> </a> <p>This is a <a href="https://deno.land/">Deno</a> module available to import direct from this repo and via the <a href="https://deno.land/x">Deno Registry</a>.</p> <p>Before importing, <a href="https://deno.land/#installation">download and install Deno</a>.</p> <p>You can then import SuperOak straight into your project:</p> <pre><code class="language-ts"><span class="hljs-keyword">import</span> { superoak } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;https://deno.land/x/superoak@2.1.0/mod.ts&quot;</span>;</code></pre> <p>SuperOak is also available on <a href="https://nest.land/package/superoak">nest.land</a>, a package registry for Deno on the Blockchain.</p> <pre><code class="language-ts"><span class="hljs-keyword">import</span> { superoak } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;https://x.nest.land/superoak@2.1.0/mod.ts&quot;</span>;</code></pre> <a href="#example" id="example" style="color: inherit; text-decoration: none;"> <h2>Example</h2> </a> <p>You may pass a url string (for an already running Oak server), or an Oak <code>Application</code> object to <code>superoak()</code> - when passing an Oak <code>Application</code>, SuperOak will automatically handle the creation of a server, binding to a free ephemeral port and closing of the server on a call to <code>.end()</code>.</p> <p>SuperOak works with any Deno test framework. Here&#39;s an example with Deno&#39;s built-in test framework.</p> <pre><code class="language-ts"><span class="hljs-keyword">import</span> { Application, Router } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;https://deno.land/x/oak@v6.0.1/mod.ts&quot;</span>;<span class="hljs-keyword">import</span> { superoak } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;https://deno.land/x/superoak@2.1.0/mod.ts&quot;</span>;
<span class="hljs-keyword">const</span> router = <span class="hljs-keyword">new</span> Router();router.get(<span class="hljs-string">&quot;/&quot;</span>, <span class="hljs-function">(<span class="hljs-params">ctx</span>) =&gt;</span> { ctx.response.body = <span class="hljs-string">&quot;Hello Deno!&quot;</span>;});
<span class="hljs-keyword">const</span> app = <span class="hljs-keyword">new</span> Application();app.use(router.routes());app.use(router.allowedMethods());
Deno.test(<span class="hljs-string">&quot;it should support the Oak framework&quot;</span>, <span class="hljs-keyword">async</span> () =&gt; { <span class="hljs-keyword">const</span> request = <span class="hljs-keyword">await</span> superoak(app); <span class="hljs-keyword">await</span> request.get(<span class="hljs-string">&quot;/&quot;</span>).expect(<span class="hljs-string">&quot;Hello Deno!&quot;</span>);});</code></pre> <p>Save the above to a file <code>demo.test.ts</code> and test it using <code>deno test --allow-net demo.test.ts</code>.</p> <p>For further examples, see the <a href="https://github.com/asos-craigmorten/superoak/blob/main/examples/README.md">SuperOak examples</a>, <a href="https://github.com/asos-craigmorten/superoak/blob/main/test/superoak.test.ts">tests</a> or the <a href="https://github.com/asos-craigmorten/superdeno#example">SuperDeno examples</a> for inspiration.</p> <a href="#documentation" id="documentation" style="color: inherit; text-decoration: none;"> <h2>Documentation</h2> </a> <ul> <li><a href="https://asos-craigmorten.github.io/superoak/">SuperOak Type Docs</a></li> <li><a href="https://doc.deno.land/https/deno.land/x/superoak/mod.ts">SuperOak Deno Docs</a></li> <li><a href="https://github.com/asos-craigmorten/superoak/blob/main/examples/README.md">SuperOak Examples</a></li> <li><a href="https://github.com/asos-craigmorten/superoak/blob/main/LICENSE.md">License</a></li> <li><a href="https://github.com/asos-craigmorten/superoak/blob/main/.github/CHANGELOG.md">Changelog</a></li> </ul> <a href="#api" id="api" style="color: inherit; text-decoration: none;"> <h2>API</h2> </a> <p>Please refer to the <a href="https://github.com/asos-craigmorten/superdeno#api">SuperDeno API</a>.</p> <a href="#notes" id="notes" style="color: inherit; text-decoration: none;"> <h2>Notes</h2> </a> <ul> <li><p>Unlike <a href="https://github.com/asos-craigmorten/superdeno">SuperDeno</a>, <code>superoak()</code> returns a promise which will need to be awaited before you can call a method such as <code>.get(&quot;/&quot;)</code>.</p> </li> <li><p>Unlike <a href="https://github.com/asos-craigmorten/superdeno">SuperDeno</a>, you cannot re-use a SuperOak instance once the chained <code>.end()</code> method has been called. This is because SuperOak will automatically close the server once the chained <code>.end()</code> method is called. Instead you should make all of your assertions on the one SuperOak instance, or create a new SuperOak instance like below:</p> <pre><code class="language-ts"><span class="hljs-keyword">import</span> { Application, Router } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;https://deno.land/x/oak@v6.0.1/mod.ts&quot;</span>;<span class="hljs-keyword">import</span> { superoak } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;https://deno.land/x/superoak@2.1.0/mod.ts&quot;</span>;
<span class="hljs-keyword">const</span> router = <span class="hljs-keyword">new</span> Router();<span class="hljs-keyword">const</span> app = <span class="hljs-keyword">new</span> Application();
router.get(<span class="hljs-string">&quot;/&quot;</span>, <span class="hljs-function">(<span class="hljs-params">ctx</span>) =&gt;</span> { ctx.response.body = <span class="hljs-string">&quot;Hello Deno!&quot;</span>;});
app.use(router.routes());app.use(router.allowedMethods());
Deno.test( <span class="hljs-string">&quot;it will allow your to make multiple assertions on one SuperOak instance&quot;</span>, <span class="hljs-keyword">async</span> () =&gt; { <span class="hljs-keyword">let</span> request = <span class="hljs-keyword">await</span> superoak(app);
<span class="hljs-keyword">await</span> request.get(<span class="hljs-string">&quot;/&quot;</span>).expect(<span class="hljs-number">200</span>).expect(<span class="hljs-string">&quot;Hello Deno!&quot;</span>); });
Deno.test( <span class="hljs-string">&quot;it will allow your to re-use the Application for another SuperOak instance&quot;</span>, <span class="hljs-keyword">async</span> () =&gt; { <span class="hljs-keyword">let</span> request = <span class="hljs-keyword">await</span> superoak(app);
<span class="hljs-keyword">await</span> request.get(<span class="hljs-string">&quot;/&quot;</span>).expect(<span class="hljs-number">200</span>);
request = <span class="hljs-keyword">await</span> superoak(app);
<span class="hljs-keyword">await</span> request.get(<span class="hljs-string">&quot;/&quot;</span>).expect(<span class="hljs-string">&quot;Hello Deno!&quot;</span>); });</code></pre> </li> </ul> <a href="#contributing" id="contributing" style="color: inherit; text-decoration: none;"> <h2>Contributing</h2> </a> <p><a href="https://github.com/asos-craigmorten/superoak/blob/main/.github/CONTRIBUTING.md">Contributing guide</a></p> <hr> <a href="#license" id="license" style="color: inherit; text-decoration: none;"> <h2>License</h2> </a> <p>SuperOak is licensed under the <a href="./LICENSE.md">MIT License</a>.</p> <p>Icon designed and created by <a href="https://www.linkedin.com/in/hannah-morten-b1218017a/">Hannah Morten</a>.</p> </div> </div> <div class="col-4 col-menu menu-sticky-wrap menu-highlight"> <nav class="tsd-navigation primary"> <ul> <li class="globals "> <a href="globals.html"><em>Globals</em></a> </li> <li class=" tsd-kind-module"> <a href="modules/_superoak_.html">&quot;superoak&quot;</a> </li> </ul> </nav> <nav class="tsd-navigation secondary menu-sticky"> <ul class="before-current"> </ul> </nav> </div> </div></div><footer class="with-border-bottom"> <div class="container"> <h2>Legend</h2> <div class="tsd-legend-group"> <ul class="tsd-legend"> <li class="tsd-kind-function"><span class="tsd-kind-icon">Function</span></li> </ul> </div> </div></footer><div class="container tsd-generator"> <p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div><div class="overlay"></div><script src="assets/js/main.js"></script></body></html>