Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Update odsp-driver package tests to build and run in ESM #23728
Update odsp-driver package tests to build and run in ESM #23728
Changes from 1 commit
15d8a18
4954e73
751acee
9fa0203
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 pattern breaks IntelliSense for the function, and also makes it easy for any code using the function in this package to call either one (and isn't super clear which one should be called.
I think it would be better to avoid having two separate functions in scope here: if you want all callers to use this version, I think a decorator would be a better way to wrap it as that would keep the non-wrapped version out of scope and allows the IntelliSense/docs to function properly. It would also be more concise.
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.
Well, as I mentioned in this comment, I can just inline it instead, so there is no rename+export. I like that better anyway, it just ruined the diff for this PR.
When you say decorator do you mean an actual TS decorator? I was under the impression that you can only write those for class members, not free functions.
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.
Apparently, you are right, they don't work on free functions.
If you don't inline them, I think you should nave the version you won't want people using something like fooInner instead of naming the one you do want people to use mockableFoo. Also leave the doc comments on the actually exported one (and maybe link or inherit doc the inner one to it).
I do think inlining it would be better, though refactoring things do we don't need mocking in the first place would be best: adding testing only hooks to production code is always a bit sketchy as it implies the code itself isn't flexible enough to do what tests need which is generally a bad sign.
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're right that renaming the inner helper would be better than renaming the outer exported function (because otherwise, code calling the function from within its module of declaration will accidentally use the wrong one). However, I just went ahead and in-lined the calls. The diff in this PR now looks worse, but the actual code looks better :)
I also took a look at refactoring so that e.g.
fetch
is injected rather than mocked. It's of course possible, but not trivial, and is beyond the scope of this PR IMO.