-
Notifications
You must be signed in to change notification settings - Fork 0
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
refactor: remove test failures/logs from injection token maker #904
refactor: remove test failures/logs from injection token maker #904
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @davidlj95 and the rest of your teammates on |
a4d72c1
to
7b3c91b
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #904 +/- ##
=======================================
Coverage 99.46% 99.46%
=======================================
Files 79 79
Lines 372 372
Branches 73 73
=======================================
Hits 370 370
Partials 2 2 ☔ View full report in Codecov by Sentry. |
📦 Bundle size (Angular v18)Git ref:
|
📦 Bundle size (Angular v15)Git ref:
|
📦 Bundle size (Angular v16)Git ref:
|
📦 Bundle size (Angular v17)Git ref:
|
7b3c91b
to
b6e54e4
Compare
b6e54e4
to
d914993
Compare
INJECTION_TOKENS.clear() | ||
INJECTION_TOKEN_FACTORIES.clear() | ||
INJECTION_TOKENS.delete(description) | ||
INJECTION_TOKEN_FACTORIES.delete(description) |
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.
Not actually needed. However nice to only mess one dummy injection token just in case.
d914993
to
95f8ff9
Compare
@@ -27,9 +27,13 @@ export const _makeInjectionToken: <T>( | |||
const injectionToken = | |||
INJECTION_TOKENS.get(description) ?? | |||
new InjectionToken(`ngx-meta ${description}`, { factory }) | |||
INJECTION_TOKENS.set(description, injectionToken) |
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.
Moved here so the prod code is ran as soon as possible (after thinking about race conditions and so). Though not needed actually.
95f8ff9
to
3049da7
Compare
🎉 This PR is included in version 1.0.0-beta.17 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Issue or need
Moar issues appeared after trying to use lazy injection tokens in #902:
Proposed changes
Removes warning. As after usingThinking about it again, doesn't make sense. Given if inspected, source code string is the same. Tests ran on the browser. All of them. Test setup code included. So code should be the same. The issue was that in #902 , the injection token factory is an anonymous function. That gets created when calling the function to create the lazy injection token. So its identity is different every time. Therefore we can't check for object identity and that's it. Therefore in order to check if they're the same or not, usingtoString()
on factories for injection tokens, seems the issue may be due to tests running on Node.js but executing on the browser. Where code may be slightly different after bundling.toString()
to compare source codes. Added a unit test to ensure about that.Deletes only the
dummy
injection token created for unit testing. Otherwise reseting the whole injection tokens map messes up tests. Why though? 🤔After a few times trying this on top of #902 , seems that first time clearing, the head element upsert or remove util injection token is there. And if clearing them, some times unit tests fail. Not always though. What may be happening is a race condition. The injection token gets created and test starts. Then,
clear
happens and removes it. Then, the test code tries to inject that token. But as it's been cleared, it creates a new one. The new one isn't a spy. So the spy isn't called. Deleting only the dummy injection token solves this.This PR has been tested on top of #902 to ensure everything works fine when the API is used around.
Quick reminders