Skip to content

Commit f579115

Browse files
JiaLiPassionAndrewKushnir
authored andcommitted
refactor(core): remove unused fakeAsyncFallback and asyncFallback (#37879)
`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
1 parent cb1d77a commit f579115

File tree

13 files changed

+289
-560
lines changed

13 files changed

+289
-560
lines changed

packages/core/test/render3/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ ts_library(
7676

7777
jasmine_node_test(
7878
name = "render3",
79-
bootstrap = [":domino_es5"],
79+
bootstrap = [
80+
":domino_es5",
81+
"//tools/testing:node_es5",
82+
],
8083
deps = [
8184
":render3_node_lib",
8285
"//packages/zone.js/lib",

packages/core/test/render3/ivy/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ ts_library(
1616

1717
jasmine_node_test(
1818
name = "ivy",
19-
bootstrap = ["//packages/core/test/render3:domino_es5"],
19+
bootstrap = [
20+
"//packages/core/test/render3:domino_es5",
21+
"//tools/testing:node_es5",
22+
],
2023
tags = [
2124
"ivy-only",
2225
],

packages/core/test/render3/load_domino.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
// Needed to run animation tests
10-
import 'zone.js/lib/node/rollup-main';
1110
import '@angular/compiler'; // For JIT mode. Must be in front of any other @angular/* imports.
1211
import {ɵgetDOM as getDOM} from '@angular/common';
1312
import {DominoAdapter} from '@angular/platform-server/src/domino_adapter';

packages/core/testing/src/async.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
9-
import {asyncFallback} from './async_fallback';
10-
118
/**
129
* Wraps a test function in an asynchronous test zone. The test will automatically
1310
* complete when all asynchronous calls within this zone are done. Can be used
@@ -38,10 +35,11 @@ export function waitForAsync(fn: Function): (done: any) => any {
3835
if (typeof asyncTest === 'function') {
3936
return asyncTest(fn);
4037
}
41-
// not using new version of zone.js
42-
// TODO @JiaLiPassion, remove this after all library updated to
43-
// newest version of zone.js(0.8.25)
44-
return asyncFallback(fn);
38+
return function() {
39+
return Promise.reject(
40+
'zone-testing.js is needed for the async() test helper but could not be found. ' +
41+
'Please make sure that your environment includes zone.js/dist/zone-testing.js');
42+
};
4543
}
4644

4745
/**

packages/core/testing/src/async_fallback.ts

Lines changed: 0 additions & 118 deletions
This file was deleted.

packages/core/testing/src/fake_async.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import {discardPeriodicTasksFallback, fakeAsyncFallback, flushFallback, flushMicrotasksFallback, resetFakeAsyncZoneFallback, tickFallback} from './fake_async_fallback';
9-
108
const _Zone: any = typeof Zone !== 'undefined' ? Zone : null;
119
const fakeAsyncTestModule = _Zone && _Zone[_Zone.__symbol__('fakeAsyncTest')];
1210

11+
const fakeAsyncTestModuleNotLoadedErrorMessage =
12+
`zone-testing.js is needed for the async() test helper but could not be found.
13+
Please make sure that your environment includes zone.js/dist/zone-testing.js`;
14+
1315
/**
1416
* Clears out the shared fake async zone for a test.
1517
* To be called in a global `beforeEach`.
@@ -19,9 +21,8 @@ const fakeAsyncTestModule = _Zone && _Zone[_Zone.__symbol__('fakeAsyncTest')];
1921
export function resetFakeAsyncZone(): void {
2022
if (fakeAsyncTestModule) {
2123
return fakeAsyncTestModule.resetFakeAsyncZone();
22-
} else {
23-
return resetFakeAsyncZoneFallback();
2424
}
25+
throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
2526
}
2627

2728
/**
@@ -46,9 +47,8 @@ export function resetFakeAsyncZone(): void {
4647
export function fakeAsync(fn: Function): (...args: any[]) => any {
4748
if (fakeAsyncTestModule) {
4849
return fakeAsyncTestModule.fakeAsync(fn);
49-
} else {
50-
return fakeAsyncFallback(fn);
5150
}
51+
throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
5252
}
5353

5454
/**
@@ -108,9 +108,8 @@ export function tick(
108108
}): void {
109109
if (fakeAsyncTestModule) {
110110
return fakeAsyncTestModule.tick(millis, tickOptions);
111-
} else {
112-
return tickFallback(millis, tickOptions);
113111
}
112+
throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
114113
}
115114

116115
/**
@@ -126,9 +125,8 @@ export function tick(
126125
export function flush(maxTurns?: number): number {
127126
if (fakeAsyncTestModule) {
128127
return fakeAsyncTestModule.flush(maxTurns);
129-
} else {
130-
return flushFallback(maxTurns);
131128
}
129+
throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
132130
}
133131

134132
/**
@@ -139,9 +137,8 @@ export function flush(maxTurns?: number): number {
139137
export function discardPeriodicTasks(): void {
140138
if (fakeAsyncTestModule) {
141139
return fakeAsyncTestModule.discardPeriodicTasks();
142-
} else {
143-
discardPeriodicTasksFallback();
144140
}
141+
throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
145142
}
146143

147144
/**
@@ -152,7 +149,6 @@ export function discardPeriodicTasks(): void {
152149
export function flushMicrotasks(): void {
153150
if (fakeAsyncTestModule) {
154151
return fakeAsyncTestModule.flushMicrotasks();
155-
} else {
156-
return flushMicrotasksFallback();
157152
}
153+
throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
158154
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy