Skip to content
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

Conversation

davidlj95
Copy link
Owner

@davidlj95 davidlj95 commented Oct 9, 2024

Issue or need

Moar issues appeared after trying to use lazy injection tokens in #902:

  • Messages about duplicate tokens creation with different factories started appearing in unit tests
  • Unit tests failed. Spies seem not to be called

Proposed changes

Removes warning. As after using toString() 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. Thinking 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, using 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

  • 🤝 I will follow Code of Conduct
  • No existing pull request already does almost same changes
  • 👁️ Contributing docs are something I've taken a look at
  • 📝 Commit messages convention has been followed
  • 💬 TSDoc comments have been added or updated indicating API visibility if API surface has changed.
  • 🧪 Tests have been added if needed. For instance, if adding new features or fixing a bug. Or removed if removing features.
  • ⚙️ API Report has been updated if API surface is altered.

Copy link
Owner Author

davidlj95 commented Oct 9, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @davidlj95 and the rest of your teammates on Graphite Graphite

@davidlj95 davidlj95 force-pushed the stacked/refactor-remove-log-test-failures-from-injection-token-maker branch from a4d72c1 to 7b3c91b Compare October 9, 2024 12:29
Copy link

codecov bot commented Oct 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.46%. Comparing base (d2566ae) to head (95f8ff9).
Report is 16 commits behind head on main.

Current head 95f8ff9 differs from pull request most recent head 3049da7

Please upload reports for the commit 3049da7 to get more accurate results.

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.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Oct 9, 2024

📦 Bundle size (Angular v18)

Git ref: 3049da7e05d2477a9974306b6cc2e82a470d0dc3

Module file Size Base size Difference
ngx-meta-core.mjs 2812 bytes (2.8KiB) 2812 bytes (2.8KiB) No change
ngx-meta-json-ld.mjs 224 bytes (224B) 224 bytes (224B) No change
ngx-meta-open-graph.mjs 984 bytes (984B) 984 bytes (984B) No change
ngx-meta-routing.mjs 449 bytes (449B) 449 bytes (449B) No change
ngx-meta-standard.mjs 990 bytes (990B) 990 bytes (990B) No change
ngx-meta-twitter-card.mjs 514 bytes (514B) 514 bytes (514B) No change
Total 5973 bytes (5.9KiB) 5973 bytes (5.9KiB) No change

Copy link

github-actions bot commented Oct 9, 2024

📦 Bundle size (Angular v15)

Git ref: 3049da7e05d2477a9974306b6cc2e82a470d0dc3

Module file Size Base size Difference
ngx-meta-core.mjs 3220 bytes (3.2KiB) 3220 bytes (3.2KiB) No change
ngx-meta-json-ld.mjs 353 bytes (353B) 353 bytes (353B) No change
ngx-meta-open-graph.mjs 1233 bytes (1.3KiB) 1233 bytes (1.3KiB) No change
ngx-meta-routing.mjs 626 bytes (626B) 626 bytes (626B) No change
ngx-meta-standard.mjs 1072 bytes (1.1KiB) 1072 bytes (1.1KiB) No change
ngx-meta-twitter-card.mjs 630 bytes (630B) 630 bytes (630B) No change
Total 7134 bytes (7.0KiB) 7134 bytes (7.0KiB) No change

Copy link

github-actions bot commented Oct 9, 2024

📦 Bundle size (Angular v16)

Git ref: 3049da7e05d2477a9974306b6cc2e82a470d0dc3

Module file Size Base size Difference
ngx-meta-core.mjs 3255 bytes (3.2KiB) 3255 bytes (3.2KiB) No change
ngx-meta-json-ld.mjs 368 bytes (368B) 368 bytes (368B) No change
ngx-meta-open-graph.mjs 1263 bytes (1.3KiB) 1263 bytes (1.3KiB) No change
ngx-meta-routing.mjs 641 bytes (641B) 641 bytes (641B) No change
ngx-meta-standard.mjs 1087 bytes (1.1KiB) 1087 bytes (1.1KiB) No change
ngx-meta-twitter-card.mjs 645 bytes (645B) 645 bytes (645B) No change
Total 7259 bytes (7.1KiB) 7259 bytes (7.1KiB) No change

Copy link

github-actions bot commented Oct 9, 2024

📦 Bundle size (Angular v17)

Git ref: 3049da7e05d2477a9974306b6cc2e82a470d0dc3

Module file Size Base size Difference
ngx-meta-core.mjs 2812 bytes (2.8KiB) 2812 bytes (2.8KiB) No change
ngx-meta-json-ld.mjs 224 bytes (224B) 224 bytes (224B) No change
ngx-meta-open-graph.mjs 984 bytes (984B) 984 bytes (984B) No change
ngx-meta-routing.mjs 449 bytes (449B) 449 bytes (449B) No change
ngx-meta-standard.mjs 990 bytes (990B) 990 bytes (990B) No change
ngx-meta-twitter-card.mjs 514 bytes (514B) 514 bytes (514B) No change
Total 5973 bytes (5.9KiB) 5973 bytes (5.9KiB) No change

@davidlj95 davidlj95 force-pushed the stacked/refactor-remove-log-test-failures-from-injection-token-maker branch from 7b3c91b to b6e54e4 Compare October 9, 2024 12:42
@davidlj95 davidlj95 changed the title refactor: remove log & test failures from injection token maker refactor: remove test failures from injection token maker Oct 9, 2024
@davidlj95 davidlj95 changed the title refactor: remove test failures from injection token maker refactor: remove test failures/logs from injection token maker Oct 9, 2024
@davidlj95 davidlj95 force-pushed the stacked/refactor-remove-log-test-failures-from-injection-token-maker branch from b6e54e4 to d914993 Compare October 9, 2024 13:01
INJECTION_TOKENS.clear()
INJECTION_TOKEN_FACTORIES.clear()
INJECTION_TOKENS.delete(description)
INJECTION_TOKEN_FACTORIES.delete(description)
Copy link
Owner Author

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.

@davidlj95 davidlj95 force-pushed the stacked/refactor-remove-log-test-failures-from-injection-token-maker branch from d914993 to 95f8ff9 Compare October 9, 2024 13:08
@@ -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)
Copy link
Owner Author

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.

@davidlj95 davidlj95 enabled auto-merge (squash) October 9, 2024 13:11
@davidlj95 davidlj95 force-pushed the stacked/refactor-remove-log-test-failures-from-injection-token-maker branch from 95f8ff9 to 3049da7 Compare October 9, 2024 14:37
@davidlj95 davidlj95 disabled auto-merge October 9, 2024 14:49
@davidlj95 davidlj95 merged commit 25d1323 into main Oct 9, 2024
32 checks passed
@davidlj95 davidlj95 deleted the stacked/refactor-remove-log-test-failures-from-injection-token-maker branch October 9, 2024 14:49
Copy link

🎉 This PR is included in version 1.0.0-beta.17 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant