-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
Feature/increase test coverage #204
Feature/increase test coverage #204
Conversation
By injecting toID as a parameter we make it possible to test errors caused by file access errors.
test/multipart-disk.test.js
Outdated
|
||
await fastify.listen(0) | ||
|
||
const tempFilePath = path.join(os.tmpdir(), fileId + 0 + path.extname(filePath)) |
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.
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 for the suggestion. I used tap's tmpdir in the next commit.
- use node-tap's testdir as a replacement for os.tmpdir - inject tmpdir in saveRequestFiles - do not inject toID in saveRequestFiles
@@ -181,6 +181,88 @@ test('should error if it is not multipart', { skip: process.platform === 'win32' | |||
}) | |||
}) | |||
|
|||
test('should error if handler is not a function', { skip: process.platform === 'win32' }, function (t) { |
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.
Do you know why these two tests wouldn't work on windows? Also, is there a reason why you're adding tests to this legacy folder? The name suggests these are old tests, I'm assuming new tests should be written outside of this folder perhaps.
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 assume it is connected to already existing issue where tests are failing on windows for the legacy api #110.
As per readme the legacy api is not compatible with windows.
The legacy use cases also take part in the test coverage computation. I assume the folder is named legacy to group the tests for the legacy callback api. In this test we are covering the error that happens in the function handleLegacyMultipartApi
.
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.
Understood, I didn't know there was a legacy API, this explains it.
} | ||
}) | ||
|
||
test('should not throw on request files cleanup error', { skip: process.platform === 'win32' }, async function (t) { |
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.
same question for this test. it doesn't seem to be doing anything that wouldn't work on windows
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.
The reason for having this test skip the Windows platform is different.
I think the test is flaky on Windows. It failed on our windows CI with node 12.x but it ran successfully on a Windows 10 laptop with node 12.x. (I can't prove that, you'll have to trust me :) )
My theory is that this could be similar to the Timing Caveat on windows described in node-tap documentation where removal of the tempdir
is asynchronous. tapjs/tapjs#677
In the test we are using rimraf which has a known issue that could be causing this: isaacs/rimraf#72
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.
Makes sense, thanks for clarifying.
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.
you can remove rimraf. recursive folder removal is now part of Node.js. See https://nodejs.org/api/fs.html#fs_fs_rmdirsync_path_options and others.
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.
This module still supports Node 10 though
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.
Yes, recursive is not supported in Node 10.
The 3 remaining uncovered lines are something that can't be tested or do you think you can cover them too? |
I was unable to reproduce the case where those three lines would be used. This functionality was created in #44 The unit test for the functionality was created but those three lines are not covered with that test. I am not comfortable enough with the untested use cases to say that we can safely remove these lines. That's why I left them uncovered. |
Fair enough. You can open this PR up for review |
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
Fix #202 Increase the test coverage for the plugin.
The coverage is:
Previously it was:
To test the scenarios where temporary files are stored to disk, we needed to be able to predict what the temporary file
name would be. Previously the temp file id was generated by
hexoid
, but now I needed to make the id generation strategy injectable. This way, I can simulate the scenario where the temp file cannot be changed or where the temp file is missing.Checklist
npm run test
andnpm run benchmark
and the Code of conduct