From a7f0b0dbe7258913abe3f2e4b6b6c9dff7661708 Mon Sep 17 00:00:00 2001 From: Adam Faur Date: Tue, 14 Jul 2020 23:47:02 -0700 Subject: [PATCH 1/5] update deps update delCookie to deleteCookie --- dependencies.ts | 8 ++++---- lib/response.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dependencies.ts b/dependencies.ts index b38d516..008cc63 100644 --- a/dependencies.ts +++ b/dependencies.ts @@ -2,11 +2,11 @@ import React from 'https://jspm.dev/react@16.13.1'; // @deno-types="https://deno.land/x/types/react-dom/v16.13.1/server.d.ts" import ReactDOMServer from 'https://jspm.dev/react-dom@16.13.1/server'; -import * as cookie from 'https://deno.land/std@v0.56.0/http/cookie.ts'; -import * as http from 'https://deno.land/std@v0.56.0/http/server.ts'; -import { Status as status, STATUS_TEXT as statusText } from 'https://deno.land/std@v0.56.0/http/http_status.ts'; +import * as cookie from 'https://deno.land/std@v0.61.0/http/cookie.ts'; +import * as http from 'https://deno.land/std@v0.61.0/http/server.ts'; +import { Status as status, STATUS_TEXT as statusText } from 'https://deno.land/std@v0.61.0/http/http_status.ts'; import * as mime from 'https://cdn.pika.dev/mime-types@2.1.27'; -import * as path from 'https://deno.land/std@v0.56.0/path/mod.ts'; +import * as path from 'https://deno.land/std@v0.61.0/path/mod.ts'; export { React, diff --git a/lib/response.ts b/lib/response.ts index 80dfd92..cb3edad 100644 --- a/lib/response.ts +++ b/lib/response.ts @@ -95,7 +95,7 @@ export default class Response { return this.header('Content-Type', mediaType); } unstate(name: string) { - cookie.delCookie(this as object, name); + cookie.deleteCookie(this as object, name); return this; } } From 1779a58898144f3ceb5dc3bedfb3ae047e860860 Mon Sep 17 00:00:00 2001 From: Adam Faur Date: Wed, 15 Jul 2020 00:51:09 -0700 Subject: [PATCH 2/5] update supported version in readme upgrade assert version alias assertStrictEqual as assertStrictEq --- README.md | 2 +- dev-dependencies.ts | 6 +++--- example/simple-server/dev-dependencies.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 80487a6..0245ff1 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Pogo is an easy-to-use, safe, and expressive framework for writing web servers a [Documentation](./docs) -*Supports Deno v1.0.0 and higher.* +*Supports Deno v1.2.0 and higher.* ## Contents diff --git a/dev-dependencies.ts b/dev-dependencies.ts index f1bb129..df450aa 100644 --- a/dev-dependencies.ts +++ b/dev-dependencies.ts @@ -1,11 +1,11 @@ import { assert, assertEquals, - assertStrictEq -} from 'https://deno.land/std@v0.56.0/testing/asserts.ts'; + assertStrictEquals +} from 'https://deno.land/std@v0.61.0/testing/asserts.ts'; export { assert, assertEquals, - assertStrictEq + assertStrictEquals as assertStrictEq }; diff --git a/example/simple-server/dev-dependencies.ts b/example/simple-server/dev-dependencies.ts index b3c6ab5..9d746b9 100644 --- a/example/simple-server/dev-dependencies.ts +++ b/example/simple-server/dev-dependencies.ts @@ -1,4 +1,4 @@ -import { assertEquals, assertStrictEq } from 'https://deno.land/std@v0.56.0/testing/asserts.ts'; +import { assertEquals, assertStrictEq } from 'https://deno.land/std@v0.61.0/testing/asserts.ts'; export { assertEquals, From 5644cc85221161d2ae520e3198f751a7a38a4cf0 Mon Sep 17 00:00:00 2001 From: Adam Faur Date: Wed, 15 Jul 2020 01:02:01 -0700 Subject: [PATCH 3/5] remove type assertions --- lib/request.ts | 2 +- lib/response.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/request.ts b/lib/request.ts index 89b35f4..ae60cc2 100644 --- a/lib/request.ts +++ b/lib/request.ts @@ -29,7 +29,7 @@ export default class Request { this.referrer = this.headers.get('referer') || ''; this.response = new Response(); this.server = options.server; - this.state = cookie.getCookies(this as any); + this.state = cookie.getCookies(this); this.url = new URL(this.raw.url, 'http://' + this.headers.get('host')); } get body() { diff --git a/lib/response.ts b/lib/response.ts index cb3edad..51b1da4 100644 --- a/lib/response.ts +++ b/lib/response.ts @@ -82,7 +82,7 @@ export default class Response { state(name: cookie.Cookie): this; state(name: string, value: string | CookieOptions): this; state(name: string | cookie.Cookie, value?: string | CookieOptions) { - cookie.setCookie(this as object, { + cookie.setCookie(this, { httpOnly : true, sameSite : 'Strict', secure : true, @@ -95,7 +95,7 @@ export default class Response { return this.header('Content-Type', mediaType); } unstate(name: string) { - cookie.deleteCookie(this as object, name); + cookie.deleteCookie(this, name); return this; } } From b9a5dc6833762d55162ee826ae3501f89adb9230 Mon Sep 17 00:00:00 2001 From: Adam Faur Date: Wed, 15 Jul 2020 01:03:17 -0700 Subject: [PATCH 4/5] update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cc91d78..d5ec334 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: python install: - - curl -fsSL https://deno.land/x/install/install.sh | sh -s v1.1.1 + - curl -fsSL https://deno.land/x/install/install.sh | sh -s v1.2.0 - export PATH="$HOME/.deno/bin:$PATH" script: From 87ca153410abc3634b604eec275add1023547195 Mon Sep 17 00:00:00 2001 From: Seth Holladay Date: Thu, 16 Jul 2020 00:02:53 -0400 Subject: [PATCH 5/5] Update imports --- dev-dependencies.ts | 12 +- example/react-on-server/dev-dependencies.ts | 2 +- example/simple-server/test.js | 8 +- test/bang.js | 30 ++-- test/request.js | 110 ++++++------ test/response.js | 62 +++---- test/server.jsx | 182 ++++++++++---------- test/toolkit.js | 48 +++--- 8 files changed, 222 insertions(+), 232 deletions(-) diff --git a/dev-dependencies.ts b/dev-dependencies.ts index df450aa..33bc66b 100644 --- a/dev-dependencies.ts +++ b/dev-dependencies.ts @@ -1,11 +1 @@ -import { - assert, - assertEquals, - assertStrictEquals -} from 'https://deno.land/std@v0.61.0/testing/asserts.ts'; - -export { - assert, - assertEquals, - assertStrictEquals as assertStrictEq -}; +export * from 'https://deno.land/std@v0.61.0/testing/asserts.ts'; diff --git a/example/react-on-server/dev-dependencies.ts b/example/react-on-server/dev-dependencies.ts index 6d40b0f..33bc66b 100644 --- a/example/react-on-server/dev-dependencies.ts +++ b/example/react-on-server/dev-dependencies.ts @@ -1 +1 @@ -export * from 'https://deno.land/std@v0.60.0/testing/asserts.ts'; +export * from 'https://deno.land/std@v0.61.0/testing/asserts.ts'; diff --git a/example/simple-server/test.js b/example/simple-server/test.js index 0d3c037..259d282 100644 --- a/example/simple-server/test.js +++ b/example/simple-server/test.js @@ -1,4 +1,4 @@ -import { assertStrictEq } from './dev-dependencies.ts'; +import { assertStrictEquals } from './dev-dependencies.ts'; import server from './main.ts'; const { test } = Deno; @@ -8,7 +8,7 @@ test('GET /', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(response.body, 'Hello, world!'); + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(response.body, 'Hello, world!'); }); diff --git a/test/bang.js b/test/bang.js index c059197..9d282c8 100644 --- a/test/bang.js +++ b/test/bang.js @@ -1,7 +1,7 @@ import { assert, assertEquals, - assertStrictEq + assertStrictEquals } from '../dev-dependencies.ts'; import Response from '../lib/response.ts'; import * as bang from '../lib/bang.ts'; @@ -12,9 +12,9 @@ test('new Bang() is a 500 error by default', () => { const error = new bang.Bang(); assert(error instanceof Error); assert(error instanceof bang.Bang); - assertStrictEq(error.message, 'Internal Server Error'); + assertStrictEquals(error.message, 'Internal Server Error'); assert(error.response instanceof Response); - assertStrictEq(error.response.status, 500); + assertStrictEquals(error.response.status, 500); assertEquals(error.response.body, { error : 'Internal Server Error', message : 'Internal Server Error', @@ -25,8 +25,8 @@ test('new Bang() is a 500 error by default', () => { test('new Bang() with custom message', () => { const error = new bang.Bang('some problem'); assert(error instanceof Error); - assertStrictEq(error.message, 'some problem'); - assertStrictEq(error.response.status, 500); + assertStrictEquals(error.message, 'some problem'); + assertStrictEquals(error.response.status, 500); assertEquals(error.response.body, { error : 'Internal Server Error', message : 'Internal Server Error', @@ -37,8 +37,8 @@ test('new Bang() with custom message', () => { test('new Bang() with custom message and explicit 500 status', () => { const error = new bang.Bang('some problem', { status : 500 }); assert(error instanceof Error); - assertStrictEq(error.message, 'some problem'); - assertStrictEq(error.response.status, 500); + assertStrictEquals(error.message, 'some problem'); + assertStrictEquals(error.response.status, 500); assertEquals(error.response.body, { error : 'Internal Server Error', message : 'Internal Server Error', @@ -49,8 +49,8 @@ test('new Bang() with custom message and explicit 500 status', () => { test('new Bang() with custom message and 501 status', () => { const error = new bang.Bang('some problem', { status : 501 }); assert(error instanceof Error); - assertStrictEq(error.message, 'some problem'); - assertStrictEq(error.response.status, 501); + assertStrictEquals(error.message, 'some problem'); + assertStrictEquals(error.response.status, 501); assertEquals(error.response.body, { error : 'Not Implemented', message : 'some problem', @@ -61,8 +61,8 @@ test('new Bang() with custom message and 501 status', () => { test('new Bang() with error', () => { const error = new bang.Bang(new Error('some problem')); assert(error instanceof Error); - assertStrictEq(error.message, 'some problem'); - assertStrictEq(error.response.status, 500); + assertStrictEquals(error.message, 'some problem'); + assertStrictEquals(error.response.status, 500); assertEquals(error.response.body, { error : 'Internal Server Error', message : 'Internal Server Error', @@ -73,8 +73,8 @@ test('new Bang() with error', () => { test('new Bang() with error and 501 status', () => { const error = new bang.Bang(new Error('some problem'), { status : 501 }); assert(error instanceof Error); - assertStrictEq(error.message, 'some problem'); - assertStrictEq(error.response.status, 501); + assertStrictEquals(error.message, 'some problem'); + assertStrictEquals(error.response.status, 501); assertEquals(error.response.body, { error : 'Not Implemented', message : 'some problem', @@ -84,11 +84,11 @@ test('new Bang() with error and 501 status', () => { test('Bang.wrap() returns Bang instance as-is', () => { const error = new bang.Bang(); - assertStrictEq(bang.Bang.wrap(error), error); + assertStrictEquals(bang.Bang.wrap(error), error); }); test('Bang.wrap() constructs new Bang from string', () => { const error = bang.Bang.wrap('hello'); assertEquals(error, new bang.Bang('hello')); - assertStrictEq(error.constructor, bang.Bang); + assertStrictEquals(error.constructor, bang.Bang); }); diff --git a/test/request.js b/test/request.js index 47316fd..dbdb250 100644 --- a/test/request.js +++ b/test/request.js @@ -1,4 +1,4 @@ -import { assertStrictEq } from '../dev-dependencies.ts'; +import { assertStrictEquals } from '../dev-dependencies.ts'; import Response from '../lib/response.ts'; import Server from '../lib/server.ts'; import pogo from '../main.ts'; @@ -22,9 +22,9 @@ test('request.headers is a Headers instance', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ isHeadersInstance : true, hostHeader : 'localhost', type : 'object' @@ -49,9 +49,9 @@ test('request.host is a hostname and port', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ isSameAsHeader : true, isSameAsUrl : true, type : 'string', @@ -77,9 +77,9 @@ test('request.hostname is a domain or IP address', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ isInHostHeader : true, isSameAsUrl : true, type : 'string', @@ -104,9 +104,9 @@ test('request.href is a full URL string', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ isSameAsUrl : true, type : 'string', value : 'http://localhost/' @@ -129,9 +129,9 @@ test('request.method is an HTTP method', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ isGet : true, type : 'string' })); @@ -154,9 +154,9 @@ test('request.origin is a protocol and host', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ isSameAsUrl : true, type : 'string', value : 'http://localhost' @@ -180,9 +180,9 @@ test('request.params contains path variables', async () => { method : 'GET', url : '/users/123' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ type : 'object', userId : '123', value : { @@ -208,9 +208,9 @@ test('request.path is a URL path string', async () => { method : 'GET', url : '/?query' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ isSameAsUrl : true, type : 'string', value : '/' @@ -233,9 +233,9 @@ test('request.raw is the original request', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ isGet : true, type : 'object' })); @@ -266,16 +266,16 @@ test('request.referrer is a referrer URL string', async () => { referer : 'https://example.com' }) }); - assertStrictEq(withoutResponse.status, 200); - assertStrictEq(withoutResponse.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(withoutResponse.body, JSON.stringify({ + assertStrictEquals(withoutResponse.status, 200); + assertStrictEquals(withoutResponse.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(withoutResponse.body, JSON.stringify({ isRefererHeader : false, type : 'string', value : '' })); - assertStrictEq(withResponse.status, 200); - assertStrictEq(withResponse.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(withResponse.body, JSON.stringify({ + assertStrictEquals(withResponse.status, 200); + assertStrictEquals(withResponse.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(withResponse.body, JSON.stringify({ isRefererHeader : true, type : 'string', value : 'https://example.com' @@ -298,9 +298,9 @@ test('request.response is a Response instance', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ isResponseInstance : true, type : 'object' })); @@ -326,9 +326,9 @@ test('request.route is a router record', async () => { method : 'GET', url : '/status' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ handlerType : 'function', method : '*', params : { @@ -357,9 +357,9 @@ test('request.search is a URL search string', async () => { method : 'GET', url : '/?query' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ isSameAsUrl : true, type : 'string', value : '?query' @@ -384,9 +384,9 @@ test('request.searchParams is a URLSearchParams instance', async () => { method : 'GET', url : '/?query' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ asString : 'query=', isSameAsUrl : true, isParamsInstance : true, @@ -410,9 +410,9 @@ test('request.server is a Server instance', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ isServerInstance : true, type : 'object' })); @@ -438,9 +438,9 @@ test('request.state is an object with cookies', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ science : 'rocket', type : 'object', value : { @@ -467,9 +467,9 @@ test('request.url is a URL instance', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ asString : 'http://localhost/', href : 'http://localhost/', isUrlInstance : true, diff --git a/test/response.js b/test/response.js index 395d649..ffc914d 100644 --- a/test/response.js +++ b/test/response.js @@ -1,4 +1,4 @@ -import { assertStrictEq } from '../dev-dependencies.ts'; +import { assertStrictEquals } from '../dev-dependencies.ts'; import pogo from '../main.ts'; const { test } = Deno; @@ -16,9 +16,9 @@ test('response.code() set status code', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 418); - assertStrictEq(response.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(response.body, 'hi'); + assertStrictEquals(response.status, 418); + assertStrictEquals(response.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(response.body, 'hi'); }); test('response.created() set status and location', async () => { @@ -45,14 +45,14 @@ test('response.created() set status and location', async () => { method : 'GET', url : '/with-location' }); - assertStrictEq(responseNoLocation.status, 201); - assertStrictEq(responseNoLocation.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(responseNoLocation.headers.has('location'), false); - assertStrictEq(responseNoLocation.body, 'one'); - assertStrictEq(responseWithLocation.status, 201); - assertStrictEq(responseWithLocation.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(responseWithLocation.headers.get('location'), '/yay'); - assertStrictEq(responseWithLocation.body, 'two'); + assertStrictEquals(responseNoLocation.status, 201); + assertStrictEquals(responseNoLocation.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(responseNoLocation.headers.has('location'), false); + assertStrictEquals(responseNoLocation.body, 'one'); + assertStrictEquals(responseWithLocation.status, 201); + assertStrictEquals(responseWithLocation.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(responseWithLocation.headers.get('location'), '/yay'); + assertStrictEquals(responseWithLocation.body, 'two'); }); test('response.header() set custom header', async () => { @@ -68,10 +68,10 @@ test('response.header() set custom header', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(response.headers.get('x-dog'), 'woof'); - assertStrictEq(response.body, 'hi'); + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(response.headers.get('x-dog'), 'woof'); + assertStrictEquals(response.body, 'hi'); }); test('response.location() set location header', async () => { @@ -87,10 +87,10 @@ test('response.location() set location header', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(response.headers.get('location'), '/over-the-rainbow'); - assertStrictEq(response.body, 'hi'); + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(response.headers.get('location'), '/over-the-rainbow'); + assertStrictEquals(response.body, 'hi'); }); test('response.state() set cookie', async () => { @@ -106,10 +106,10 @@ test('response.state() set cookie', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(response.headers.get('set-cookie'), 'sesh=nomnomnom; Secure; HttpOnly; SameSite=Strict'); - assertStrictEq(response.body, ''); + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(response.headers.get('set-cookie'), 'sesh=nomnomnom; Secure; HttpOnly; SameSite=Strict'); + assertStrictEquals(response.body, ''); }); test('response.type() override default content-type handling', async () => { @@ -125,9 +125,9 @@ test('response.type() override default content-type handling', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'weird/type'); - assertStrictEq(response.body, JSON.stringify({ hello : 'world' })); + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'weird/type'); + assertStrictEquals(response.body, JSON.stringify({ hello : 'world' })); }); test('response.unstate() clear cookie', async () => { @@ -143,8 +143,8 @@ test('response.unstate() clear cookie', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(response.headers.get('set-cookie'), 'mwahaha=; Expires=Thu, 01 Jan 1970 00:00:00 GMT'); - assertStrictEq(response.body, ''); + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(response.headers.get('set-cookie'), 'mwahaha=; Expires=Thu, 01 Jan 1970 00:00:00 GMT'); + assertStrictEquals(response.body, ''); }); diff --git a/test/server.jsx b/test/server.jsx index 805f548..9457ba4 100644 --- a/test/server.jsx +++ b/test/server.jsx @@ -1,5 +1,5 @@ import { React } from '../dependencies.ts'; -import { assertEquals, assertStrictEq } from '../dev-dependencies.ts'; +import { assertEquals, assertStrictEquals } from '../dev-dependencies.ts'; import * as bang from '../lib/bang.ts'; import pogo from '../main.ts'; @@ -20,10 +20,10 @@ test('server.route() HTML response for string', async () => { method : 'GET', url : '/' }); - assertStrictEq(called, true); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(response.body, 'hi'); + assertStrictEquals(called, true); + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(response.body, 'hi'); }); test('server.route() HTML response for JSX', async () => { @@ -41,10 +41,10 @@ test('server.route() HTML response for JSX', async () => { method : 'GET', url : '/' }); - assertStrictEq(called, true); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(response.body, '

Supports JSX

'); + assertStrictEquals(called, true); + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(response.body, '

Supports JSX

'); }); test('server.route() returns Uint8Array', async () => { @@ -62,9 +62,9 @@ test('server.route() returns Uint8Array', async () => { method : 'GET', url : '/' }); - assertStrictEq(called, true); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.has('content-type'), false); + assertStrictEquals(called, true); + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.has('content-type'), false); assertEquals(response.body, new TextEncoder().encode('Hello')); }); @@ -83,10 +83,10 @@ test('server.route() JSON response for plain object', async () => { method : 'GET', url : '/' }); - assertStrictEq(called, true); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ foo : 'bar' })); + assertStrictEquals(called, true); + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ foo : 'bar' })); }); test('server.route() JSON response for boolean', async () => { @@ -113,12 +113,12 @@ test('server.route() JSON response for boolean', async () => { method : 'GET', url : '/true' }); - assertStrictEq(responseFalse.status, 200); - assertStrictEq(responseFalse.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(responseFalse.body, JSON.stringify(false)); - assertStrictEq(responseTrue.status, 200); - assertStrictEq(responseTrue.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(responseTrue.body, JSON.stringify(true)); + assertStrictEquals(responseFalse.status, 200); + assertStrictEquals(responseFalse.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(responseFalse.body, JSON.stringify(false)); + assertStrictEquals(responseTrue.status, 200); + assertStrictEquals(responseTrue.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(responseTrue.body, JSON.stringify(true)); }); test('server.route() JSON response for number', async () => { @@ -145,12 +145,12 @@ test('server.route() JSON response for number', async () => { method : 'GET', url : '/one' }); - assertStrictEq(responseZero.status, 200); - assertStrictEq(responseZero.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(responseZero.body, JSON.stringify(0)); - assertStrictEq(responseOne.status, 200); - assertStrictEq(responseOne.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(responseOne.body, JSON.stringify(1)); + assertStrictEquals(responseZero.status, 200); + assertStrictEquals(responseZero.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(responseZero.body, JSON.stringify(0)); + assertStrictEquals(responseOne.status, 200); + assertStrictEquals(responseOne.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(responseOne.body, JSON.stringify(1)); }); test('server.route() empty response for null', async () => { @@ -166,9 +166,9 @@ test('server.route() empty response for null', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.has('content-type'), false); - assertStrictEq(response.body, ''); + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.has('content-type'), false); + assertStrictEquals(response.body, ''); }); test('server.route() error response for undefined', async () => { @@ -184,9 +184,9 @@ test('server.route() error response for undefined', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 500); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 500); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ error : 'Internal Server Error', message : 'Internal Server Error', status : 500 @@ -206,9 +206,9 @@ test('server.route() with dynamic path', async () => { method : 'GET', url : '/users/123' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ userId : '123' })); + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ userId : '123' })); }); test('server.route() can be chained', async () => { @@ -236,12 +236,12 @@ test('server.route() can be chained', async () => { method : 'GET', url : '/b' }); - assertStrictEq(responseA.status, 200); - assertStrictEq(responseA.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(responseA.body, 'a'); - assertStrictEq(responseB.status, 200); - assertStrictEq(responseB.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(responseB.body, 'b'); + assertStrictEquals(responseA.status, 200); + assertStrictEquals(responseA.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(responseA.body, 'a'); + assertStrictEquals(responseB.status, 200); + assertStrictEquals(responseB.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(responseB.body, 'b'); }); test('server.route() array of routes', async () => { @@ -270,12 +270,12 @@ test('server.route() array of routes', async () => { method : 'GET', url : '/b' }); - assertStrictEq(responseA.status, 200); - assertStrictEq(responseA.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(responseA.body, 'a'); - assertStrictEq(responseB.status, 200); - assertStrictEq(responseB.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(responseB.body, 'b'); + assertStrictEquals(responseA.status, 200); + assertStrictEquals(responseA.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(responseA.body, 'a'); + assertStrictEquals(responseB.status, 200); + assertStrictEquals(responseB.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(responseB.body, 'b'); }); test('server.route() array of methods', async () => { @@ -299,15 +299,15 @@ test('server.route() array of methods', async () => { method : 'PUT', url : '/hello' }); - assertStrictEq(getResponse.status, 200); - assertStrictEq(getResponse.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(getResponse.body, 'Hi, GET'); - assertStrictEq(postResponse.status, 200); - assertStrictEq(postResponse.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(postResponse.body, 'Hi, POST'); - assertStrictEq(putResponse.status, 404); - assertStrictEq(putResponse.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(putResponse.body, JSON.stringify({ + assertStrictEquals(getResponse.status, 200); + assertStrictEquals(getResponse.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(getResponse.body, 'Hi, GET'); + assertStrictEquals(postResponse.status, 200); + assertStrictEquals(postResponse.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(postResponse.body, 'Hi, POST'); + assertStrictEquals(putResponse.status, 404); + assertStrictEquals(putResponse.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(putResponse.body, JSON.stringify({ error : 'Not Found', message : 'Not Found', status : 404 @@ -335,15 +335,15 @@ test('server.route() wildcard method', async () => { method : 'PUT', url : '/hello' }); - assertStrictEq(getResponse.status, 200); - assertStrictEq(getResponse.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(getResponse.body, 'Hi, GET'); - assertStrictEq(postResponse.status, 200); - assertStrictEq(postResponse.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(postResponse.body, 'Hi, POST'); - assertStrictEq(putResponse.status, 200); - assertStrictEq(putResponse.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(putResponse.body, 'Hi, PUT'); + assertStrictEquals(getResponse.status, 200); + assertStrictEquals(getResponse.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(getResponse.body, 'Hi, GET'); + assertStrictEquals(postResponse.status, 200); + assertStrictEquals(postResponse.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(postResponse.body, 'Hi, POST'); + assertStrictEquals(putResponse.status, 200); + assertStrictEquals(putResponse.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(putResponse.body, 'Hi, PUT'); }); test('server.route() handler returns Error', async () => { @@ -359,9 +359,9 @@ test('server.route() handler returns Error', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 500); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 500); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ error : 'Internal Server Error', message : 'Internal Server Error', status : 500 @@ -381,9 +381,9 @@ test('server.route() handler throws Error', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 500); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 500); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ error : 'Internal Server Error', message : 'Internal Server Error', status : 500 @@ -403,9 +403,9 @@ test('server.route() handler returns bang.badRequest()', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 400); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 400); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ error : 'Bad Request', message : 'Crazyyy', status : 400 @@ -425,9 +425,9 @@ test('server.route() handler throws bang.badRequest()', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 400); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ + assertStrictEquals(response.status, 400); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ error : 'Bad Request', message : 'Crazyyy', status : 400 @@ -463,16 +463,16 @@ test('server catchAll option', async () => { method : 'POST', url : '/void' }); - assertStrictEq(getHelloResponse.status, 200); - assertStrictEq(getHelloResponse.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(getHelloResponse.body, 'Hi, GET'); - assertStrictEq(getRootResponse.status, 418); - assertStrictEq(getRootResponse.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(getRootResponse.body, 'Custom fallback, GET'); - assertStrictEq(getVoidResponse.status, 418); - assertStrictEq(getVoidResponse.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(getVoidResponse.body, 'Custom fallback, GET'); - assertStrictEq(postVoidResponse.status, 418); - assertStrictEq(postVoidResponse.headers.get('content-type'), 'text/html; charset=utf-8'); - assertStrictEq(postVoidResponse.body, 'Custom fallback, POST'); + assertStrictEquals(getHelloResponse.status, 200); + assertStrictEquals(getHelloResponse.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(getHelloResponse.body, 'Hi, GET'); + assertStrictEquals(getRootResponse.status, 418); + assertStrictEquals(getRootResponse.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(getRootResponse.body, 'Custom fallback, GET'); + assertStrictEquals(getVoidResponse.status, 418); + assertStrictEquals(getVoidResponse.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(getVoidResponse.body, 'Custom fallback, GET'); + assertStrictEquals(postVoidResponse.status, 418); + assertStrictEquals(postVoidResponse.headers.get('content-type'), 'text/html; charset=utf-8'); + assertStrictEquals(postVoidResponse.body, 'Custom fallback, POST'); }); diff --git a/test/toolkit.js b/test/toolkit.js index 04efc41..5eeeb22 100644 --- a/test/toolkit.js +++ b/test/toolkit.js @@ -1,4 +1,4 @@ -import { assertEquals, assertStrictEq } from '../dev-dependencies.ts'; +import { assertEquals, assertStrictEquals } from '../dev-dependencies.ts'; import pogo from '../main.ts'; const { test } = Deno; @@ -16,9 +16,9 @@ test('h.response() set JSON body', async () => { method : 'GET', url : '/' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); - assertStrictEq(response.body, JSON.stringify({ hello : 'world' })); + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.body, JSON.stringify({ hello : 'world' })); }); test('h.redirect()', async () => { @@ -67,22 +67,22 @@ test('h.redirect()', async () => { method : 'GET', url : '/permanent-no-rewrite' }); - assertStrictEq(responseOne.status, 302); - assertStrictEq(responseOne.headers.get('content-type'), null); - assertStrictEq(responseOne.headers.get('location'), '/one'); - assertStrictEq(responseOne.body, ''); - assertStrictEq(responseTwo.status, 307); - assertStrictEq(responseTwo.headers.get('content-type'), null); - assertStrictEq(responseTwo.headers.get('location'), '/two'); - assertStrictEq(responseTwo.body, ''); - assertStrictEq(responseThree.status, 301); - assertStrictEq(responseThree.headers.get('content-type'), null); - assertStrictEq(responseThree.headers.get('location'), '/three'); - assertStrictEq(responseThree.body, ''); - assertStrictEq(responseFour.status, 308); - assertStrictEq(responseFour.headers.get('content-type'), null); - assertStrictEq(responseFour.headers.get('location'), '/four'); - assertStrictEq(responseFour.body, ''); + assertStrictEquals(responseOne.status, 302); + assertStrictEquals(responseOne.headers.get('content-type'), null); + assertStrictEquals(responseOne.headers.get('location'), '/one'); + assertStrictEquals(responseOne.body, ''); + assertStrictEquals(responseTwo.status, 307); + assertStrictEquals(responseTwo.headers.get('content-type'), null); + assertStrictEquals(responseTwo.headers.get('location'), '/two'); + assertStrictEquals(responseTwo.body, ''); + assertStrictEquals(responseThree.status, 301); + assertStrictEquals(responseThree.headers.get('content-type'), null); + assertStrictEquals(responseThree.headers.get('location'), '/three'); + assertStrictEquals(responseThree.body, ''); + assertStrictEquals(responseFour.status, 308); + assertStrictEquals(responseFour.headers.get('content-type'), null); + assertStrictEquals(responseFour.headers.get('location'), '/four'); + assertStrictEquals(responseFour.body, ''); }); test('h.file()', async () => { @@ -98,8 +98,8 @@ test('h.file()', async () => { method : 'GET', url : '/names' }); - assertStrictEq(response.status, 200); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.status, 200); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); assertEquals(response.body, new TextEncoder().encode('[\n "Alice",\n "Bob",\n "Cara"\n]\n')); }); @@ -116,8 +116,8 @@ test('h.file() outside default confine', async () => { method : 'GET', url : '/forbid' }); - assertStrictEq(response.status, 403); - assertStrictEq(response.headers.get('content-type'), 'application/json; charset=utf-8'); + assertStrictEquals(response.status, 403); + assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8'); assertEquals(response.body, JSON.stringify({ error : 'Forbidden', message : 'Forbidden',