Skip to content

Commit

Permalink
Support Deno 0.3.x (#2)
Browse files Browse the repository at this point in the history
* Upgrade deno_std to 0.3.4 and update tests.

* Travis CI: Upgrade deno to 0.3.7

* Fix formatting

* Use release tags for pinning dependencies
  • Loading branch information
nilsnh authored and sholladay committed Apr 16, 2019
1 parent 8c77079 commit 567e95b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: python

install:
- curl -fL https://deno.land/x/install/install.sh | sh -s v0.2.11
- curl -fL https://deno.land/x/install/install.sh | sh -s v0.3.7
- export PATH="$HOME/.deno/bin:$PATH"

script:
Expand Down
6 changes: 3 additions & 3 deletions dependencies.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * as http from 'https://deno.land/x/http@61a3911be7e01273e13bf35a3a16285f413f0b70/mod.ts';
export { Status as status } from 'https://deno.land/x/http@61a3911be7e01273e13bf35a3a16285f413f0b70/http_status.ts';
export { STATUS_TEXT as statusText } from 'https://deno.land/x/http@61a3911be7e01273e13bf35a3a16285f413f0b70/http_status.ts';
export * as http from 'https://deno.land/x/http@v0.3.4/server.ts';
export { Status as status } from 'https://deno.land/x/http@v0.3.4/http_status.ts';
export { STATUS_TEXT as statusText } from 'https://deno.land/x/http@v0.3.4/http_status.ts';
1 change: 1 addition & 0 deletions lib/respond.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ respond.notFound = (request, option) => {
status : status.NotFound
});
};

respond.badImplementation = (request, option) => {
return respond(request, {
body : {
Expand Down
3 changes: 3 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Pogo {
if (typeof config.handler !== 'function') {
throw new TypeError('route.handler must be a function');
}

this.router[config.method] = this.router[config.method] || {};
this.router[config.method][config.path] = config;
}
Expand All @@ -28,6 +29,7 @@ class Pogo {
await respond.notFound(request);
return;
}

let result;
try {
result = await route.handler(request, new Toolkit());
Expand All @@ -36,6 +38,7 @@ class Pogo {
await respond.badImplementation(request);
return;
}

if (result instanceof Toolkit) {
await respond(request, result._response);
}
Expand Down
15 changes: 8 additions & 7 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
import { assert, runTests, test } from 'https://deno.land/x/std/testing/mod.ts';
import { assertEquals, assertStrictEq } from 'https://deno.land/[email protected]/testing/asserts.ts';
import { runTests, test } from 'https://deno.land/[email protected]/testing/mod.ts';
import respond from './lib/respond.js';

test(async function respondsHtml() {
let called = false;
const fakeRequest = {
respond(config) {
called = true;
assert.equal(config.body, new TextEncoder().encode('hi'));
assert.strictEqual(config.headers.get('Content-Type'), 'text/html; charset=utf-8');
assertEquals(config.body, new TextEncoder().encode('hi'));
assertStrictEq(config.headers.get('Content-Type'), 'text/html; charset=utf-8');
}
};
await respond(fakeRequest, { body : 'hi' });
assert.strictEqual(called, true);
assertStrictEq(called, true);
});

test(async function respondsJson() {
let called = false;
const fakeRequest = {
respond(config) {
called = true;
assert.equal(config.body, new TextEncoder().encode(JSON.stringify({ foo : 'bar' })));
assert.strictEqual(config.headers.get('Content-Type'), 'application/json; charset=utf-8');
assertEquals(config.body, new TextEncoder().encode(JSON.stringify({ foo : 'bar' })));
assertStrictEq(config.headers.get('Content-Type'), 'application/json; charset=utf-8');
}
};
await respond(fakeRequest, {
body : {
foo : 'bar'
}
});
assert.strictEqual(called, true);
assertStrictEq(called, true);
});

runTests();

0 comments on commit 567e95b

Please sign in to comment.