-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Achieve 100% test coverage #349
Changes from 20 commits
e39091e
0ab4156
c9ccb25
b34c360
9bb5967
26b6214
8a86282
81c1e12
ed9aa9f
f028a10
84c1541
3467d7c
03bd828
d9decb9
3c3785d
96c367b
3ba9e4b
8788748
7cc5bb0
6e6f03e
1c29f91
4370ccb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
ts: false | ||
jsx: false | ||
flow: false | ||
branches: 90 | ||
functions: 90 | ||
lines: 90 | ||
statements: 90 | ||
flow: false |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -344,7 +344,6 @@ Router.prototype.findRoute = function findNode (method, path, constraints = {}) | |
const isRegexParam = charCode === 40 | ||
const isStaticPart = charCode === 45 || charCode === 46 | ||
const isEndOfNode = charCode === 47 || j === pattern.length | ||
|
||
if (isRegexParam || isStaticPart || isEndOfNode) { | ||
const paramName = pattern.slice(lastParamStartIndex, j) | ||
params.push(paramName) | ||
|
@@ -407,9 +406,7 @@ Router.prototype.findRoute = function findNode (method, path, constraints = {}) | |
// add the wildcard parameter | ||
params.push('*') | ||
currentNode = currentNode.getWildcardChild() | ||
if (currentNode === null) { | ||
return null | ||
} | ||
|
||
parentNodePathIndex = i + 1 | ||
|
||
if (i !== pattern.length - 1) { | ||
|
@@ -422,10 +419,6 @@ Router.prototype.findRoute = function findNode (method, path, constraints = {}) | |
pattern = pattern.toLowerCase() | ||
} | ||
|
||
if (pattern === '*') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uncovered branch. Can't find a good reason why |
||
pattern = '/*' | ||
} | ||
|
||
for (const existRoute of this.routes) { | ||
const routeConstraints = existRoute.opts.constraints || {} | ||
if ( | ||
|
@@ -436,7 +429,7 @@ Router.prototype.findRoute = function findNode (method, path, constraints = {}) | |
return { | ||
handler: existRoute.handler, | ||
store: existRoute.store, | ||
params: existRoute.params || [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uncovered branch.
|
||
params: existRoute.params | ||
} | ||
} | ||
} | ||
|
@@ -625,7 +618,6 @@ Router.prototype.find = function find (method, path, derivedConstraints) { | |
|
||
currentNode = node | ||
|
||
// static route | ||
mcollina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (currentNode.kind === NODE_TYPES.STATIC) { | ||
pathIndex += currentNode.prefix.length | ||
continue | ||
|
@@ -642,37 +634,36 @@ Router.prototype.find = function find (method, path, derivedConstraints) { | |
continue | ||
} | ||
|
||
if (currentNode.kind === NODE_TYPES.PARAMETRIC) { | ||
let paramEndIndex = originPath.indexOf('/', pathIndex) | ||
if (paramEndIndex === -1) { | ||
paramEndIndex = pathLen | ||
} | ||
// parametric node | ||
let paramEndIndex = originPath.indexOf('/', pathIndex) | ||
if (paramEndIndex === -1) { | ||
paramEndIndex = pathLen | ||
} | ||
|
||
let param = originPath.slice(pathIndex, paramEndIndex) | ||
if (shouldDecodeParam) { | ||
param = safeDecodeURIComponent(param) | ||
} | ||
let param = originPath.slice(pathIndex, paramEndIndex) | ||
if (shouldDecodeParam) { | ||
param = safeDecodeURIComponent(param) | ||
} | ||
|
||
if (currentNode.isRegex) { | ||
const matchedParameters = currentNode.regex.exec(param) | ||
if (matchedParameters === null) continue | ||
if (currentNode.isRegex) { | ||
const matchedParameters = currentNode.regex.exec(param) | ||
if (matchedParameters === null) continue | ||
|
||
for (let i = 1; i < matchedParameters.length; i++) { | ||
const matchedParam = matchedParameters[i] | ||
if (matchedParam.length > maxParamLength) { | ||
return null | ||
} | ||
params.push(matchedParam) | ||
} | ||
} else { | ||
if (param.length > maxParamLength) { | ||
for (let i = 1; i < matchedParameters.length; i++) { | ||
const matchedParam = matchedParameters[i] | ||
if (matchedParam.length > maxParamLength) { | ||
return null | ||
} | ||
params.push(param) | ||
params.push(matchedParam) | ||
} | ||
|
||
pathIndex = paramEndIndex | ||
} else { | ||
if (param.length > maxParamLength) { | ||
return null | ||
} | ||
params.push(param) | ||
} | ||
|
||
pathIndex = paramEndIndex | ||
} | ||
} | ||
|
||
|
@@ -742,8 +733,6 @@ for (const i in httpMethods) { | |
const m = httpMethods[i] | ||
const methodName = m.toLowerCase() | ||
|
||
if (Router.prototype[methodName]) throw new Error('Method already exists: ' + methodName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uncovered branch. I think |
||
|
||
Router.prototype[methodName] = function (path, handler, store) { | ||
return this.on(m, path, handler, store) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,10 +153,8 @@ class Constrainer { | |
if (!strategy.isCustom) { | ||
if (key === 'version') { | ||
lines.push(' version: req.headers[\'accept-version\'],') | ||
} else if (key === 'host') { | ||
lines.push(' host: req.headers.host || req.headers[\':authority\'],') | ||
} else { | ||
throw new Error('unknown non-custom strategy for compiling constraint derivation function') | ||
lines.push(' host: req.headers.host || req.headers[\':authority\'],') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uncovered branch. How can we accidentally inject a builtin strategy or forget to manage it? |
||
} | ||
} else { | ||
lines.push(` ${strategy.name}: this.strategies.${key}.deriveConstraint(req, ctx),`) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,11 @@ SemVerStore.prototype.set = function (version, store) { | |
} | ||
let [major, minor, patch] = version.split('.') | ||
|
||
major = Number(major) || 0 | ||
if (isNaN(major)) { | ||
throw new TypeError('Major version must be a numeric value') | ||
mcollina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
major = Number(major) | ||
minor = Number(minor) || 0 | ||
patch = Number(patch) || 0 | ||
|
||
|
@@ -38,7 +42,7 @@ SemVerStore.prototype.set = function (version, store) { | |
this.store[`${major}.x.x`] = store | ||
} | ||
|
||
if (patch >= (this.store[`${major}.${minor}`] || 0)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's an error here, but curiously no one seems to have noticed, right? |
||
if (patch >= (this.maxPatches[`${major}.${minor}`] || 0)) { | ||
this.maxPatches[`${major}.${minor}`] = patch | ||
this.store[`${major}.${minor}.x`] = store | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
"chalk": "^4.1.2", | ||
"inquirer": "^8.2.4", | ||
"pre-commit": "^1.2.2", | ||
"proxyquire": "^2.1.3", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw it has a dependency of Fastify, so I tough it could be welcome here. |
||
"rfdc": "^1.3.0", | ||
"simple-git": "^3.7.1", | ||
"standard": "^14.3.4", | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -3,6 +3,7 @@ | |||
const t = require('tap') | ||||
const test = t.test | ||||
const FindMyWay = require('..') | ||||
const rfdc = require('rfdc')({ proto: true }) | ||||
|
||||
const customHeaderConstraint = { | ||||
name: 'requestedBy', | ||||
|
@@ -23,11 +24,14 @@ const customHeaderConstraint = { | |||
} | ||||
} | ||||
|
||||
test('should derive async constraint', t => { | ||||
test('should derive multiple async constraints', t => { | ||||
t.plan(2) | ||||
|
||||
const router = FindMyWay({ constraints: { requestedBy: customHeaderConstraint } }) | ||||
router.on('GET', '/', { constraints: { requestedBy: 'node' } }, () => 'asyncHandler') | ||||
const customHeaderConstraint2 = rfdc(customHeaderConstraint) | ||||
customHeaderConstraint2.name = 'requestedBy2' | ||||
|
||||
const router = FindMyWay({ constraints: { requestedBy: customHeaderConstraint, requestedBy2: customHeaderConstraint2 } }) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To evaluate this branch: find-my-way/lib/constrainer.js Line 135 in c4ffd9e
|
||||
router.on('GET', '/', { constraints: { requestedBy: 'node', requestedBy2: 'node' } }, () => 'asyncHandler') | ||||
|
||||
router.lookup( | ||||
{ | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uncovered branch.
Can't find a good reason why this could be null using apis.