Skip to content

refactor(core): remove unused fakeAsyncFallback and asyncFallback #37879

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

Closed

Conversation

JiaLiPassion
Copy link
Contributor

zone.js 0.8.25 introduces zone-testing bundle and move all fakeAsync/async logic
from @angular/core/testing to zone.js package. But in case some user still using the old
version of zone.js, an old version of fakeAsync/async logic were still kept inside @angular/core/testing
package as fallback logic. Since now Angular8+ already use zone.js 0.9+, so
those fallback logic can be removed.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

Other information

@JiaLiPassion JiaLiPassion requested a review from mhevery July 1, 2020 21:57
@JiaLiPassion JiaLiPassion force-pushed the remove-test-fallback branch from c6c1dc1 to 2e1ec96 Compare July 1, 2020 21:57
@pullapprove pullapprove bot requested a review from IgorMinar July 1, 2020 21:57
@JiaLiPassion JiaLiPassion added area: zones Issues related to zone.js target: patch This PR is targeted for the next patch release labels Jul 1, 2020
@ngbot ngbot bot added this to the needsTriage milestone Jul 1, 2020
@JiaLiPassion JiaLiPassion force-pushed the remove-test-fallback branch 3 times, most recently from 2d0dc7c to b3ba146 Compare July 1, 2020 22:56
@mhevery
Copy link
Contributor

mhevery commented Jul 15, 2020

presubmit

@pullapprove pullapprove bot requested review from josephperrott and pkozlowski-opensource and removed request for IgorMinar July 23, 2020 03:33
Copy link
Member

@josephperrott josephperrott left a comment

Choose a reason for hiding this comment

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

LGTM

Reviewed-For:dev-infra

@mhevery
Copy link
Contributor

mhevery commented Jul 27, 2020

presubmit

@mhevery
Copy link
Contributor

mhevery commented Jul 29, 2020

google3 failure:


          
        Please make sure that your environment includes zone.js/dist/zone-testing.js
Error: zone-testing.js is needed for the async() test helper but could not be found.
        Please make sure that your environment includes zone.js/dist/zone-testing.js
    at Object.resetFakeAsyncZone (third_party/javascript/angular2/rc/packages/core/testing/src/fake_async.ts?l=25
    at UserContext.<anonymous> (third_party/javascript/angular2/rc/packages/core/testing/src/before_each.ts?l=26
    at ProxyZoneSpec.onInvoke (https://cs.corp.google.com/piper///depot/google3/third_party/javascript/angular2/rc/packages/zone.js/lib/zone-spec/proxy.ts?l=137
    at runInTestZone (https://cs.corp.google.com/piper///depot/google3/third_party/javascript/angular2/rc/packages/zone.js/lib/jasmine/jasmine.ts?l=208
    at UserContext.<anonymous> (https://cs.corp.google.com/piper///depot/google3/third_party/javascript/angular2/rc/packages/zone.js/lib/jasmine/jasmine.ts?l=224        

@JiaLiPassion
Copy link
Contributor Author

@mhevery , I think the error means, this g3 application loading zone testing libs in the old way.
something like this if the g3 app import from source

import 'zone.js/lib/zone-spec/long-stack-trace';
import 'zone.js/lib/zone-spec/proxy';
import 'zone.js/lib/zone-spec/sync-test';
import 'zone.js/lib/jasmine/jasmine';
import 'zone.js/lib/zone-spec/async-test';
import 'zone.js/lib/zone-spec/fake-async-test';

or something like this if the g3 app import from node_modules.

import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy';
import 'zone.js/dist/sync-test';
import 'zzone.js/dist/jasmine';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';

So is that possible to update this g3 application to load zone testing libs in the new way?

  • The most easiest way.

If import from source

import `zone.js/lib/testing/zone-testing`;

if import from node_modules.

import `zone.js/dist/zone-testing`;
  • In some case, the app has to load those libs separately, for example, the app may want to do some additional patch for jasmine. In that case, load like this.

import from source

import 'zone.js/lib/zone-spec/long-stack-trace';
import 'zone.js/lib/zone-spec/proxy';
import 'zone.js/lib/zone-spec/sync-test';
import 'zone.js/lib/jasmine/jasmine';
import 'zone.js/lib/testing/async-testing';
import 'zone.js/lib/testing/fake-async';

Thanks.

@mhevery
Copy link
Contributor

mhevery commented Nov 16, 2020

If we have to change a lot of apps in g3 than this change is unlikely to land due to the amount of work required.

presubmit To get the latest amount of work which would be needed to land this.

About 1,300+ tests fail do to this.

@@ -5,11 +5,13 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {discardPeriodicTasksFallback, fakeAsyncFallback, flushFallback, flushMicrotasksFallback, resetFakeAsyncZoneFallback, tickFallback} from './fake_async_fallback';
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't we add import here?

import `zone.js/lib/testing/zone-testing`;

That way it would fix all google3 applications?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since currently the application generated by the Angular CLI will have a test.ts, and in the test.ts, it is loading zone-testing.

// This file is required by karma.conf.js and loads recursively all the .spec and framework files

import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
...

So if we are adding the import here, the testing bundle will be loaded twice and may throw error in some cases.

With the same idea, we can try to import the missing logic from

import `zone.js/lib/testing/fake-async`;
import `zone.js/lib/testing/async-testing`;

But still if the application already loaded the zone-testing bundle, it will throw error in some cases.
We can change the code in zone.js/lib/testing/fake-async and zone.js/lib/testing/async-test to make it work for this case (duplicate import), not sure we should do that in this way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding import here fixes google3. Could zone.js api loading make sure that we don't double load it. This would allow the PR to land.

@pullapprove pullapprove bot requested a review from IgorMinar November 16, 2020 22:55
@JiaLiPassion JiaLiPassion force-pushed the remove-test-fallback branch 2 times, most recently from 60795d2 to 619d245 Compare November 17, 2020 19:57
@mhevery
Copy link
Contributor

mhevery commented Nov 18, 2020

presubmit

@mhevery
Copy link
Contributor

mhevery commented Nov 18, 2020

A lot better but still errors:

TypeError: Cannot read property 'assertPresent' of undefined
          at UserContext.fakeAsyncFn (https://cs.corp.google.com/piper///depot/google3/third_party/javascript/angular2/rc/packages/zone.js/lib/zone-spec/fake-async-test.ts?l=753
          at ZoneDelegate.invoke (https://cs.corp.google.com/piper///depot/google3/third_party/javascript/angular2/rc/packages/zone.js/lib/zone.ts?l=1148
          at ProxyZoneSpec.onInvoke (https://cs.corp.google.com/piper///depot/google3/third_party/javascript/angular2/rc/packages/zone.js/lib/zone-spec/proxy.ts?l=137
          at ZoneDelegate.invoke (https://cs.corp.google.com/piper///depot/google3/third_party/javascript/angular2/rc/packages/zone.js/lib/zone.ts?l=1145
          at Zone.run (https://cs.corp.google.com/piper///depot/google3/third_party/javascript/angular2/rc/packages/zone.js/lib/zone.ts?l=826
          at runInTestZone (https://cs.corp.google.com/piper///depot/google3/third_party/javascript/angular2/rc/packages/zone.js/lib/jasmine/jasmine.ts?l=208
          at UserContext.<anonymous> (https://cs.corp.google.com/piper///depot/google3/third_party/javascript/angular2/rc/packages/zone.js/lib/jasmine/jasmine.ts?l=224
          at ZoneDelegate.invokeTask (https://cs.corp.google.com/piper///depot/google3/third_party/javascript/angular2/rc/packages/zone.js/lib/zone.ts?l=1185
          at Zone.runTask (https://cs.corp.google.com/piper///depot/google3/third_party/javascript/angular2/rc/packages/zone.js/lib/zone.ts?l=876
          at drainMicroTaskQueue (https://cs.corp.google.com/piper///depot/google3/third_party/javascript/angular2/rc/packages/zone.js/lib/zone.ts?l=1383

I see ProxyZoneSpec is not loaded. Let me investigate if this can be fixed on google3 side.

@JiaLiPassion JiaLiPassion force-pushed the remove-test-fallback branch 2 times, most recently from ce1b4d7 to e82daef Compare November 19, 2020 02:37
`zone.js` 0.8.25 introduces `zone-testing` bundle and move all `fakeAsync/async` logic
from `@angular/core/testing` to `zone.js` package. But in case some user still using the old
version of `zone.js`, an old version of `fakeAsync/async` logic were still kept inside `@angular/core/testing`
package as `fallback` logic. Since now `Angular8+` already use `zone.js 0.9+`, so
those fallback logic is removed.
@mhevery mhevery self-assigned this Nov 19, 2020
@mhevery
Copy link
Contributor

mhevery commented Nov 19, 2020

presubmit

Copy link
Contributor

@mhevery mhevery left a comment

Choose a reason for hiding this comment

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

reviewed-for: global-approvers

@mhevery mhevery removed the request for review from IgorMinar November 19, 2020 23:12
@mhevery mhevery added the action: merge The PR is ready for merge by the caretaker label Nov 19, 2020
AndrewKushnir pushed a commit that referenced this pull request Nov 20, 2020
…7879)

`zone.js` 0.8.25 introduces `zone-testing` bundle and move all `fakeAsync/async` logic
from `@angular/core/testing` to `zone.js` package. But in case some user still using the old
version of `zone.js`, an old version of `fakeAsync/async` logic were still kept inside `@angular/core/testing`
package as `fallback` logic. Since now `Angular8+` already use `zone.js 0.9+`, so
those fallback logic is removed.

PR Close #37879
@angular-automatic-lock-bot
Copy link

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 Dec 21, 2020
@pullapprove pullapprove bot removed the area: zones Issues related to zone.js label Dec 21, 2020
@ngbot ngbot bot removed this from the needsTriage milestone Dec 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants