-
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
Achieve 100% test coverage #349
Conversation
test: findMyWay.findRoute should also trows an error when wildcard is not the last character test: does not find the route if maxParamLength is exceeded refactor: make integration test more compliant with the existing code base test: cover uncovered constrainer.js test cases test: safeDecodeURIComponent should replace %3x to null for every x that is not a valid lowchar test: SemVerStore version should be a string test: httpMethodStrategy storage handles set and get operations correctly test: case insensitive static routes of level 1 for FindMyWay.findRoute test: findRoute normalizes wildcard patterns to require leading slash refactor: make tests more consistants with the existing test: should return null if no wildchar child Date: Tue Feb 20 14:10:18 2024 +0100 Achieves 100% test coverage
You should make them all green. They are yellow because the lines are covered, but the branches of those conditions are not. |
Still have some work to do... But maybe someone can answers these questions.
test('throws error if pass an undefined constraint value', (t) => {
t.plan(1)
const constrainer = new Constrainer()
const error = new Error('Can\'t pass an undefined constraint value, must pass null or no key at all')
t.throws(() => constrainer.validateConstraints({ key: undefined }), error)
}) Or do I have to test through apis?
test('findRoute normalizes wildcard patterns with leading slash', (t) => {
t.plan(4)
const findMyWay = FindMyWay()
findMyWay.get('*', () => {})
t.equal(findMyWay.routes.length, 1)
// will match with leading slash
t.equal(findMyWay.routes[0].pattern, '/*')
t.ok(findMyWay.findRoute('GET', '*'))
// will fail if we remove it
findMyWay.routes[0].pattern = '*'
t.equal(findMyWay.findRoute('GET', '*'), null)
})
|
…ttern with a leading slash
…er break internals
|
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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Uncovered branch.
I think httpMethods
should be a trusted source: if it contains duplicates, the tests will fail in one way or another.
} 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 comment
The 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?
@@ -407,9 +406,7 @@ Router.prototype.findRoute = function findNode (method, path, constraints = {}) | |||
// add the wildcard parameter | |||
params.push('*') | |||
currentNode = currentNode.getWildcardChild() | |||
if (currentNode === null) { |
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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Uncovered branch.
Can't find a good reason why pattern
could be *
using apis.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Uncovered branch.
route.params
is assigned as an array and never reassigned, do I miss something?
@@ -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 comment
The 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?
@@ -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 comment
The 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.
https://github.com/fastify/fastify/blob/7e50e5307c9a6593a2e43171912630033aa1aacb/package.json#L189
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 comment
The 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
if (--asyncConstraintsCount === 0) { |
once you are done, remove the last 4 lines from https://github.com/delvedor/find-my-way/blob/main/.taprc. In that way it will fail the test suit if the coverage falls again. |
100% reached, minimal limits removed. |
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.
Thanks. I'm a bit worried about the changes in the router's behaviour. I will take a deep look into them next week.
I'd also appreciate feedback on how you'd test these lines if you prefer I reintroduce them. |
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.
lgtm with a nit
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [find-my-way](https://togithub.com/delvedor/find-my-way) | [`8.1.0` -> `8.2.0`](https://renovatebot.com/diffs/npm/find-my-way/8.1.0/8.2.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/find-my-way/8.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/find-my-way/8.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/find-my-way/8.1.0/8.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/find-my-way/8.1.0/8.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>delvedor/find-my-way (find-my-way)</summary> ### [`v8.2.0`](https://togithub.com/delvedor/find-my-way/releases/tag/v8.2.0) [Compare Source](https://togithub.com/delvedor/find-my-way/compare/v8.1.0...v8.2.0) #### What's Changed - Update contraint check to throw with 32 handlers by [@​valeneiko](https://togithub.com/valeneiko) in [https://github.com/delvedor/find-my-way/pull/344](https://togithub.com/delvedor/find-my-way/pull/344) - feat: add node: prefix for assert by [@​SavaCool122](https://togithub.com/SavaCool122) in [https://github.com/delvedor/find-my-way/pull/347](https://togithub.com/delvedor/find-my-way/pull/347) - add dependabot.yml by [@​Uzlopak](https://togithub.com/Uzlopak) in [https://github.com/delvedor/find-my-way/pull/350](https://togithub.com/delvedor/find-my-way/pull/350) - chore: bump actions/setup-node from 3 to 4 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/delvedor/find-my-way/pull/351](https://togithub.com/delvedor/find-my-way/pull/351) - chore: bump actions/checkout from 3 to 4 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/delvedor/find-my-way/pull/352](https://togithub.com/delvedor/find-my-way/pull/352) - Achieve 100% test coverage by [@​jean-michelet](https://togithub.com/jean-michelet) in [https://github.com/delvedor/find-my-way/pull/349](https://togithub.com/delvedor/find-my-way/pull/349) - chore: bump the dependencies-major group with 1 update by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/delvedor/find-my-way/pull/353](https://togithub.com/delvedor/find-my-way/pull/353) - Fix header in README by [@​selimb](https://togithub.com/selimb) in [https://github.com/delvedor/find-my-way/pull/345](https://togithub.com/delvedor/find-my-way/pull/345) - Exclude Node v14 and v16 on macos by [@​mcollina](https://togithub.com/mcollina) in [https://github.com/delvedor/find-my-way/pull/364](https://togithub.com/delvedor/find-my-way/pull/364) - add node v22. Skip old nodes on mac by [@​mcollina](https://togithub.com/mcollina) in [https://github.com/delvedor/find-my-way/pull/363](https://togithub.com/delvedor/find-my-way/pull/363) - Support optional params on root by [@​mcollina](https://togithub.com/mcollina) in [https://github.com/delvedor/find-my-way/pull/367](https://togithub.com/delvedor/find-my-way/pull/367) #### New Contributors - [@​valeneiko](https://togithub.com/valeneiko) made their first contribution in [https://github.com/delvedor/find-my-way/pull/344](https://togithub.com/delvedor/find-my-way/pull/344) - [@​SavaCool122](https://togithub.com/SavaCool122) made their first contribution in [https://github.com/delvedor/find-my-way/pull/347](https://togithub.com/delvedor/find-my-way/pull/347) - [@​dependabot](https://togithub.com/dependabot) made their first contribution in [https://github.com/delvedor/find-my-way/pull/351](https://togithub.com/delvedor/find-my-way/pull/351) - [@​jean-michelet](https://togithub.com/jean-michelet) made their first contribution in [https://github.com/delvedor/find-my-way/pull/349](https://togithub.com/delvedor/find-my-way/pull/349) - [@​selimb](https://togithub.com/selimb) made their first contribution in [https://github.com/delvedor/find-my-way/pull/345](https://togithub.com/delvedor/find-my-way/pull/345) **Full Changelog**: delvedor/find-my-way@v8.1.0...v8.2.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/redwoodjs/redwood). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zNjMuNSIsInVwZGF0ZWRJblZlciI6IjM3LjM2My41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Hi, first time contributor here 👋
Will fixes #330
So far, I've only worked on one test file, but I think I should try to improve existing tests or create new isolated test files.
I don't have much confidence in the tests I've written, so I'd like to get some initial feedback to make sure I'm on the right track.
Although all filenames are green now, yellow has gradually appeared...
I'm not familiar with test coverage tools but this seems to be related to conditional statements and logical expressions, right?
How important is it for you to cover these cases? To what extent?