From c05b28a9f41fcb8cdf8894e36a5825f171933d9e Mon Sep 17 00:00:00 2001 From: JP Sugarbroad Date: Sat, 29 May 2021 19:46:59 -0700 Subject: [PATCH 1/2] Add missing yarn devDependency --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 4af3b455..0615a4c9 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "rimraf": "^3.0.2", "terser": "^5.7.0", "vite": "^2.3.0", + "yarn": "^1.22.10", "yarn-release": "^1.10.3" } } From e152b70761ebc67b618c8c8ddecd42d7a6c67629 Mon Sep 17 00:00:00 2001 From: JP Sugarbroad Date: Sat, 29 May 2021 19:49:19 -0700 Subject: [PATCH 2/2] Make all handle calls await --- src/itty-router.spec.js | 44 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/itty-router.spec.js b/src/itty-router.spec.js index 8465e9ac..bbad9070 100644 --- a/src/itty-router.spec.js +++ b/src/itty-router.spec.js @@ -69,9 +69,9 @@ describe('Router', () => { describe('.handle({ method = \'GET\', url })', () => { - it('returns { path, query } from match', () => { + it('returns { path, query } from match', async () => { const route = routes.find(r => r.path === '/foo/:id') - router.handle(buildRequest({ path: '/foo/13?foo=bar&cat=dog' })) + await router.handle(buildRequest({ path: '/foo/13?foo=bar&cat=dog' })) expect(route.callback).toHaveReturnedWith({ params: { id: '13' }, @@ -79,10 +79,10 @@ describe('Router', () => { }) }) - it('requires exact route match', () => { + it('requires exact route match', async () => { const route = routes.find(r => r.path === '/') - router.handle(buildRequest({ path: '/foo' })) + await router.handle(buildRequest({ path: '/foo' })) expect(route.callback).not.toHaveBeenCalled() }) @@ -166,33 +166,33 @@ describe('Router', () => { expect(handler).toHaveReturnedWith('domain.dev') }) - it('match earliest routes that match', () => { + it('match earliest routes that match', async () => { const route = routes.find(r => r.path === '/foo/first') - router.handle(buildRequest({ path: '/foo/first' })) + await router.handle(buildRequest({ path: '/foo/first' })) expect(route.callback).toHaveBeenCalled() }) - it('honors correct method (e.g. GET, POST, etc)', () => { + it('honors correct method (e.g. GET, POST, etc)', async () => { const route = routes.find(r => r.path === '/foo' && r.method === 'post') - router.handle(buildRequest({ method: 'POST', path: '/foo' })) + await router.handle(buildRequest({ method: 'POST', path: '/foo' })) expect(route.callback).toHaveBeenCalled() }) - it('handles optional params (e.g. /foo/:id?)', () => { + it('handles optional params (e.g. /foo/:id?)', async () => { const route = routes.find(r => r.path === '/optional/:id?') - router.handle(buildRequest({ path: '/optional' })) + await router.handle(buildRequest({ path: '/optional' })) expect(route.callback).toHaveBeenCalled() - router.handle(buildRequest({ path: '/optional/13' })) + await router.handle(buildRequest({ path: '/optional/13' })) expect(route.callback).toHaveBeenCalledTimes(2) }) - it('passes the entire original request through to the handler', () => { + it('passes the entire original request through to the handler', async () => { const route = routes.find(r => r.path === '/passthrough') - router.handle(buildRequest({ path: '/passthrough', name: 'miffles' })) + await router.handle(buildRequest({ path: '/passthrough', name: 'miffles' })) expect(route.callback).toHaveReturnedWith({ path: '/passthrough', @@ -200,19 +200,19 @@ describe('Router', () => { }) }) - it('accepts * as a wildcard route (e.g. for use in 404)', () => { + it('accepts * as a wildcard route (e.g. for use in 404)', async () => { const route = routes.find(r => r.path === '*') - router.handle(buildRequest({ path: '/missing' })) + await router.handle(buildRequest({ path: '/missing' })) expect(route.callback).toHaveBeenCalled() const route2 = routes.find(r => r.path === '/wildcards/*') - router.handle(buildRequest({ path: '/wildcards/missing' })) + await router.handle(buildRequest({ path: '/wildcards/missing' })) expect(route2.callback).toHaveBeenCalled() }) - it('allows missing handler later in flow with "all" channel', () => { + it('allows missing handler later in flow with "all" channel', async () => { const missingHandler = jest.fn() const matchHandler = jest.fn() @@ -224,16 +224,16 @@ describe('Router', () => { .all('/nested/*', router2.handle) .all('*', missingHandler) - router1.handle(buildRequest({ path: '/foo' })) + await router1.handle(buildRequest({ path: '/foo' })) expect(missingHandler).toHaveBeenCalled() - router1.handle(buildRequest({ path: '/nested/foo' })) + await router1.handle(buildRequest({ path: '/nested/foo' })) expect(matchHandler).toHaveBeenCalled() }) - it('defaults to GET assumption when handling new requests without { method: \'METHOD\' }', () => { + it('defaults to GET assumption when handling new requests without { method: \'METHOD\' }', async () => { const route = routes.find(r => r.path === '/foo') - router.handle({ url: 'https://example.com/foo' }) // no method listed + await router.handle({ url: 'https://example.com/foo' }) // no method listed expect(route.callback).toHaveBeenCalled() }) @@ -265,7 +265,7 @@ describe('Router', () => { const handler = jest.fn() router.get('/foo/:id?', handler) - router.handle(buildRequest({ path: '/api/foo' })) + await router.handle(buildRequest({ path: '/api/foo' })) expect(handler).toHaveBeenCalled() await router.handle(buildRequest({ path: '/api/foo/13' }))