Visitar URL original
`destroy` testing modules during `resetTestingModule` by josephperrott · Pull Request #38336 · angular/angular · GitHub
The Wayback Machine - https://web.archive.org/web/20260831062044/https://github.com/angular/angular/pull/38336
Skip to content

destroy testing modules during resetTestingModule - #38336

Closed
josephperrott wants to merge 1 commit into
angular:masterfrom
josephperrott:shared-styles-cleanup
Closed

destroy testing modules during resetTestingModule#38336
josephperrott wants to merge 1 commit into
angular:masterfrom
josephperrott:shared-styles-cleanup

Conversation

@josephperrott

@josephperrott josephperrott commented Aug 3, 2020 •

Copy link
Copy Markdown
Member

See individual commits.

Fixes #18831

@josephperrott josephperrott added area: testing Issues related to Angular testing features, such as TestBed action: review The PR is still awaiting reviews from at least one requested reviewer area: router area: core Issues related to the framework runtime target: major This PR is targeted for the next major release labels Aug 3, 2020
@ngbot ngbot Bot modified the milestone: needsTriage Aug 3, 2020
@muhammedMoussa

Copy link
Copy Markdown

Hi, can (this.subscription && !this.subscription.closed) shorthanded
to be (!this.subscription?.closed)

@josephperrott
josephperrott force-pushed the shared-styles-cleanup branch 5 times, most recently from d7d142b to b803904 Compare August 6, 2020 20:40
@josephperrott
josephperrott force-pushed the shared-styles-cleanup branch from b803904 to 1490c1d Compare August 10, 2020 22:15
@josephperrott
josephperrott force-pushed the shared-styles-cleanup branch 4 times, most recently from 63e25ad to 7c48418 Compare August 21, 2020 20:08
@cexbrayat cexbrayat mentioned this pull request Nov 27, 2020
14 tasks
cexbrayat added a commit to cexbrayat/angular that referenced this pull request Nov 29, 2020
There is currently a known issue with the framework when testing that leaks style.
See angular#31834

A possible temporary workaround is to manually call the service that adds/aremoves the style.
See angular#31834 (comment)

This workaround will be unnecessary when angular#38336 lands.

This speeds up the `ng test` task locally by ~30%:
- before: Executed 649 of 652 (skipped 3) SUCCESS (24.161 secs / 20.072 secs)
- after: Executed 649 of 652 (skipped 3) SUCCESS (17.854 secs / 15.584 secs)

@Splaktar Splaktar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like CircleCI is requiring this PR be rebased:

        CircleCI config on master has been modified since commit 250e299,
        which this PR is based on.

        Please rebase the PR on master after fetching from upstream.

        Rebase instructions for PR Author, please run the following commands:

          git fetch upstream master;
          git checkout shared-styles-cleanup;
          git rebase upstream/master;
          git push --force-with-lease;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this just for debugging? Can it be removed now?

@ngbot ngbot Bot modified the milestones: needsTriage, Backlog Mar 11, 2021
@elesueur

Copy link
Copy Markdown

@AndrewKushnir can you describe how this change is breaking?

@AndrewKushnir

Copy link
Copy Markdown
Contributor

@elesueur given that there was no cleanup of shared styles, tests might be written in a way where they depend on the presence of some CSS rules added during previous tests. With the proposed cleanup, such tests will start to fail (so this is a breaking change). We've confirmed that by running tests in Google's codebase. Before merging this change it's important to estimate potential risks and come up with proper rollout plan/communication.

@josephperrott please correct me if I'm wrong or if I'm missing something.

@josephperrott

Copy link
Copy Markdown
Member Author

That is correct, I would only add that it could go even further and maintain the state in other ways between tests. Since modules are not torn down, things like the state of a service can leak between tests.

@elesueur

Copy link
Copy Markdown

That is correct, I would only add that it could go even further and maintain the state in other ways between tests. Since modules are not torn down, things like the state of a service can leak between tests.

As a maintainer of several large Angular apps, I would want to learn about which tests are relying on pollution (and fix them) and get the performance improvement rather than wait for a 'less breaky' solution that hides the pollution and leaves me with slow tests :)

…ule`

Previously, the reference to the test `NgModuleRef` was set to null when the testing module
was reset via `resetTestingModule`.  While this clears the reference to the specific instance
of `NgModuleRef`, it does not properly break down/destroy the established injectibles within
the `TestBed`.  By calling `destroy` on the `_moduleRef` instance, the entire established
structue is correctly torn down to truly reset what the module has created.
@josephperrott
josephperrott force-pushed the shared-styles-cleanup branch from 0ce8927 to 2505cf2 Compare May 14, 2021 17:40
@crisbeto

Copy link
Copy Markdown
Member

Will be superseded by #42566.

@josephperrott

Copy link
Copy Markdown
Member Author

Closing in favor of #42566

@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Jul 18, 2021
@josephperrott
josephperrott deleted the shared-styles-cleanup branch August 31, 2023 17:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: core Issues related to the framework runtime area: router area: testing Issues related to Angular testing features, such as TestBed breaking changes cla: yes target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Destroy listeners aren't called in TestBed

7 participants