-
Notifications
You must be signed in to change notification settings - Fork 31
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
Tech/update jest, babel and adapt mocks #1097
Conversation
Remove ng-annotate-loader
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.
Awesome work! Just left a few small comments.
visualization/app/codeCharta/ui/codeMap/codeMap.label.service.spec.ts
Outdated
Show resolved
Hide resolved
visualization/app/codeCharta/ui/codeMap/codeMap.label.service.spec.ts
Outdated
Show resolved
Hide resolved
} | ||
})() | ||
codeMapPreRenderService.getRenderFileMeta = jest.fn().mockReturnValue({ fileName: "my_fileName" }) | ||
attributeSideBarController["codeMapPreRenderService"] = codeMapPreRenderService |
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 suggest to add a linter rule to use the dot notation in the future (if you agree, in a separate PR).
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.
Accessing private fields or functions is quite useful when writing tests or setting up a test.
We could enable that rule for our production code for sure, but tests shouldn't be included.
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.
Using the dot notation is independent from accessing private fields :)
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.
How? When I want to access a private field, I have to use class["private_field"]
? instead of class.private_field
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.
TIL. I was not aware that TypeScript used this specific notation to access private fields. IMO it's a bad practice to access any private field. I do not want to go into that discussion here though. I would actively mark access like these (by adding a comment) that it's a private properly that it's intentionally accessed and that it's the TypeScript way to do so.
Calling something a private field that is still accessible is somewhat weird. The reason that it's working like that was AFAIK that it was difficult to create actual private members when TypeScript came up. That changed in the meanwhile and now JS has actual private fields that do not allow any access from outside.
I personally always test internals by either: using the dependency injection pattern or by just plainly checking the overall output of a higher level API that should only work if the internal path is hit. If the coverage does not show the expected lines to be covered, something is fishy.
To get back to the actual comment: for now it would be possible to exclude tests for such a rule. On the long term, I'd try to refactor the code to the dependency injection 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.
We could use the typescript-es-lint rule. It has an option to allow private class member access like this.
I'm not sure if you can allow/disallow individual rules. I think you can just define a pattern that applies to all rules.
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.
It is possible to enable specific rules for specific files by using overrides. It should be sufficient to just use the "native" rule.
visualization/app/codeCharta/ui/nodeContextMenu/nodeContextMenu.component.spec.ts
Outdated
Show resolved
Hide resolved
visualization/app/codeCharta/ui/nodeContextMenu/nodeContextMenu.component.spec.ts
Outdated
Show resolved
Hide resolved
visualization/app/codeCharta/ui/codeMap/codeMap.component.spec.ts
Outdated
Show resolved
Hide resolved
visualization/app/codeCharta/ui/codeMap/codeMap.component.spec.ts
Outdated
Show resolved
Hide resolved
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! Just left one question and the promise part could be shorter.
Update Jest, Babel and adapt broken tests due to jest mock change
Description
I hope that with updating Babel, I can rework our compiling and transpiling flow and fix my issues in #992
Definition of Done
A task/pull request will not be considered to be complete until all these items can be checked off.
master