-
Notifications
You must be signed in to change notification settings - Fork 94
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
Eslint check for mocking node core modules #786
Conversation
582e277
to
435de15
Compare
see https://jestjs.io/docs/en/manual-mocks#mocking-node-modules > Warning: If we want to mock Node's core modules (e.g.: fs or path), then explicitly calling e.g. jest.mock('path') is required, because core Node modules are not mocked by default. Signed-off-by: Vit Gottwald <vit.gottwald@gmail.com>
435de15
to
a72ce3f
Compare
Codecov Report
@@ Coverage Diff @@
## master #786 +/- ##
=======================================
Coverage 91.23% 91.23%
=======================================
Files 47 47
Lines 5143 5143
Branches 1076 1076
=======================================
Hits 4692 4692
Misses 447 447
Partials 4 4 Continue to review full report at Codecov.
|
I want to mock these, but in the test PRs I am having trouble mocking node's standard module Sometimes we need to use the standard behavior of Maybe we could use something like this: https://www.npmjs.com/package/mock-fs Or maybe there is a mock library someone has already made for path, somewhere on the interwebs? |
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.
Please see my comments
{ | ||
"name": "eslint-plugin-zowe-explorer", | ||
"version": "0.0.0", | ||
"description": "Custom ESLint Rules for ZOWE Explorer", |
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 am confused with the word plugin. For me, plugin is optional but somehow I feel like this is not optional.
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.
Eslint has several parts. Its core (the eslint package), plugins (which can provide linting rules) and a user configuration.
If someone wants to create a new rule for ESLint, they need to create an eslint plugin with the rule. That is what the eslint-plugin folder is.
To tell eslint I want it to use the plugin, the plugin has to be specified in eslint config https://github.com/zowe/vscode-extension-for-zowe/pull/786/files#diff-e4403a877d80de653400d88d85e4801aR4 . And to tell eslint to use a rule from the plugin for linting, it also has to be specified in the eslint config https://github.com/zowe/vscode-extension-for-zowe/pull/786/files#diff-e4403a877d80de653400d88d85e4801aR7.
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.
Does that answer your questions @jellypuno ?
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 the team was interested in more details, I could do a small presentation and explain how today's javascript/typescript tooling works under the hood.
@katelynienaber I believe I answered your question in a standup. Because we are modifying the fs module, we have to make sure it is mocked. This eslint rule will make sure we call jest.mock('fs'). |
Do we really want to run two linters? I would propose to switch everything over to eslint at once. I did some experimentation with it here: zowe/zowe-explorer-ftp-extension#3 I would also not add any .js files. As we are typescript project we should implement everything strongly typed in .ts files. Configurations such as .eslintrc are easier to maintain as yaml files. |
Good points @phaumer ! I would switch to ESlint without a blink of an eye. I actually suggested it about a month ago, but it has not been discussed yet and had no priority. The goal of this PR is to prevent a very particular kind of error we discovered in our tests. I do not think its scope includes switching linters. For a short period of time I do not see a problem with having two of them. |
I guess I used .eslintrc.js because I am used to it. I have no problem switching to yaml. There might however be some quirks related to running prettier. In the last project I had a conditional logic in eslintrc to only run prettier on CI to avoid the problems I described in zowe/zowe-explorer-ftp-extension#3 |
The I thought about all of this and decided that instead of boiling the ocean and introducing new concepts and additional tooling to he project, I would make it simple and go with javascript for the plugin. It is a lint tool, not production code. What do you think we should do @phaumer ? |
Ok, I did not realize that. If this is just a tool that does not require constant maintenance and not production code then I agree to do it in just the most straightforward way. Sorry for chiming in without fully understanding what is going on. I definitely like yaml files for listing the rules for our main code, but if that also causes problem then I understand. |
No worries @phaumer. All feedback is appreciated. It is my fault. I was so happy to have the solution to make sure we do not break tests again by modifying the fs module, that I rushed in with the PR. I should really have diligently described the solution and choices I made to everyone upfront. |
For this particular PR we can go with |
Signed-off-by: Vit Gottwald <vit.gottwald@gmail.com>
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 @VitGottwald
This will make sure that any new/refactored tests PRs do the right thing! 👍
Please keep in mind that the migration from tslint to eslint is still pending. and we will continue further discussion in zowe/zowe-explorer-ftp-extension#3 Also another reminder, let's aim to make eslint rule changes whenever there are a small amount of open PRs 😋 |
No description provided.