@angular/core 12.1.0-next.6 → 12.1.3
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/bundles/core-testing.umd.js +239 -46
- package/bundles/core-testing.umd.js.map +1 -1
- package/bundles/core.umd.js +126 -49
- package/bundles/core.umd.js.map +1 -1
- package/core.d.ts +45 -19
- package/core.metadata.json +1 -1
- package/esm2015/src/application_init.js +5 -5
- package/esm2015/src/application_ref.js +34 -9
- package/esm2015/src/change_detection/differs/iterable_differs.js +1 -1
- package/esm2015/src/compiler/compiler_facade.js +31 -8
- package/esm2015/src/compiler/compiler_facade_interface.js +1 -1
- package/esm2015/src/di/jit/injectable.js +4 -3
- package/esm2015/src/di/r3_injector.js +5 -2
- package/esm2015/src/error_handler.js +2 -6
- package/esm2015/src/event_emitter.js +1 -1
- package/esm2015/src/linker/component_factory_resolver.js +1 -1
- package/esm2015/src/linker/template_ref.js +1 -1
- package/esm2015/src/linker/view_container_ref.js +1 -1
- package/esm2015/src/metadata/di.js +1 -1
- package/esm2015/src/metadata/do_boostrap.js +1 -1
- package/esm2015/src/render3/component_ref.js +1 -1
- package/esm2015/src/render3/jit/directive.js +6 -5
- package/esm2015/src/render3/jit/module.js +7 -4
- package/esm2015/src/render3/jit/partial.js +27 -9
- package/esm2015/src/render3/jit/pipe.js +5 -3
- package/esm2015/src/render3/ng_module_ref.js +1 -1
- package/esm2015/src/render3/view_ref.js +1 -1
- package/esm2015/src/sanitization/bypass.js +1 -1
- package/esm2015/src/version.js +1 -1
- package/esm2015/src/view/entrypoint.js +1 -1
- package/esm2015/src/view/refs.js +1 -1
- package/esm2015/testing/src/ng_zone_mock.js +1 -1
- package/esm2015/testing/src/r3_test_bed.js +84 -7
- package/esm2015/testing/src/r3_test_bed_compiler.js +4 -1
- package/esm2015/testing/src/resolvers.js +1 -1
- package/esm2015/testing/src/test_bed.js +110 -21
- package/esm2015/testing/src/test_bed_common.js +7 -1
- package/esm2015/testing/src/test_hooks.js +45 -0
- package/esm2015/testing/src/testing.js +3 -3
- package/fesm2015/core.js +116 -45
- package/fesm2015/core.js.map +1 -1
- package/fesm2015/testing.js +216 -29
- package/fesm2015/testing.js.map +1 -1
- package/package.json +1 -1
- package/schematics/migrations/missing-injectable/providers_evaluator.js +1 -1
- package/schematics/migrations/static-queries/strategies/usage_strategy/template_usage_visitor.js +1 -1
- package/schematics/migrations/template-var-assignment/angular/html_variable_assignment_visitor.js +1 -1
- package/schematics/migrations.json +1 -1
- package/src/r3_symbols.d.ts +2 -3
- package/testing/testing.d.ts +64 -5
- package/testing/testing.metadata.json +1 -1
- package/testing.d.ts +1 -1
- package/esm2015/testing/src/before_each.js +0 -33
- package/schematics/migrations/abstract-control-parent/abstract-control-parent.externs.js +0 -0
- package/schematics/migrations/abstract-control-parent/index.mjs +0 -47
- package/schematics/migrations/abstract-control-parent/util.mjs +0 -50
- package/schematics/migrations/activated-route-snapshot-fragment/activated-route-snapshot-fragment.externs.js +0 -0
- package/schematics/migrations/activated-route-snapshot-fragment/index.mjs +0 -48
- package/schematics/migrations/activated-route-snapshot-fragment/util.mjs +0 -33
- package/schematics/migrations/can-activate-with-redirect-to/can-activate-with-redirect-to.externs.js +0 -0
- package/schematics/migrations/can-activate-with-redirect-to/index.mjs +0 -44
- package/schematics/migrations/can-activate-with-redirect-to/util.mjs +0 -55
- package/schematics/migrations/deep-shadow-piercing-selector/deep-shadow-piercing-selector.externs.js +0 -0
- package/schematics/migrations/deep-shadow-piercing-selector/index.mjs +0 -36
- package/schematics/migrations/dynamic-queries/dynamic-queries.externs.js +0 -0
- package/schematics/migrations/dynamic-queries/index.mjs +0 -51
- package/schematics/migrations/dynamic-queries/util.mjs +0 -65
- package/schematics/migrations/initial-navigation/collector.mjs +0 -105
- package/schematics/migrations/initial-navigation/index.mjs +0 -61
- package/schematics/migrations/initial-navigation/initial-navigation.externs.js +0 -0
- package/schematics/migrations/initial-navigation/transform.mjs +0 -54
- package/schematics/migrations/initial-navigation/update_recorder.mjs +0 -9
- package/schematics/migrations/initial-navigation/util.mjs +0 -28
- package/schematics/migrations/missing-injectable/definition_collector.mjs +0 -75
- package/schematics/migrations/missing-injectable/index.mjs +0 -100
- package/schematics/migrations/missing-injectable/missing-injectable.externs.js +0 -0
- package/schematics/migrations/missing-injectable/providers_evaluator.mjs +0 -50
- package/schematics/migrations/missing-injectable/transform.mjs +0 -187
- package/schematics/migrations/missing-injectable/update_recorder.mjs +0 -9
- package/schematics/migrations/module-with-providers/collector.mjs +0 -59
- package/schematics/migrations/module-with-providers/index.mjs +0 -71
- package/schematics/migrations/module-with-providers/module-with-providers.externs.js +0 -0
- package/schematics/migrations/module-with-providers/transform.mjs +0 -134
- package/schematics/migrations/module-with-providers/util.mjs +0 -25
- package/schematics/migrations/move-document/document_import_visitor.mjs +0 -60
- package/schematics/migrations/move-document/index.mjs +0 -71
- package/schematics/migrations/move-document/move-document.externs.js +0 -0
- package/schematics/migrations/move-document/move-import.mjs +0 -45
- package/schematics/migrations/native-view-encapsulation/index.mjs +0 -41
- package/schematics/migrations/native-view-encapsulation/native-view-encapsulation.externs.js +0 -0
- package/schematics/migrations/native-view-encapsulation/util.mjs +0 -34
- package/schematics/migrations/navigation-extras-omissions/index.mjs +0 -47
- package/schematics/migrations/navigation-extras-omissions/navigation-extras-omissions.externs.js +0 -0
- package/schematics/migrations/navigation-extras-omissions/util.mjs +0 -111
- package/schematics/migrations/relative-link-resolution/collector.mjs +0 -81
- package/schematics/migrations/relative-link-resolution/index.mjs +0 -62
- package/schematics/migrations/relative-link-resolution/relative-link-resolution.externs.js +0 -0
- package/schematics/migrations/relative-link-resolution/transform.mjs +0 -51
- package/schematics/migrations/relative-link-resolution/update_recorder.mjs +0 -9
- package/schematics/migrations/relative-link-resolution/util.mjs +0 -28
- package/schematics/migrations/renderer-to-renderer2/helpers.mjs +0 -224
- package/schematics/migrations/renderer-to-renderer2/index.mjs +0 -113
- package/schematics/migrations/renderer-to-renderer2/migration.mjs +0 -211
- package/schematics/migrations/renderer-to-renderer2/renderer-to-renderer2.externs.js +0 -0
- package/schematics/migrations/renderer-to-renderer2/util.mjs +0 -69
- package/schematics/migrations/router-preserve-query-params/index.mjs +0 -50
- package/schematics/migrations/router-preserve-query-params/router-preserve-query-params.externs.js +0 -0
- package/schematics/migrations/router-preserve-query-params/util.mjs +0 -88
- package/schematics/migrations/static-queries/angular/directive_inputs.mjs +0 -70
- package/schematics/migrations/static-queries/angular/ng_query_visitor.mjs +0 -113
- package/schematics/migrations/static-queries/angular/query-definition.mjs +0 -20
- package/schematics/migrations/static-queries/angular/super_class.mjs +0 -21
- package/schematics/migrations/static-queries/index.mjs +0 -206
- package/schematics/migrations/static-queries/static-queries.externs.js +0 -0
- package/schematics/migrations/static-queries/strategies/template_strategy/template_strategy.mjs +0 -200
- package/schematics/migrations/static-queries/strategies/test_strategy/test_strategy.mjs +0 -24
- package/schematics/migrations/static-queries/strategies/timing-strategy.mjs +0 -9
- package/schematics/migrations/static-queries/strategies/usage_strategy/declaration_usage_visitor.mjs +0 -355
- package/schematics/migrations/static-queries/strategies/usage_strategy/super_class_context.mjs +0 -38
- package/schematics/migrations/static-queries/strategies/usage_strategy/template_usage_visitor.mjs +0 -80
- package/schematics/migrations/static-queries/strategies/usage_strategy/usage_strategy.mjs +0 -154
- package/schematics/migrations/static-queries/transform.mjs +0 -88
- package/schematics/migrations/template-var-assignment/analyze_template.mjs +0 -25
- package/schematics/migrations/template-var-assignment/angular/html_variable_assignment_visitor.mjs +0 -65
- package/schematics/migrations/template-var-assignment/index.mjs +0 -68
- package/schematics/migrations/template-var-assignment/template-var-assignment.externs.js +0 -0
- package/schematics/migrations/undecorated-classes-with-decorated-fields/index.mjs +0 -92
- package/schematics/migrations/undecorated-classes-with-decorated-fields/transform.mjs +0 -286
- package/schematics/migrations/undecorated-classes-with-decorated-fields/undecorated-classes-with-decorated-fields.externs.js +0 -0
- package/schematics/migrations/undecorated-classes-with-decorated-fields/update_recorder.mjs +0 -9
- package/schematics/migrations/undecorated-classes-with-di/create_ngc_program.mjs +0 -43
- package/schematics/migrations/undecorated-classes-with-di/decorator_rewrite/convert_directive_metadata.mjs +0 -82
- package/schematics/migrations/undecorated-classes-with-di/decorator_rewrite/decorator_rewriter.mjs +0 -102
- package/schematics/migrations/undecorated-classes-with-di/decorator_rewrite/import_rewrite_visitor.mjs +0 -111
- package/schematics/migrations/undecorated-classes-with-di/decorator_rewrite/path_format.mjs +0 -17
- package/schematics/migrations/undecorated-classes-with-di/decorator_rewrite/source_file_exports.mjs +0 -51
- package/schematics/migrations/undecorated-classes-with-di/index.mjs +0 -162
- package/schematics/migrations/undecorated-classes-with-di/ng_declaration_collector.mjs +0 -124
- package/schematics/migrations/undecorated-classes-with-di/transform.mjs +0 -356
- package/schematics/migrations/undecorated-classes-with-di/undecorated-classes-with-di.externs.js +0 -0
- package/schematics/migrations/undecorated-classes-with-di/update_recorder.mjs +0 -9
- package/schematics/migrations/wait-for-async/index.mjs +0 -76
- package/schematics/migrations/wait-for-async/util.mjs +0 -23
- package/schematics/migrations/wait-for-async/wait-for-async.externs.js +0 -0
- package/schematics/migrations/xhr-factory/index.mjs +0 -91
- package/schematics/migrations/xhr-factory/xhr-factory.externs.js +0 -0
- package/schematics/utils/import_manager.mjs +0 -197
- package/schematics/utils/line_mappings.mjs +0 -60
- package/schematics/utils/ng_component_template.mjs +0 -96
- package/schematics/utils/ng_decorators.mjs +0 -23
- package/schematics/utils/parse_html.mjs +0 -24
- package/schematics/utils/project_tsconfig_paths.mjs +0 -74
- package/schematics/utils/schematics_prompt.mjs +0 -30
- package/schematics/utils/typescript/class_declaration.mjs +0 -33
- package/schematics/utils/typescript/compiler_host.mjs +0 -66
- package/schematics/utils/typescript/decorators.mjs +0 -20
- package/schematics/utils/typescript/find_base_classes.mjs +0 -30
- package/schematics/utils/typescript/functions.mjs +0 -28
- package/schematics/utils/typescript/imports.mjs +0 -91
- package/schematics/utils/typescript/nodes.mjs +0 -57
- package/schematics/utils/typescript/parse_tsconfig.mjs +0 -26
- package/schematics/utils/typescript/property_name.mjs +0 -23
- package/schematics/utils/typescript/symbol.mjs +0 -72
- package/schematics/utils/utils.externs.js +0 -0
package/fesm2015/testing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v12.1.
|
|
2
|
+
* @license Angular v12.1.3
|
|
3
3
|
* (c) 2010-2021 Google LLC. https://angular.io/
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
@@ -1176,6 +1176,9 @@ class R3TestBedCompiler {
|
|
|
1176
1176
|
queueTypesFromModulesArrayRecur(maybeUnwrapFn(def.imports));
|
|
1177
1177
|
queueTypesFromModulesArrayRecur(maybeUnwrapFn(def.exports));
|
|
1178
1178
|
}
|
|
1179
|
+
else if (isModuleWithProviders(value)) {
|
|
1180
|
+
queueTypesFromModulesArrayRecur([value.ngModule]);
|
|
1181
|
+
}
|
|
1179
1182
|
}
|
|
1180
1183
|
};
|
|
1181
1184
|
queueTypesFromModulesArrayRecur(arr);
|
|
@@ -1469,6 +1472,11 @@ class R3TestCompiler {
|
|
|
1469
1472
|
* Use of this source code is governed by an MIT-style license that can be
|
|
1470
1473
|
* found in the LICENSE file at https://angular.io/license
|
|
1471
1474
|
*/
|
|
1475
|
+
/**
|
|
1476
|
+
* Whether test modules should be torn down by default.
|
|
1477
|
+
* Currently disabled for backwards-compatibility reasons.
|
|
1478
|
+
*/
|
|
1479
|
+
const TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT = false;
|
|
1472
1480
|
/**
|
|
1473
1481
|
* An abstract class for inserting the root test component element in a platform independent way.
|
|
1474
1482
|
*
|
|
@@ -1476,6 +1484,7 @@ class R3TestCompiler {
|
|
|
1476
1484
|
*/
|
|
1477
1485
|
class TestComponentRenderer {
|
|
1478
1486
|
insertRootElement(rootElementId) { }
|
|
1487
|
+
removeAllRootElements() { }
|
|
1479
1488
|
}
|
|
1480
1489
|
/**
|
|
1481
1490
|
* @publicApi
|
|
@@ -1527,9 +1536,9 @@ class TestBedRender3 {
|
|
|
1527
1536
|
*
|
|
1528
1537
|
* @publicApi
|
|
1529
1538
|
*/
|
|
1530
|
-
static initTestEnvironment(ngModule, platform,
|
|
1539
|
+
static initTestEnvironment(ngModule, platform, summariesOrOptions) {
|
|
1531
1540
|
const testBed = _getTestBedRender3();
|
|
1532
|
-
testBed.initTestEnvironment(ngModule, platform,
|
|
1541
|
+
testBed.initTestEnvironment(ngModule, platform, summariesOrOptions);
|
|
1533
1542
|
return testBed;
|
|
1534
1543
|
}
|
|
1535
1544
|
/**
|
|
@@ -1608,6 +1617,12 @@ class TestBedRender3 {
|
|
|
1608
1617
|
_getTestBedRender3().resetTestingModule();
|
|
1609
1618
|
return TestBedRender3;
|
|
1610
1619
|
}
|
|
1620
|
+
static shouldTearDownTestingModule() {
|
|
1621
|
+
return _getTestBedRender3().shouldTearDownTestingModule();
|
|
1622
|
+
}
|
|
1623
|
+
static tearDownTestingModule() {
|
|
1624
|
+
_getTestBedRender3().tearDownTestingModule();
|
|
1625
|
+
}
|
|
1611
1626
|
/**
|
|
1612
1627
|
* Initialize the environment for testing with a compiler factory, a PlatformRef, and an
|
|
1613
1628
|
* angular module. These are common to every test in the suite.
|
|
@@ -1621,10 +1636,14 @@ class TestBedRender3 {
|
|
|
1621
1636
|
*
|
|
1622
1637
|
* @publicApi
|
|
1623
1638
|
*/
|
|
1624
|
-
initTestEnvironment(ngModule, platform,
|
|
1639
|
+
initTestEnvironment(ngModule, platform, summariesOrOptions) {
|
|
1625
1640
|
if (this.platform || this.ngModule) {
|
|
1626
1641
|
throw new Error('Cannot set base providers because it has already been called');
|
|
1627
1642
|
}
|
|
1643
|
+
// If `summariesOrOptions` is a function, it means that it's
|
|
1644
|
+
// an AOT summaries factory which Ivy doesn't support.
|
|
1645
|
+
TestBedRender3._environmentTeardownOptions =
|
|
1646
|
+
typeof summariesOrOptions === 'function' ? undefined : summariesOrOptions === null || summariesOrOptions === void 0 ? void 0 : summariesOrOptions.teardown;
|
|
1628
1647
|
this.platform = platform;
|
|
1629
1648
|
this.ngModule = ngModule;
|
|
1630
1649
|
this._compiler = new R3TestBedCompiler(this.platform, this.ngModule);
|
|
@@ -1639,6 +1658,7 @@ class TestBedRender3 {
|
|
|
1639
1658
|
this._compiler = null;
|
|
1640
1659
|
this.platform = null;
|
|
1641
1660
|
this.ngModule = null;
|
|
1661
|
+
TestBedRender3._environmentTeardownOptions = undefined;
|
|
1642
1662
|
}
|
|
1643
1663
|
resetTestingModule() {
|
|
1644
1664
|
this.checkGlobalCompilationFinished();
|
|
@@ -1647,8 +1667,23 @@ class TestBedRender3 {
|
|
|
1647
1667
|
this.compiler.restoreOriginalState();
|
|
1648
1668
|
}
|
|
1649
1669
|
this._compiler = new R3TestBedCompiler(this.platform, this.ngModule);
|
|
1650
|
-
|
|
1651
|
-
|
|
1670
|
+
// We have to chain a couple of try/finally blocks, because each step can
|
|
1671
|
+
// throw errors and we don't want it to interrupt the next step and we also
|
|
1672
|
+
// want an error to be thrown at the end.
|
|
1673
|
+
try {
|
|
1674
|
+
this.destroyActiveFixtures();
|
|
1675
|
+
}
|
|
1676
|
+
finally {
|
|
1677
|
+
try {
|
|
1678
|
+
if (this.shouldTearDownTestingModule()) {
|
|
1679
|
+
this.tearDownTestingModule();
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
finally {
|
|
1683
|
+
this._testModuleRef = null;
|
|
1684
|
+
this._instanceTeardownOptions = undefined;
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1652
1687
|
}
|
|
1653
1688
|
configureCompiler(config) {
|
|
1654
1689
|
if (config.useJit != null) {
|
|
@@ -1660,6 +1695,9 @@ class TestBedRender3 {
|
|
|
1660
1695
|
}
|
|
1661
1696
|
configureTestingModule(moduleDef) {
|
|
1662
1697
|
this.assertNotInstantiated('R3TestBed.configureTestingModule', 'configure the test module');
|
|
1698
|
+
// Always re-assign the teardown options, even if they're undefined.
|
|
1699
|
+
// This ensures that we don't carry the options between tests.
|
|
1700
|
+
this._instanceTeardownOptions = moduleDef.teardown;
|
|
1663
1701
|
this.compiler.configureTestingModule(moduleDef);
|
|
1664
1702
|
}
|
|
1665
1703
|
compileComponents() {
|
|
@@ -1778,11 +1816,13 @@ class TestBedRender3 {
|
|
|
1778
1816
|
this._globalCompilationChecked = true;
|
|
1779
1817
|
}
|
|
1780
1818
|
destroyActiveFixtures() {
|
|
1819
|
+
let errorCount = 0;
|
|
1781
1820
|
this._activeFixtures.forEach((fixture) => {
|
|
1782
1821
|
try {
|
|
1783
1822
|
fixture.destroy();
|
|
1784
1823
|
}
|
|
1785
1824
|
catch (e) {
|
|
1825
|
+
errorCount++;
|
|
1786
1826
|
console.error('Error during cleanup of component', {
|
|
1787
1827
|
component: fixture.componentInstance,
|
|
1788
1828
|
stacktrace: e,
|
|
@@ -1790,6 +1830,52 @@ class TestBedRender3 {
|
|
|
1790
1830
|
}
|
|
1791
1831
|
});
|
|
1792
1832
|
this._activeFixtures = [];
|
|
1833
|
+
if (errorCount > 0 && this.shouldRethrowTeardownErrors()) {
|
|
1834
|
+
throw Error(`${errorCount} ${(errorCount === 1 ? 'component' : 'components')} ` +
|
|
1835
|
+
`threw errors during cleanup`);
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
shouldRethrowTeardownErrors() {
|
|
1839
|
+
var _a, _b;
|
|
1840
|
+
const instanceOptions = this._instanceTeardownOptions;
|
|
1841
|
+
const environmentOptions = TestBedRender3._environmentTeardownOptions;
|
|
1842
|
+
// If the new teardown behavior hasn't been configured, preserve the old behavior.
|
|
1843
|
+
if (!instanceOptions && !environmentOptions) {
|
|
1844
|
+
return false;
|
|
1845
|
+
}
|
|
1846
|
+
// Otherwise use the configured behavior or default to rethrowing.
|
|
1847
|
+
return (_b = (_a = instanceOptions === null || instanceOptions === void 0 ? void 0 : instanceOptions.rethrowErrors) !== null && _a !== void 0 ? _a : environmentOptions === null || environmentOptions === void 0 ? void 0 : environmentOptions.rethrowErrors) !== null && _b !== void 0 ? _b : true;
|
|
1848
|
+
}
|
|
1849
|
+
shouldTearDownTestingModule() {
|
|
1850
|
+
var _a, _b, _c, _d;
|
|
1851
|
+
return (_d = (_b = (_a = this._instanceTeardownOptions) === null || _a === void 0 ? void 0 : _a.destroyAfterEach) !== null && _b !== void 0 ? _b : (_c = TestBedRender3._environmentTeardownOptions) === null || _c === void 0 ? void 0 : _c.destroyAfterEach) !== null && _d !== void 0 ? _d : TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT;
|
|
1852
|
+
}
|
|
1853
|
+
tearDownTestingModule() {
|
|
1854
|
+
var _a;
|
|
1855
|
+
// If the module ref has already been destroyed, we won't be able to get a test renderer.
|
|
1856
|
+
if (this._testModuleRef === null) {
|
|
1857
|
+
return;
|
|
1858
|
+
}
|
|
1859
|
+
// Resolve the renderer ahead of time, because we want to remove the root elements as the very
|
|
1860
|
+
// last step, but the injector will be destroyed as a part of the module ref destruction.
|
|
1861
|
+
const testRenderer = this.inject(TestComponentRenderer);
|
|
1862
|
+
try {
|
|
1863
|
+
this._testModuleRef.destroy();
|
|
1864
|
+
}
|
|
1865
|
+
catch (e) {
|
|
1866
|
+
if (this.shouldRethrowTeardownErrors()) {
|
|
1867
|
+
throw e;
|
|
1868
|
+
}
|
|
1869
|
+
else {
|
|
1870
|
+
console.error('Error during cleanup of a testing module', {
|
|
1871
|
+
component: this._testModuleRef.instance,
|
|
1872
|
+
stacktrace: e,
|
|
1873
|
+
});
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
finally {
|
|
1877
|
+
(_a = testRenderer.removeAllRootElements) === null || _a === void 0 ? void 0 : _a.call(testRenderer);
|
|
1878
|
+
}
|
|
1793
1879
|
}
|
|
1794
1880
|
}
|
|
1795
1881
|
let testBed;
|
|
@@ -1886,6 +1972,7 @@ class TestBedViewEngine {
|
|
|
1886
1972
|
this._compiler = null;
|
|
1887
1973
|
this._moduleRef = null;
|
|
1888
1974
|
this._moduleFactory = null;
|
|
1975
|
+
this._pendingModuleFactory = null;
|
|
1889
1976
|
this._compilerOptions = [];
|
|
1890
1977
|
this._moduleOverrides = [];
|
|
1891
1978
|
this._componentOverrides = [];
|
|
@@ -1915,9 +2002,9 @@ class TestBedViewEngine {
|
|
|
1915
2002
|
* Test modules and platforms for individual platforms are available from
|
|
1916
2003
|
* '@angular/<platform_name>/testing'.
|
|
1917
2004
|
*/
|
|
1918
|
-
static initTestEnvironment(ngModule, platform,
|
|
2005
|
+
static initTestEnvironment(ngModule, platform, summariesOrOptions) {
|
|
1919
2006
|
const testBed = _getTestBedViewEngine();
|
|
1920
|
-
testBed.initTestEnvironment(ngModule, platform,
|
|
2007
|
+
testBed.initTestEnvironment(ngModule, platform, summariesOrOptions);
|
|
1921
2008
|
return testBed;
|
|
1922
2009
|
}
|
|
1923
2010
|
/**
|
|
@@ -1998,6 +2085,12 @@ class TestBedViewEngine {
|
|
|
1998
2085
|
static createComponent(component) {
|
|
1999
2086
|
return _getTestBedViewEngine().createComponent(component);
|
|
2000
2087
|
}
|
|
2088
|
+
static shouldTearDownTestingModule() {
|
|
2089
|
+
return _getTestBedViewEngine().shouldTearDownTestingModule();
|
|
2090
|
+
}
|
|
2091
|
+
static tearDownTestingModule() {
|
|
2092
|
+
_getTestBedViewEngine().tearDownTestingModule();
|
|
2093
|
+
}
|
|
2001
2094
|
/**
|
|
2002
2095
|
* Initialize the environment for testing with a compiler factory, a PlatformRef, and an
|
|
2003
2096
|
* angular module. These are common to every test in the suite.
|
|
@@ -2009,14 +2102,19 @@ class TestBedViewEngine {
|
|
|
2009
2102
|
* Test modules and platforms for individual platforms are available from
|
|
2010
2103
|
* '@angular/<platform_name>/testing'.
|
|
2011
2104
|
*/
|
|
2012
|
-
initTestEnvironment(ngModule, platform,
|
|
2105
|
+
initTestEnvironment(ngModule, platform, summariesOrOptions) {
|
|
2013
2106
|
if (this.platform || this.ngModule) {
|
|
2014
2107
|
throw new Error('Cannot set base providers because it has already been called');
|
|
2015
2108
|
}
|
|
2016
2109
|
this.platform = platform;
|
|
2017
2110
|
this.ngModule = ngModule;
|
|
2018
|
-
if (
|
|
2019
|
-
this._testEnvAotSummaries =
|
|
2111
|
+
if (typeof summariesOrOptions === 'function') {
|
|
2112
|
+
this._testEnvAotSummaries = summariesOrOptions;
|
|
2113
|
+
TestBedViewEngine._environmentTeardownOptions = undefined;
|
|
2114
|
+
}
|
|
2115
|
+
else {
|
|
2116
|
+
this._testEnvAotSummaries = (summariesOrOptions === null || summariesOrOptions === void 0 ? void 0 : summariesOrOptions.aotSummaries) || (() => []);
|
|
2117
|
+
TestBedViewEngine._environmentTeardownOptions = summariesOrOptions === null || summariesOrOptions === void 0 ? void 0 : summariesOrOptions.teardown;
|
|
2020
2118
|
}
|
|
2021
2119
|
}
|
|
2022
2120
|
/**
|
|
@@ -2027,6 +2125,7 @@ class TestBedViewEngine {
|
|
|
2027
2125
|
this.platform = null;
|
|
2028
2126
|
this.ngModule = null;
|
|
2029
2127
|
this._testEnvAotSummaries = () => [];
|
|
2128
|
+
TestBedViewEngine._environmentTeardownOptions = undefined;
|
|
2030
2129
|
}
|
|
2031
2130
|
resetTestingModule() {
|
|
2032
2131
|
ɵclearOverrides();
|
|
@@ -2039,26 +2138,31 @@ class TestBedViewEngine {
|
|
|
2039
2138
|
this._pipeOverrides = [];
|
|
2040
2139
|
this._isRoot = true;
|
|
2041
2140
|
this._rootProviderOverrides = [];
|
|
2042
|
-
this._moduleRef = null;
|
|
2043
2141
|
this._moduleFactory = null;
|
|
2142
|
+
this._pendingModuleFactory = null;
|
|
2044
2143
|
this._compilerOptions = [];
|
|
2045
2144
|
this._providers = [];
|
|
2046
2145
|
this._declarations = [];
|
|
2047
2146
|
this._imports = [];
|
|
2048
2147
|
this._schemas = [];
|
|
2049
|
-
|
|
2050
|
-
|
|
2148
|
+
// We have to chain a couple of try/finally blocks, because each step can
|
|
2149
|
+
// throw errors and we don't want it to interrupt the next step and we also
|
|
2150
|
+
// want an error to be thrown at the end.
|
|
2151
|
+
try {
|
|
2152
|
+
this.destroyActiveFixtures();
|
|
2153
|
+
}
|
|
2154
|
+
finally {
|
|
2051
2155
|
try {
|
|
2052
|
-
|
|
2156
|
+
if (this.shouldTearDownTestingModule()) {
|
|
2157
|
+
this.tearDownTestingModule();
|
|
2158
|
+
}
|
|
2053
2159
|
}
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
});
|
|
2160
|
+
finally {
|
|
2161
|
+
this._moduleRef = null;
|
|
2162
|
+
this._instanceTeardownOptions = undefined;
|
|
2163
|
+
this._instantiated = false;
|
|
2059
2164
|
}
|
|
2060
|
-
}
|
|
2061
|
-
this._activeFixtures = [];
|
|
2165
|
+
}
|
|
2062
2166
|
}
|
|
2063
2167
|
configureCompiler(config) {
|
|
2064
2168
|
this._assertNotInstantiated('TestBed.configureCompiler', 'configure the compiler');
|
|
@@ -2081,15 +2185,24 @@ class TestBedViewEngine {
|
|
|
2081
2185
|
if (moduleDef.aotSummaries) {
|
|
2082
2186
|
this._aotSummaries.push(moduleDef.aotSummaries);
|
|
2083
2187
|
}
|
|
2188
|
+
// Always re-assign the teardown options, even if they're undefined.
|
|
2189
|
+
// This ensures that we don't carry the options between tests.
|
|
2190
|
+
this._instanceTeardownOptions = moduleDef.teardown;
|
|
2084
2191
|
}
|
|
2085
2192
|
compileComponents() {
|
|
2086
2193
|
if (this._moduleFactory || this._instantiated) {
|
|
2087
2194
|
return Promise.resolve(null);
|
|
2088
2195
|
}
|
|
2089
2196
|
const moduleType = this._createCompilerAndModule();
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2197
|
+
this._pendingModuleFactory = moduleType;
|
|
2198
|
+
return this._compiler.compileModuleAndAllComponentsAsync(moduleType).then(result => {
|
|
2199
|
+
// If the module mismatches by the time the promise resolves, it means that the module has
|
|
2200
|
+
// already been destroyed and a new compilation has started. If that's the case, avoid
|
|
2201
|
+
// overwriting the module factory, because it can cause downstream errors.
|
|
2202
|
+
if (this._pendingModuleFactory === moduleType) {
|
|
2203
|
+
this._moduleFactory = result.ngModuleFactory;
|
|
2204
|
+
this._pendingModuleFactory = null;
|
|
2205
|
+
}
|
|
2093
2206
|
});
|
|
2094
2207
|
}
|
|
2095
2208
|
_initIfNeeded() {
|
|
@@ -2288,6 +2401,68 @@ class TestBedViewEngine {
|
|
|
2288
2401
|
this._activeFixtures.push(fixture);
|
|
2289
2402
|
return fixture;
|
|
2290
2403
|
}
|
|
2404
|
+
destroyActiveFixtures() {
|
|
2405
|
+
let errorCount = 0;
|
|
2406
|
+
this._activeFixtures.forEach((fixture) => {
|
|
2407
|
+
try {
|
|
2408
|
+
fixture.destroy();
|
|
2409
|
+
}
|
|
2410
|
+
catch (e) {
|
|
2411
|
+
errorCount++;
|
|
2412
|
+
console.error('Error during cleanup of component', {
|
|
2413
|
+
component: fixture.componentInstance,
|
|
2414
|
+
stacktrace: e,
|
|
2415
|
+
});
|
|
2416
|
+
}
|
|
2417
|
+
});
|
|
2418
|
+
this._activeFixtures = [];
|
|
2419
|
+
if (errorCount > 0 && this.shouldRethrowTeardownErrors()) {
|
|
2420
|
+
throw Error(`${errorCount} ${(errorCount === 1 ? 'component' : 'components')} ` +
|
|
2421
|
+
`threw errors during cleanup`);
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
shouldRethrowTeardownErrors() {
|
|
2425
|
+
var _a, _b;
|
|
2426
|
+
const instanceOptions = this._instanceTeardownOptions;
|
|
2427
|
+
const environmentOptions = TestBedViewEngine._environmentTeardownOptions;
|
|
2428
|
+
// If the new teardown behavior hasn't been configured, preserve the old behavior.
|
|
2429
|
+
if (!instanceOptions && !environmentOptions) {
|
|
2430
|
+
return false;
|
|
2431
|
+
}
|
|
2432
|
+
// Otherwise use the configured behavior or default to rethrowing.
|
|
2433
|
+
return (_b = (_a = instanceOptions === null || instanceOptions === void 0 ? void 0 : instanceOptions.rethrowErrors) !== null && _a !== void 0 ? _a : environmentOptions === null || environmentOptions === void 0 ? void 0 : environmentOptions.rethrowErrors) !== null && _b !== void 0 ? _b : true;
|
|
2434
|
+
}
|
|
2435
|
+
shouldTearDownTestingModule() {
|
|
2436
|
+
var _a, _b, _c, _d;
|
|
2437
|
+
return (_d = (_b = (_a = this._instanceTeardownOptions) === null || _a === void 0 ? void 0 : _a.destroyAfterEach) !== null && _b !== void 0 ? _b : (_c = TestBedViewEngine._environmentTeardownOptions) === null || _c === void 0 ? void 0 : _c.destroyAfterEach) !== null && _d !== void 0 ? _d : TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT;
|
|
2438
|
+
}
|
|
2439
|
+
tearDownTestingModule() {
|
|
2440
|
+
var _a, _b, _c, _d, _e;
|
|
2441
|
+
// If the module ref has already been destroyed, we won't be able to get a test renderer.
|
|
2442
|
+
if (this._moduleRef === null) {
|
|
2443
|
+
return;
|
|
2444
|
+
}
|
|
2445
|
+
// Resolve the renderer ahead of time, because we want to remove the root elements as the very
|
|
2446
|
+
// last step, but the injector will be destroyed as a part of the module ref destruction.
|
|
2447
|
+
const testRenderer = this.inject(TestComponentRenderer);
|
|
2448
|
+
try {
|
|
2449
|
+
this._moduleRef.destroy();
|
|
2450
|
+
}
|
|
2451
|
+
catch (e) {
|
|
2452
|
+
if ((_d = (_b = (_a = this._instanceTeardownOptions) === null || _a === void 0 ? void 0 : _a.rethrowErrors) !== null && _b !== void 0 ? _b : (_c = TestBedViewEngine._environmentTeardownOptions) === null || _c === void 0 ? void 0 : _c.rethrowErrors) !== null && _d !== void 0 ? _d : true) {
|
|
2453
|
+
throw e;
|
|
2454
|
+
}
|
|
2455
|
+
else {
|
|
2456
|
+
console.error('Error during cleanup of a testing module', {
|
|
2457
|
+
component: this._moduleRef.instance,
|
|
2458
|
+
stacktrace: e,
|
|
2459
|
+
});
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
finally {
|
|
2463
|
+
(_e = testRenderer === null || testRenderer === void 0 ? void 0 : testRenderer.removeAllRootElements) === null || _e === void 0 ? void 0 : _e.call(testRenderer);
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2291
2466
|
}
|
|
2292
2467
|
/**
|
|
2293
2468
|
* @description
|
|
@@ -2386,10 +2561,22 @@ function withModule(moduleDef, fn) {
|
|
|
2386
2561
|
const _global = (typeof window === 'undefined' ? global : window);
|
|
2387
2562
|
// Reset the test providers and the fake async zone before each test.
|
|
2388
2563
|
if (_global.beforeEach) {
|
|
2389
|
-
_global.beforeEach(()
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2564
|
+
_global.beforeEach(getCleanupHook(false));
|
|
2565
|
+
}
|
|
2566
|
+
// We provide both a `beforeEach` and `afterEach`, because the updated behavior for
|
|
2567
|
+
// tearing down the module is supposed to run after the test so that we can associate
|
|
2568
|
+
// teardown errors with the correct test.
|
|
2569
|
+
if (_global.afterEach) {
|
|
2570
|
+
_global.afterEach(getCleanupHook(true));
|
|
2571
|
+
}
|
|
2572
|
+
function getCleanupHook(expectedTeardownValue) {
|
|
2573
|
+
return () => {
|
|
2574
|
+
if (TestBed.shouldTearDownTestingModule() ===
|
|
2575
|
+
expectedTeardownValue) {
|
|
2576
|
+
TestBed.resetTestingModule();
|
|
2577
|
+
resetFakeAsyncZone();
|
|
2578
|
+
}
|
|
2579
|
+
};
|
|
2393
2580
|
}
|
|
2394
2581
|
/**
|
|
2395
2582
|
* This API should be removed. But doing so seems to break `google3` and so it requires a bit of
|