Pass the tests
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Yusuke Wada · committed by Yusuke Wada · parent 072196c · Browse files · 6 files·+24 added−7 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+24 added−7 removed
- tests:+13 added−1 removed
- other:+11 added−6 removed
Provenance
- Commit
b70bfb0- Tree
cb92695- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
Yusuke Wada <yusuke@kamawada.com>- Parent
072196c
6 files changed+24 added−7 removed
modified:src/hono.js+5 added-1 removed
13 unmodified lines14151617181819202123 unmodified lines4546474849505152535455565758596061626379 unmodified lines13 unmodified lines this.node.insert(method, path, handlers) }
match(method, path) { method = method.toLowerCase() return this.node.search(method, path) }}
23 unmodified lines this.middlewareRouter = new Router() this.middlewareRouters = [] }
getRouter() { return this.router }
addRoute(method, path, ...args) { this.router.add(method, path, ...args) return WrappedApp(this) }
matchRoute(method, path) { method = method.toLowerCase() return this.router.match(method, path) }
route(path) {79 unmodified linesmodified:src/node.js+4 added-3 removed
1+'use strict'2+3 const { splitPath, getPattern, getParamName } = require('./util')4 5 const METHOD_NAME_OF_ALL = 'all'6 13 unmodified lines20 21 insert(method, path, handler) {22 let curNode = this23 for (const p of splitPath(path)) {22- const nextNode = curNode.children[p]23- if (nextNode) {24- curNode = nextNode24+ if (Object.keys(curNode.children).includes(p)) {25+ curNode = curNode.children[p]26 continue27 }28 curNode.children[p] = new Node({29 label: p,67 unmodified linesmodified:src/node.test.js+8 added
79 unmodified lines80 expect(res.handler).toBe('get comment')81 expect(res.params['id']).toBe('789')82 expect(res.params['comment_id']).toBe('123')83 })84+85+ it('get /map/:location/events', () => {86+ node.insert('get', '/map/:location/events', 'get events')87+ let res = node.search('get', '/map/yokohama/events')88+ expect(res).not.toBeNull()89+ expect(res.handler).toBe('get events')90+ expect(res.params['location']).toBe('yokohama')91+ })92 })93 94 describe('Wildcard', () => {95 const node = new Node()44 unmodified linesmodified:src/router.test.js+1 added-1 removed
1 const App = require('./hono')2 3 describe('Basic Usage', () => {4- let router = App()4+ const router = App()5 6 it('get, post hello', () => {7 router.get('/hello', 'get hello')8 router.post('/hello', 'post hello')76 unmodified linesmodified:src/util.test.js+4 added
10 unmodified lines11121314151617181920212212 unmodified lines10 unmodified lines ps = splitPath('/wildcard-abc/*/wildcard-efg') expect(ps[0]).toBe('wildcard-abc') expect(ps[1]).toBe('*') expect(ps[2]).toBe('wildcard-efg') ps = splitPath('/map/:location/events') expect(ps[0]).toBe('map') expect(ps[1]).toBe(':location') expect(ps[2]).toBe('events') })
it('getPattern', () => { let res = getPattern(':id')12 unmodified linesmodified:package.json+2 added-2 removed
2 unmodified lines3456778910114 unmodified lines1617181920202 unmodified lines "version": "0.0.4", "description": "Minimal web framework for Cloudflare Workers", "main": "src/hono.js", "scripts": { "test": "jest --verbose" "test": "jest" }, "author": "Yusuke Wada <yusuke@kamawada.com> (https://github.com/yusukebe)", "license": "MIT", "repository": {4 unmodified lines "devDependencies": { "jest": "^27.4.5", "node-fetch": "^2.6.6" }}No newline at end of file}