-
Notifications
You must be signed in to change notification settings - Fork 25.3k
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
TestBed.overrideModule affects other tests #36619
Comments
Hi @kalsowerus, Thanks for reporting the issue and providing a repro (this is super helpful!). I was able to reproduce the problem, will perform further investigation and will keep this thread updated. Thank you. |
When module overrides (via `TestBed.overrideModule`) are present, it might affect all modules that import (even transitively) an overridden one. For all affected modules we need to recalculate their scopes for a given test run and restore original scopes at the end. Prior to this change, we were recalculating module scopes only for components that are used in a test, without taking into account module hierarchy. This commit updates Ivy TestBed logic to calculate all potentially affected modules are reset cached scopes information for them (so that scopes are recalculated as needed). Resolves angular#36619.
When module overrides (via `TestBed.overrideModule`) are present, it might affect all modules that import (even transitively) an overridden one. For all affected modules we need to recalculate their scopes for a given test run and restore original scopes at the end. Prior to this change, we were recalculating module scopes only for components that are used in a test, without taking into account module hierarchy. This commit updates Ivy TestBed logic to calculate all potentially affected modules are reset cached scopes information for them (so that scopes are recalculated as needed). Resolves angular#36619.
Hi @kalsowerus, I've created a PR with proposed fix. I tested the fix using the repro that you provided and it seems to be working correctly now. If you get a chance, it'd be great if you could help test this fix with your real app to see if the original problem is also resolved. To test your app with the changes from PR #36649, you can follow an instruction in this document on how to use PR artifacts. An archive with updated Thank you. |
Hi @AndrewKushnir, Thank you very much for your response. I ran my tests a few times with your PR artifact and could not reproduce the original error. It seems to be working fine now. Can I expect to see this fix in 9.1.3? Thank you. |
When module overrides (via `TestBed.overrideModule`) are present, it might affect all modules that import (even transitively) an overridden one. For all affected modules we need to recalculate their scopes for a given test run and restore original scopes at the end. Prior to this change, we were recalculating module scopes only for components that are used in a test, without taking into account module hierarchy. This commit updates Ivy TestBed logic to calculate all potentially affected modules are reset cached scopes information for them (so that scopes are recalculated as needed). Resolves angular#36619.
Hi @kalsowerus, thanks for your help with testing the change 👍I expect the change to be included into |
…#36649) When module overrides (via `TestBed.overrideModule`) are present, it might affect all modules that import (even transitively) an overridden one. For all affected modules we need to recalculate their scopes for a given test run and restore original scopes at the end. Prior to this change, we were recalculating module scopes only for components that are used in a test, without taking into account module hierarchy. This commit updates Ivy TestBed logic to calculate all potentially affected modules are reset cached scopes information for them (so that scopes are recalculated as needed). Resolves #36619. PR Close #36649
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🐞 bug report
Affected Package
The issue is caused by package @angular/core/testingIs this a regression?
Yes, the previous version in which this bug was not present was: 8.2.13Description
All test cases after a call to
TestBed.overrideModule
seem to be affected by its modifications.In the provided Example project I have two tests:
one.spec.ts
andtwo.spec.ts
. Both create an instance of their own component which both contain aTestComponent
. Inone.spec.ts
I replaceTestComponent
with a Mock usingoverrideModule
. Ifone.spec.ts
is executed first by the test runner,two.spec.ts
also uses the Mock component.Additionally this example also does not work if
two.spec.ts
is executed first. In that case theoverrideModule
-call seems to be ignored.I cannot say for sure wether this is a problem with Angular or Karma. If you think I should open an issue on Karma, please let me know.
🔬 Minimal Reproduction
https://github.com/kalsowerus/repro-app
The
TestComponent
I mentioned earlier prints'test'
in itsngOnInit()
, while the mock component insideone.spec.ts
prints'mock'
. To see the problem justnpm install
and thenng test
. The exact command I used to execute the tests isng test --browsers ChromeForWSL --watch=false
.ChromeForWSL
being a custom Launcher based on Chrome which disables the "VizDisplayCompositor"-feature since that does not seem to work in a WSL (Windows subsystem for Linux) environment.The expected result would be seeing both
'test'
and'mock'
in the console once in any order. But depending on the execution order either of them are printed twice while the other one is not printed at all.🔥 Exception or Error
No exception or error
🌍 Your Environment
Angular Version:
Anything else relevant?
The text was updated successfully, but these errors were encountered: