@angular/core 17.0.0-next.3 → 17.0.0-next.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2022/src/core.mjs +2 -2
- package/esm2022/src/core_private_export.mjs +3 -1
- package/esm2022/src/core_reactivity_export_internal.mjs +3 -3
- package/esm2022/src/core_render3_private_export.mjs +3 -2
- package/esm2022/src/di/initializer_token.mjs +1 -1
- package/esm2022/src/di/internal_tokens.mjs +1 -1
- package/esm2022/src/di/r3_injector.mjs +3 -4
- package/esm2022/src/errors.mjs +1 -1
- package/esm2022/src/metadata/directives.mjs +1 -1
- package/esm2022/src/metadata/ng_module_def.mjs +1 -1
- package/esm2022/src/metadata/resource_loading.mjs +27 -14
- package/esm2022/src/render3/after_render_hooks.mjs +123 -30
- package/esm2022/src/render3/component_ref.mjs +3 -4
- package/esm2022/src/render3/deps_tracker/api.mjs +1 -1
- package/esm2022/src/render3/deps_tracker/deps_tracker.mjs +13 -3
- package/esm2022/src/render3/index.mjs +2 -2
- package/esm2022/src/render3/instructions/change_detection.mjs +3 -3
- package/esm2022/src/render3/instructions/defer.mjs +121 -40
- package/esm2022/src/render3/interfaces/defer.mjs +66 -1
- package/esm2022/src/render3/interfaces/definition.mjs +1 -1
- package/esm2022/src/render3/interfaces/view.mjs +1 -1
- package/esm2022/src/render3/jit/directive.mjs +6 -2
- package/esm2022/src/render3/local_compilation.mjs +8 -2
- package/esm2022/src/render3/pipe.mjs +2 -1
- package/esm2022/src/render3/reactive_lview_consumer.mjs +1 -1
- package/esm2022/src/render3/reactivity/effect.mjs +134 -43
- package/esm2022/src/render3/scope.mjs +10 -4
- package/esm2022/src/signals/index.mjs +2 -2
- package/esm2022/src/signals/src/api.mjs +2 -2
- package/esm2022/src/signals/src/computed.mjs +50 -45
- package/esm2022/src/signals/src/graph.mjs +10 -2
- package/esm2022/src/signals/src/signal.mjs +11 -6
- package/esm2022/src/signals/src/watch.mjs +40 -12
- package/esm2022/src/version.mjs +1 -1
- package/esm2022/testing/src/component_fixture.mjs +20 -3
- package/esm2022/testing/src/defer.mjs +84 -0
- package/esm2022/testing/src/logger.mjs +3 -3
- package/esm2022/testing/src/test_bed.mjs +24 -3
- package/esm2022/testing/src/test_bed_common.mjs +1 -1
- package/esm2022/testing/src/test_bed_compiler.mjs +7 -4
- package/esm2022/testing/src/testing.mjs +3 -1
- package/fesm2022/core.mjs +694 -285
- package/fesm2022/core.mjs.map +1 -1
- package/fesm2022/rxjs-interop.mjs +1 -1
- package/fesm2022/testing.mjs +124 -7
- package/fesm2022/testing.mjs.map +1 -1
- package/index.d.ts +260 -25
- package/package.json +3 -3
- package/rxjs-interop/index.d.ts +1 -1
- package/schematics/migrations/guard-and-resolve-interfaces/bundle.js +13 -13
- package/schematics/migrations/remove-module-id/bundle.js +14 -14
- package/schematics/ng-generate/standalone-migration/bundle.js +1962 -1303
- package/schematics/ng-generate/standalone-migration/bundle.js.map +4 -4
- package/testing/index.d.ts +50 -2
package/fesm2022/testing.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v17.0.0-next.
|
|
2
|
+
* @license Angular v17.0.0-next.5
|
|
3
3
|
* (c) 2010-2022 Google LLC. https://angular.io/
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { getDebugNode, RendererFactory2, InjectionToken, ɵstringify, ɵReflectionCapabilities, Directive, Component, Pipe, NgModule, ɵgetAsyncClassMetadata, ɵgenerateStandaloneInDeclarationsError, ɵUSE_RUNTIME_DEPS_TRACKER_FOR_JIT, ɵdepsTracker, ɵgetInjectableDef, resolveForwardRef, ɵNG_COMP_DEF, ɵisComponentDefPendingResolution, ɵresolveComponentResources, ɵRender3NgModuleRef, ApplicationInitStatus, LOCALE_ID, ɵDEFAULT_LOCALE_ID, ɵsetLocaleId, ɵRender3ComponentFactory, ɵcompileComponent, ɵNG_DIR_DEF, ɵcompileDirective, ɵNG_PIPE_DEF, ɵcompilePipe, ɵNG_MOD_DEF, ɵtransitiveScopesFor, ɵpatchComponentDefWithScope, ɵNG_INJ_DEF, ɵcompileNgModuleDefs, ɵclearResolutionOfComponentResourcesQueue, ɵrestoreComponentResolutionQueue, provideZoneChangeDetection, Compiler, COMPILER_OPTIONS, Injector, ɵisEnvironmentProviders, ɵNgModuleFactory, ModuleWithComponentFactories, ɵconvertToBitFlags, InjectFlags, ɵsetAllowDuplicateNgModuleIdsForTest, ɵresetCompiledComponents, ɵsetUnknownElementStrictMode, ɵsetUnknownPropertyStrictMode, ɵgetUnknownElementStrictMode, ɵgetUnknownPropertyStrictMode, EnvironmentInjector, NgZone, ɵflushModuleScopingQueueAsMuchAsPossible } from '@angular/core';
|
|
7
|
+
import { ɵDeferBlockState, ɵtriggerResourceLoading, ɵrenderDeferBlockState, ɵCONTAINER_HEADER_OFFSET, ɵgetDeferBlocks, getDebugNode, RendererFactory2, InjectionToken, ɵstringify, ɵReflectionCapabilities, Directive, Component, Pipe, NgModule, ɵgetAsyncClassMetadata, ɵgenerateStandaloneInDeclarationsError, ɵDeferBlockBehavior, ɵUSE_RUNTIME_DEPS_TRACKER_FOR_JIT, ɵdepsTracker, ɵgetInjectableDef, resolveForwardRef, ɵNG_COMP_DEF, ɵisComponentDefPendingResolution, ɵresolveComponentResources, ɵRender3NgModuleRef, ApplicationInitStatus, LOCALE_ID, ɵDEFAULT_LOCALE_ID, ɵsetLocaleId, ɵRender3ComponentFactory, ɵcompileComponent, ɵNG_DIR_DEF, ɵcompileDirective, ɵNG_PIPE_DEF, ɵcompilePipe, ɵNG_MOD_DEF, ɵtransitiveScopesFor, ɵpatchComponentDefWithScope, ɵNG_INJ_DEF, ɵcompileNgModuleDefs, ɵclearResolutionOfComponentResourcesQueue, ɵrestoreComponentResolutionQueue, provideZoneChangeDetection, Compiler, ɵDEFER_BLOCK_CONFIG, COMPILER_OPTIONS, Injector, ɵisEnvironmentProviders, ɵNgModuleFactory, ModuleWithComponentFactories, ɵconvertToBitFlags, InjectFlags, ɵsetAllowDuplicateNgModuleIdsForTest, ɵresetCompiledComponents, ɵsetUnknownElementStrictMode, ɵsetUnknownPropertyStrictMode, ɵgetUnknownElementStrictMode, ɵgetUnknownPropertyStrictMode, EnvironmentInjector, NgZone, ɵZoneAwareQueueingScheduler, ɵflushModuleScopingQueueAsMuchAsPossible } from '@angular/core';
|
|
8
|
+
export { ɵDeferBlockBehavior as DeferBlockBehavior, ɵDeferBlockState as DeferBlockState } from '@angular/core';
|
|
8
9
|
import { ResourceLoader } from '@angular/compiler';
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -50,15 +51,93 @@ function async(fn) {
|
|
|
50
51
|
return waitForAsync(fn);
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Represents an individual `{#defer}` block for testing purposes.
|
|
56
|
+
*
|
|
57
|
+
* @publicApi
|
|
58
|
+
* @developerPreview
|
|
59
|
+
*/
|
|
60
|
+
class DeferBlockFixture {
|
|
61
|
+
/** @nodoc */
|
|
62
|
+
constructor(block, componentFixture) {
|
|
63
|
+
this.block = block;
|
|
64
|
+
this.componentFixture = componentFixture;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Renders the specified state of the defer fixture.
|
|
68
|
+
* @param state the defer state to render
|
|
69
|
+
*/
|
|
70
|
+
async render(state) {
|
|
71
|
+
if (!hasStateTemplate(state, this.block)) {
|
|
72
|
+
const stateAsString = getDeferBlockStateNameFromEnum(state);
|
|
73
|
+
throw new Error(`Tried to render this defer block in the \`${stateAsString}\` state, ` +
|
|
74
|
+
`but there was no \`{:${stateAsString.toLowerCase()}}\` section defined in a template.`);
|
|
75
|
+
}
|
|
76
|
+
if (state === ɵDeferBlockState.Complete) {
|
|
77
|
+
await ɵtriggerResourceLoading(this.block.tDetails, this.block.lView);
|
|
78
|
+
}
|
|
79
|
+
ɵrenderDeferBlockState(state, this.block.tNode, this.block.lContainer);
|
|
80
|
+
this.componentFixture.detectChanges();
|
|
81
|
+
return this.componentFixture.whenStable();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Retrieves all nested child defer block fixtures
|
|
85
|
+
* in a given defer block.
|
|
86
|
+
*/
|
|
87
|
+
getDeferBlocks() {
|
|
88
|
+
const deferBlocks = [];
|
|
89
|
+
// An LContainer that represents a defer block has at most 1 view, which is
|
|
90
|
+
// located right after an LContainer header. Get a hold of that view and inspect
|
|
91
|
+
// it for nested defer blocks.
|
|
92
|
+
const deferBlockFixtures = [];
|
|
93
|
+
if (this.block.lContainer.length >= ɵCONTAINER_HEADER_OFFSET) {
|
|
94
|
+
const lView = this.block.lContainer[ɵCONTAINER_HEADER_OFFSET];
|
|
95
|
+
ɵgetDeferBlocks(lView, deferBlocks);
|
|
96
|
+
for (const block of deferBlocks) {
|
|
97
|
+
deferBlockFixtures.push(new DeferBlockFixture(block, this.componentFixture));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return Promise.resolve(deferBlockFixtures);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function hasStateTemplate(state, block) {
|
|
104
|
+
switch (state) {
|
|
105
|
+
case ɵDeferBlockState.Placeholder:
|
|
106
|
+
return block.tDetails.placeholderTmplIndex !== null;
|
|
107
|
+
case ɵDeferBlockState.Loading:
|
|
108
|
+
return block.tDetails.loadingTmplIndex !== null;
|
|
109
|
+
case ɵDeferBlockState.Error:
|
|
110
|
+
return block.tDetails.errorTmplIndex !== null;
|
|
111
|
+
case ɵDeferBlockState.Complete:
|
|
112
|
+
return true;
|
|
113
|
+
default:
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function getDeferBlockStateNameFromEnum(state) {
|
|
118
|
+
switch (state) {
|
|
119
|
+
case ɵDeferBlockState.Placeholder:
|
|
120
|
+
return 'Placeholder';
|
|
121
|
+
case ɵDeferBlockState.Loading:
|
|
122
|
+
return 'Loading';
|
|
123
|
+
case ɵDeferBlockState.Error:
|
|
124
|
+
return 'Error';
|
|
125
|
+
default:
|
|
126
|
+
return 'Main';
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
53
130
|
/**
|
|
54
131
|
* Fixture for debugging and testing a component.
|
|
55
132
|
*
|
|
56
133
|
* @publicApi
|
|
57
134
|
*/
|
|
58
135
|
class ComponentFixture {
|
|
59
|
-
|
|
136
|
+
/** @nodoc */
|
|
137
|
+
constructor(componentRef, ngZone, effectRunner, _autoDetect) {
|
|
60
138
|
this.componentRef = componentRef;
|
|
61
139
|
this.ngZone = ngZone;
|
|
140
|
+
this.effectRunner = effectRunner;
|
|
62
141
|
this._autoDetect = _autoDetect;
|
|
63
142
|
this._isStable = true;
|
|
64
143
|
this._isDestroyed = false;
|
|
@@ -131,6 +210,7 @@ class ComponentFixture {
|
|
|
131
210
|
* Trigger a change detection cycle for the component.
|
|
132
211
|
*/
|
|
133
212
|
detectChanges(checkNoChanges = true) {
|
|
213
|
+
this.effectRunner?.flush();
|
|
134
214
|
if (this.ngZone != null) {
|
|
135
215
|
// Run the change detection inside the NgZone so that any async tasks as part of the change
|
|
136
216
|
// detection are captured by the zone and can be waited for in isStable.
|
|
@@ -188,6 +268,19 @@ class ComponentFixture {
|
|
|
188
268
|
return this._promise;
|
|
189
269
|
}
|
|
190
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Retrieves all defer block fixtures in the component fixture
|
|
273
|
+
*/
|
|
274
|
+
getDeferBlocks() {
|
|
275
|
+
const deferBlocks = [];
|
|
276
|
+
const lView = this.componentRef.hostView['_lView'];
|
|
277
|
+
ɵgetDeferBlocks(lView, deferBlocks);
|
|
278
|
+
const deferBlockFixtures = [];
|
|
279
|
+
for (const block of deferBlocks) {
|
|
280
|
+
deferBlockFixtures.push(new DeferBlockFixture(block, this));
|
|
281
|
+
}
|
|
282
|
+
return Promise.resolve(deferBlockFixtures);
|
|
283
|
+
}
|
|
191
284
|
_getRenderer() {
|
|
192
285
|
if (this._renderer === undefined) {
|
|
193
286
|
this._renderer = this.componentRef.injector.get(RendererFactory2, null);
|
|
@@ -672,6 +765,7 @@ class TestBedCompiler {
|
|
|
672
765
|
this.providerOverridesByToken = new Map();
|
|
673
766
|
this.scopesWithOverriddenProviders = new Set();
|
|
674
767
|
this.testModuleRef = null;
|
|
768
|
+
this.deferBlockBehavior = ɵDeferBlockBehavior.Manual;
|
|
675
769
|
class DynamicTestModule {
|
|
676
770
|
}
|
|
677
771
|
this.testModuleType = DynamicTestModule;
|
|
@@ -699,6 +793,7 @@ class TestBedCompiler {
|
|
|
699
793
|
if (moduleDef.schemas !== undefined) {
|
|
700
794
|
this.schemas.push(...moduleDef.schemas);
|
|
701
795
|
}
|
|
796
|
+
this.deferBlockBehavior = moduleDef.deferBlockBehavior ?? ɵDeferBlockBehavior.Manual;
|
|
702
797
|
}
|
|
703
798
|
overrideModule(ngModule, override) {
|
|
704
799
|
if (ɵUSE_RUNTIME_DEPS_TRACKER_FOR_JIT) {
|
|
@@ -775,7 +870,7 @@ class TestBedCompiler {
|
|
|
775
870
|
const def = type[ɵNG_COMP_DEF];
|
|
776
871
|
const hasStyleUrls = () => {
|
|
777
872
|
const metadata = this.resolvers.component.resolve(type);
|
|
778
|
-
return !!metadata.
|
|
873
|
+
return !!metadata.styleUrl || !!metadata.styleUrls?.length;
|
|
779
874
|
};
|
|
780
875
|
const overrideStyleUrls = !!def && !ɵisComponentDefPendingResolution(type) && hasStyleUrls();
|
|
781
876
|
// In Ivy, compiling a component does not require knowing the module providing the
|
|
@@ -785,7 +880,7 @@ class TestBedCompiler {
|
|
|
785
880
|
// resolution). In order to avoid this, we preemptively set styleUrls to an empty array,
|
|
786
881
|
// preserve current styles available on Component def and restore styles back once compilation
|
|
787
882
|
// is complete.
|
|
788
|
-
const override = overrideStyleUrls ? { template, styles: [], styleUrls: [] } : { template };
|
|
883
|
+
const override = overrideStyleUrls ? { template, styles: [], styleUrls: [], styleUrl: undefined } : { template };
|
|
789
884
|
this.overrideComponent(type, { set: override });
|
|
790
885
|
if (overrideStyleUrls && def.styles && def.styles.length > 0) {
|
|
791
886
|
this.existingComponentStyles.set(type, def.styles);
|
|
@@ -1287,6 +1382,7 @@ class TestBedCompiler {
|
|
|
1287
1382
|
const providers = [
|
|
1288
1383
|
provideZoneChangeDetection(),
|
|
1289
1384
|
{ provide: Compiler, useFactory: () => new R3TestCompiler(this) },
|
|
1385
|
+
{ provide: ɵDEFER_BLOCK_CONFIG, useValue: { behavior: this.deferBlockBehavior } },
|
|
1290
1386
|
...this.providers,
|
|
1291
1387
|
...this.providerOverrides,
|
|
1292
1388
|
];
|
|
@@ -1496,6 +1592,11 @@ function getTestBed() {
|
|
|
1496
1592
|
*/
|
|
1497
1593
|
class TestBedImpl {
|
|
1498
1594
|
constructor() {
|
|
1595
|
+
/**
|
|
1596
|
+
* Defer block behavior option that specifies whether defer blocks will be triggered manually
|
|
1597
|
+
* or set to play through.
|
|
1598
|
+
*/
|
|
1599
|
+
this._instanceDeferBlockBehavior = ɵDeferBlockBehavior.Manual;
|
|
1499
1600
|
// Properties
|
|
1500
1601
|
this.platform = null;
|
|
1501
1602
|
this.ngModule = null;
|
|
@@ -1614,6 +1715,9 @@ class TestBedImpl {
|
|
|
1614
1715
|
static get ngModule() {
|
|
1615
1716
|
return TestBedImpl.INSTANCE.ngModule;
|
|
1616
1717
|
}
|
|
1718
|
+
static flushEffects() {
|
|
1719
|
+
return TestBedImpl.INSTANCE.flushEffects();
|
|
1720
|
+
}
|
|
1617
1721
|
/**
|
|
1618
1722
|
* Initialize the environment for testing with a compiler factory, a PlatformRef, and an
|
|
1619
1723
|
* angular module. These are common to every test in the suite.
|
|
@@ -1684,6 +1788,7 @@ class TestBedImpl {
|
|
|
1684
1788
|
this._instanceTeardownOptions = undefined;
|
|
1685
1789
|
this._instanceErrorOnUnknownElementsOption = undefined;
|
|
1686
1790
|
this._instanceErrorOnUnknownPropertiesOption = undefined;
|
|
1791
|
+
this._instanceDeferBlockBehavior = ɵDeferBlockBehavior.Manual;
|
|
1687
1792
|
}
|
|
1688
1793
|
}
|
|
1689
1794
|
return this;
|
|
@@ -1709,6 +1814,7 @@ class TestBedImpl {
|
|
|
1709
1814
|
this._instanceTeardownOptions = moduleDef.teardown;
|
|
1710
1815
|
this._instanceErrorOnUnknownElementsOption = moduleDef.errorOnUnknownElements;
|
|
1711
1816
|
this._instanceErrorOnUnknownPropertiesOption = moduleDef.errorOnUnknownProperties;
|
|
1817
|
+
this._instanceDeferBlockBehavior = moduleDef.deferBlockBehavior ?? ɵDeferBlockBehavior.Manual;
|
|
1712
1818
|
// Store the current value of the strict mode option,
|
|
1713
1819
|
// so we can restore it later
|
|
1714
1820
|
this._previousErrorOnUnknownElementsOption = ɵgetUnknownElementStrictMode();
|
|
@@ -1795,7 +1901,7 @@ class TestBedImpl {
|
|
|
1795
1901
|
const componentFactory = new ɵRender3ComponentFactory(componentDef);
|
|
1796
1902
|
const initComponent = () => {
|
|
1797
1903
|
const componentRef = componentFactory.create(Injector.NULL, [], `#${rootElId}`, this.testModuleRef);
|
|
1798
|
-
return new ComponentFixture(componentRef, ngZone, autoDetect);
|
|
1904
|
+
return new ComponentFixture(componentRef, ngZone, this.inject(ɵZoneAwareQueueingScheduler, null), autoDetect);
|
|
1799
1905
|
};
|
|
1800
1906
|
const fixture = ngZone ? ngZone.run(initComponent) : initComponent();
|
|
1801
1907
|
this._activeFixtures.push(fixture);
|
|
@@ -1894,6 +2000,9 @@ class TestBedImpl {
|
|
|
1894
2000
|
TestBedImpl._environmentTeardownOptions?.destroyAfterEach ??
|
|
1895
2001
|
TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT;
|
|
1896
2002
|
}
|
|
2003
|
+
getDeferBlockBehavior() {
|
|
2004
|
+
return this._instanceDeferBlockBehavior;
|
|
2005
|
+
}
|
|
1897
2006
|
tearDownTestingModule() {
|
|
1898
2007
|
// If the module ref has already been destroyed, we won't be able to get a test renderer.
|
|
1899
2008
|
if (this._testModuleRef === null) {
|
|
@@ -1920,6 +2029,14 @@ class TestBedImpl {
|
|
|
1920
2029
|
testRenderer.removeAllRootElements?.();
|
|
1921
2030
|
}
|
|
1922
2031
|
}
|
|
2032
|
+
/**
|
|
2033
|
+
* Execute any pending effects.
|
|
2034
|
+
*
|
|
2035
|
+
* @developerPreview
|
|
2036
|
+
*/
|
|
2037
|
+
flushEffects() {
|
|
2038
|
+
this.inject(ɵZoneAwareQueueingScheduler).flush();
|
|
2039
|
+
}
|
|
1923
2040
|
}
|
|
1924
2041
|
/**
|
|
1925
2042
|
* @description
|
|
@@ -2046,5 +2163,5 @@ const __core_private_testing_placeholder__ = '';
|
|
|
2046
2163
|
* Generated bundle index. Do not edit.
|
|
2047
2164
|
*/
|
|
2048
2165
|
|
|
2049
|
-
export { ComponentFixture, ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, InjectSetupWrapper, TestBed, TestComponentRenderer, __core_private_testing_placeholder__, async, discardPeriodicTasks, fakeAsync, flush, flushMicrotasks, getTestBed, inject, resetFakeAsyncZone, tick, waitForAsync, withModule, MetadataOverrider as ɵMetadataOverrider };
|
|
2166
|
+
export { ComponentFixture, ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, DeferBlockFixture, InjectSetupWrapper, TestBed, TestComponentRenderer, __core_private_testing_placeholder__, async, discardPeriodicTasks, fakeAsync, flush, flushMicrotasks, getTestBed, inject, resetFakeAsyncZone, tick, waitForAsync, withModule, MetadataOverrider as ɵMetadataOverrider };
|
|
2050
2167
|
//# sourceMappingURL=testing.mjs.map
|