Skip to content

Commit

Permalink
fix: bug in router when next is undefined
Browse files Browse the repository at this point in the history
fix: bug in url parser for FQDN and other combinations
fix: bug in etag generator not decoding Uint8Arrays
test: add test coverage that doesn't involve supertest

TODO: figure out how to get supertest / equivalent working with Deno
  • Loading branch information
asos-craigmorten committed May 23, 2020
1 parent fad29b2 commit de26da5
Show file tree
Hide file tree
Showing 58 changed files with 1,527 additions and 584 deletions.
12 changes: 12 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# ChangeLog

## [0.1.0] - 23-05-2020

### Added

- Test coverage for majority of code that doesn't require supertest.

### Updated

- fix: bug in router when next is undefined
- fix: bug in url parser for FQDN and other combinations
- fix: bug in etag generator not decoding Uint8Arrays

## [0.0.4] - 22-05-2020

### Added
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ update-lock:
@deno run --lock=lock.json --lock-write --reload mod.ts

test:
@deno test ./test
@deno test --allow-net ./test/units/

typedoc:
@typedoc --ignoreCompilerErrors --out ./docs --mode modules --includeDeclarations --excludeExternals --includes ./typings/index.d.ts ./src
66 changes: 0 additions & 66 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* Module dependencies
*/
export {
serve,
serveTLS,
Expand Down Expand Up @@ -32,66 +29,3 @@ export {
to as getEvent,
} from "https://deno.land/x/evt@v1.6.8/mod.ts";
export { contentType } from "https://deno.land/x/media_types@v2.3.1/mod.ts";

/**
* Test dependencies
*/
export { expect } from "https://deno.land/x/expect@9effa6c6da3bcf4b66114b44e6b1662e85c91337/mod.ts";

export const TEST_TIMEOUT = 3000;

/**
* A no-op _describe_ method.
*
* @param name
* @param fn
*/
export async function describe(name: string, fn: () => void | Promise<void>) {
fn();
}

/**
* An _it_ wrapper around `Deno.test`.
*
* @param name
* @param fn
*/
export async function it(
name: string,
fn: (done?: any) => void | Promise<void>,
) {
Deno.test(name, async () => {
let done: any = () => {};
let race: Promise<unknown> = Promise.resolve();

if (fn.length === 1) {
let resolve: () => void;
const donePromise = new Promise((r) => {
resolve = r;
});

let timeoutId: number;

race = Promise.race([
new Promise((_, reject) =>
timeoutId = setTimeout(() => {
reject(
new Error(
`test "${name}" failed to complete by calling "done" within ${TEST_TIMEOUT}ms.`,
),
);
}, TEST_TIMEOUT)
),
donePromise,
]);

done = () => {
clearTimeout(timeoutId);
resolve();
};
}

await fn(done);
await race;
});
}
2 changes: 1 addition & 1 deletion docs/assets/js/search.json

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions docs/classes/_response_.response.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ <h3>app</h3>
<div class="tsd-signature tsd-kind-icon">app<span class="tsd-signature-symbol">:</span> <a href="../interfaces/_types_.application.html" class="tsd-signature-type">Application</a></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L32">response.ts:32</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L32">response.ts:32</a></li>
</ul>
</aside>
</section>
Expand All @@ -148,7 +148,7 @@ <h3>body</h3>
<div class="tsd-signature tsd-kind-icon">body<span class="tsd-signature-symbol">:</span> <a href="../modules/_types_.html#denoresponsebody" class="tsd-signature-type">DenoResponseBody</a></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L31">response.ts:31</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L31">response.ts:31</a></li>
</ul>
</aside>
</section>
Expand All @@ -158,7 +158,7 @@ <h3>headers</h3>
<div class="tsd-signature tsd-kind-icon">headers<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Headers</span><span class="tsd-signature-symbol"> = new Headers()</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L30">response.ts:30</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L30">response.ts:30</a></li>
</ul>
</aside>
</section>
Expand All @@ -168,7 +168,7 @@ <h3>locals</h3>
<div class="tsd-signature tsd-kind-icon">locals<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">any</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L34">response.ts:34</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L34">response.ts:34</a></li>
</ul>
</aside>
</section>
Expand All @@ -178,7 +178,7 @@ <h3>req</h3>
<div class="tsd-signature tsd-kind-icon">req<span class="tsd-signature-symbol">:</span> <a href="../interfaces/_types_.request.html" class="tsd-signature-type">Request</a></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L33">response.ts:33</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L33">response.ts:33</a></li>
</ul>
</aside>
</section>
Expand All @@ -188,7 +188,7 @@ <h3>status</h3>
<div class="tsd-signature tsd-kind-icon">status<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Status</span><span class="tsd-signature-symbol"> = 200</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L29">response.ts:29</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L29">response.ts:29</a></li>
</ul>
</aside>
</section>
Expand All @@ -205,7 +205,7 @@ <h3>append</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L49">response.ts:49</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L49">response.ts:49</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -240,7 +240,7 @@ <h3>attachment</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L62">response.ts:62</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L62">response.ts:62</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -269,7 +269,7 @@ <h3>clear<wbr>Cookie</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L101">response.ts:101</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L101">response.ts:101</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -298,7 +298,7 @@ <h3>cookie</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L84">response.ts:84</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L84">response.ts:84</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -330,7 +330,7 @@ <h3>download</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L124">response.ts:124</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L124">response.ts:124</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -366,7 +366,7 @@ <h3>end</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L149">response.ts:149</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L149">response.ts:149</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -394,7 +394,7 @@ <h3>etag</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L166">response.ts:166</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L166">response.ts:166</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -427,7 +427,7 @@ <h3>get</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L189">response.ts:189</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L189">response.ts:189</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -456,7 +456,7 @@ <h3>json</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L205">response.ts:205</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L205">response.ts:205</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -488,7 +488,7 @@ <h3>jsonp</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L231">response.ts:231</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L231">response.ts:231</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -520,7 +520,7 @@ <h3>links</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L281">response.ts:281</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L281">response.ts:281</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -554,7 +554,7 @@ <h3>location</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L311">response.ts:311</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L311">response.ts:311</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -589,7 +589,7 @@ <h3>send</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L334">response.ts:334</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L334">response.ts:334</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -621,7 +621,7 @@ <h3>send<wbr>File</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L401">response.ts:401</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L401">response.ts:401</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -650,7 +650,7 @@ <h3>send<wbr>Status</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L442">response.ts:442</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L442">response.ts:442</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -684,7 +684,7 @@ <h3>set</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L464">response.ts:464</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L464">response.ts:464</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -719,7 +719,7 @@ <h3>set<wbr>Status</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L486">response.ts:486</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L486">response.ts:486</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -750,7 +750,7 @@ <h3>type</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L507">response.ts:507</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L507">response.ts:507</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -785,7 +785,7 @@ <h3>unset</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/7401279/src/response.ts#L520">response.ts:520</a></li>
<li>Defined in <a href="https://github.com/asos-craigmorten/opine/blob/fad29b2/src/response.ts#L520">response.ts:520</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
Loading

0 comments on commit de26da5

Please sign in to comment.