-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
increase code coverage to 100% #267
Conversation
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.
Good work, I've left a few nits!
test/static.js
Outdated
const next = () => console.log() | ||
|
||
// eslint-disable-next-line | ||
fastify.register(Function(fastifySwagger(fastify, null, next))) |
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.
Why the Function
?
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.
If we don't use a Function
constructor, avvio
throws an error saying that:
FAIL test/static.js
✖ plugin must be a function or a promise
node_modules/avvio/boot.js
192 | function assertPlugin (plugin) {
193 | if (!(plugin && (typeof plugin === 'function' || typeof plugin.then === 'function'))) {
> 194 | throw new Error('plugin must be a function or a promise')
| ----------^
195 | }
196 | }
197 |
So, if we remove the Function
for this test, it'll fail
what issues? |
Yeah, I've spent a couple of days trying to cover all the remaining lines/statements/branches inside |
Which lines are unreacheable? You can paste links to the line in the issue.
I don't understand why adding an |
I'll try more then |
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.
Good job! I think you have found a few dead code paths!
how are we for code coverage now? |
Hey @mcollina We're approx. at the same point. I'm currently trying to cover the remaining statements and branches :) |
const localReference = jsonSchema.$ref.split('/')[2] | ||
return localRefResolve(externalSchemas[localReference], externalSchemas) | ||
} | ||
return jsonSchema |
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.
We don't need this "default" return
statement. In this function, the flow goes either into the first if
or into the second one due to the schema validation rules as far as I understood.
Therefore, I refactored things a bit.
@@ -5,7 +5,7 @@ | |||
"main": "index.js", | |||
"scripts": { | |||
"prepare": "node prepare-swagger-ui", | |||
"test": "standard && tap test/*.js && npm run typescript", | |||
"test": "standard && tap --100 test/*.js && npm run typescript", |
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 enforce 100%
percent coverage in the future
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.
Perfect!
@@ -106,22 +106,20 @@ module.exports = function (fastify, opts, next) { | |||
swaggerObject.externalDocs = externalDocs | |||
} | |||
|
|||
if (!ref) { |
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've played with code a bit more and found out that we don't need this if
clause. The swagger
function is called only once at the very beginning, and the second call does not allow us to trigger it once again. Therefore, we're quite safe to remove it, it should not break any logic.
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, really good work!
Hey @mcollina Should I add something or this can be merged to the main branch? Do I need to request some more reviews? |
I was waiting for more reviews.. but not really needed! Landed! |
Currently, 4 out of 4 files have 100% coverage:
Fixes: #258
Checklist
npm run test
andnpm run benchmark