@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.
Files changed (164) hide show
  1. package/bundles/core-testing.umd.js +239 -46
  2. package/bundles/core-testing.umd.js.map +1 -1
  3. package/bundles/core.umd.js +126 -49
  4. package/bundles/core.umd.js.map +1 -1
  5. package/core.d.ts +45 -19
  6. package/core.metadata.json +1 -1
  7. package/esm2015/src/application_init.js +5 -5
  8. package/esm2015/src/application_ref.js +34 -9
  9. package/esm2015/src/change_detection/differs/iterable_differs.js +1 -1
  10. package/esm2015/src/compiler/compiler_facade.js +31 -8
  11. package/esm2015/src/compiler/compiler_facade_interface.js +1 -1
  12. package/esm2015/src/di/jit/injectable.js +4 -3
  13. package/esm2015/src/di/r3_injector.js +5 -2
  14. package/esm2015/src/error_handler.js +2 -6
  15. package/esm2015/src/event_emitter.js +1 -1
  16. package/esm2015/src/linker/component_factory_resolver.js +1 -1
  17. package/esm2015/src/linker/template_ref.js +1 -1
  18. package/esm2015/src/linker/view_container_ref.js +1 -1
  19. package/esm2015/src/metadata/di.js +1 -1
  20. package/esm2015/src/metadata/do_boostrap.js +1 -1
  21. package/esm2015/src/render3/component_ref.js +1 -1
  22. package/esm2015/src/render3/jit/directive.js +6 -5
  23. package/esm2015/src/render3/jit/module.js +7 -4
  24. package/esm2015/src/render3/jit/partial.js +27 -9
  25. package/esm2015/src/render3/jit/pipe.js +5 -3
  26. package/esm2015/src/render3/ng_module_ref.js +1 -1
  27. package/esm2015/src/render3/view_ref.js +1 -1
  28. package/esm2015/src/sanitization/bypass.js +1 -1
  29. package/esm2015/src/version.js +1 -1
  30. package/esm2015/src/view/entrypoint.js +1 -1
  31. package/esm2015/src/view/refs.js +1 -1
  32. package/esm2015/testing/src/ng_zone_mock.js +1 -1
  33. package/esm2015/testing/src/r3_test_bed.js +84 -7
  34. package/esm2015/testing/src/r3_test_bed_compiler.js +4 -1
  35. package/esm2015/testing/src/resolvers.js +1 -1
  36. package/esm2015/testing/src/test_bed.js +110 -21
  37. package/esm2015/testing/src/test_bed_common.js +7 -1
  38. package/esm2015/testing/src/test_hooks.js +45 -0
  39. package/esm2015/testing/src/testing.js +3 -3
  40. package/fesm2015/core.js +116 -45
  41. package/fesm2015/core.js.map +1 -1
  42. package/fesm2015/testing.js +216 -29
  43. package/fesm2015/testing.js.map +1 -1
  44. package/package.json +1 -1
  45. package/schematics/migrations/missing-injectable/providers_evaluator.js +1 -1
  46. package/schematics/migrations/static-queries/strategies/usage_strategy/template_usage_visitor.js +1 -1
  47. package/schematics/migrations/template-var-assignment/angular/html_variable_assignment_visitor.js +1 -1
  48. package/schematics/migrations.json +1 -1
  49. package/src/r3_symbols.d.ts +2 -3
  50. package/testing/testing.d.ts +64 -5
  51. package/testing/testing.metadata.json +1 -1
  52. package/testing.d.ts +1 -1
  53. package/esm2015/testing/src/before_each.js +0 -33
  54. package/schematics/migrations/abstract-control-parent/abstract-control-parent.externs.js +0 -0
  55. package/schematics/migrations/abstract-control-parent/index.mjs +0 -47
  56. package/schematics/migrations/abstract-control-parent/util.mjs +0 -50
  57. package/schematics/migrations/activated-route-snapshot-fragment/activated-route-snapshot-fragment.externs.js +0 -0
  58. package/schematics/migrations/activated-route-snapshot-fragment/index.mjs +0 -48
  59. package/schematics/migrations/activated-route-snapshot-fragment/util.mjs +0 -33
  60. package/schematics/migrations/can-activate-with-redirect-to/can-activate-with-redirect-to.externs.js +0 -0
  61. package/schematics/migrations/can-activate-with-redirect-to/index.mjs +0 -44
  62. package/schematics/migrations/can-activate-with-redirect-to/util.mjs +0 -55
  63. package/schematics/migrations/deep-shadow-piercing-selector/deep-shadow-piercing-selector.externs.js +0 -0
  64. package/schematics/migrations/deep-shadow-piercing-selector/index.mjs +0 -36
  65. package/schematics/migrations/dynamic-queries/dynamic-queries.externs.js +0 -0
  66. package/schematics/migrations/dynamic-queries/index.mjs +0 -51
  67. package/schematics/migrations/dynamic-queries/util.mjs +0 -65
  68. package/schematics/migrations/initial-navigation/collector.mjs +0 -105
  69. package/schematics/migrations/initial-navigation/index.mjs +0 -61
  70. package/schematics/migrations/initial-navigation/initial-navigation.externs.js +0 -0
  71. package/schematics/migrations/initial-navigation/transform.mjs +0 -54
  72. package/schematics/migrations/initial-navigation/update_recorder.mjs +0 -9
  73. package/schematics/migrations/initial-navigation/util.mjs +0 -28
  74. package/schematics/migrations/missing-injectable/definition_collector.mjs +0 -75
  75. package/schematics/migrations/missing-injectable/index.mjs +0 -100
  76. package/schematics/migrations/missing-injectable/missing-injectable.externs.js +0 -0
  77. package/schematics/migrations/missing-injectable/providers_evaluator.mjs +0 -50
  78. package/schematics/migrations/missing-injectable/transform.mjs +0 -187
  79. package/schematics/migrations/missing-injectable/update_recorder.mjs +0 -9
  80. package/schematics/migrations/module-with-providers/collector.mjs +0 -59
  81. package/schematics/migrations/module-with-providers/index.mjs +0 -71
  82. package/schematics/migrations/module-with-providers/module-with-providers.externs.js +0 -0
  83. package/schematics/migrations/module-with-providers/transform.mjs +0 -134
  84. package/schematics/migrations/module-with-providers/util.mjs +0 -25
  85. package/schematics/migrations/move-document/document_import_visitor.mjs +0 -60
  86. package/schematics/migrations/move-document/index.mjs +0 -71
  87. package/schematics/migrations/move-document/move-document.externs.js +0 -0
  88. package/schematics/migrations/move-document/move-import.mjs +0 -45
  89. package/schematics/migrations/native-view-encapsulation/index.mjs +0 -41
  90. package/schematics/migrations/native-view-encapsulation/native-view-encapsulation.externs.js +0 -0
  91. package/schematics/migrations/native-view-encapsulation/util.mjs +0 -34
  92. package/schematics/migrations/navigation-extras-omissions/index.mjs +0 -47
  93. package/schematics/migrations/navigation-extras-omissions/navigation-extras-omissions.externs.js +0 -0
  94. package/schematics/migrations/navigation-extras-omissions/util.mjs +0 -111
  95. package/schematics/migrations/relative-link-resolution/collector.mjs +0 -81
  96. package/schematics/migrations/relative-link-resolution/index.mjs +0 -62
  97. package/schematics/migrations/relative-link-resolution/relative-link-resolution.externs.js +0 -0
  98. package/schematics/migrations/relative-link-resolution/transform.mjs +0 -51
  99. package/schematics/migrations/relative-link-resolution/update_recorder.mjs +0 -9
  100. package/schematics/migrations/relative-link-resolution/util.mjs +0 -28
  101. package/schematics/migrations/renderer-to-renderer2/helpers.mjs +0 -224
  102. package/schematics/migrations/renderer-to-renderer2/index.mjs +0 -113
  103. package/schematics/migrations/renderer-to-renderer2/migration.mjs +0 -211
  104. package/schematics/migrations/renderer-to-renderer2/renderer-to-renderer2.externs.js +0 -0
  105. package/schematics/migrations/renderer-to-renderer2/util.mjs +0 -69
  106. package/schematics/migrations/router-preserve-query-params/index.mjs +0 -50
  107. package/schematics/migrations/router-preserve-query-params/router-preserve-query-params.externs.js +0 -0
  108. package/schematics/migrations/router-preserve-query-params/util.mjs +0 -88
  109. package/schematics/migrations/static-queries/angular/directive_inputs.mjs +0 -70
  110. package/schematics/migrations/static-queries/angular/ng_query_visitor.mjs +0 -113
  111. package/schematics/migrations/static-queries/angular/query-definition.mjs +0 -20
  112. package/schematics/migrations/static-queries/angular/super_class.mjs +0 -21
  113. package/schematics/migrations/static-queries/index.mjs +0 -206
  114. package/schematics/migrations/static-queries/static-queries.externs.js +0 -0
  115. package/schematics/migrations/static-queries/strategies/template_strategy/template_strategy.mjs +0 -200
  116. package/schematics/migrations/static-queries/strategies/test_strategy/test_strategy.mjs +0 -24
  117. package/schematics/migrations/static-queries/strategies/timing-strategy.mjs +0 -9
  118. package/schematics/migrations/static-queries/strategies/usage_strategy/declaration_usage_visitor.mjs +0 -355
  119. package/schematics/migrations/static-queries/strategies/usage_strategy/super_class_context.mjs +0 -38
  120. package/schematics/migrations/static-queries/strategies/usage_strategy/template_usage_visitor.mjs +0 -80
  121. package/schematics/migrations/static-queries/strategies/usage_strategy/usage_strategy.mjs +0 -154
  122. package/schematics/migrations/static-queries/transform.mjs +0 -88
  123. package/schematics/migrations/template-var-assignment/analyze_template.mjs +0 -25
  124. package/schematics/migrations/template-var-assignment/angular/html_variable_assignment_visitor.mjs +0 -65
  125. package/schematics/migrations/template-var-assignment/index.mjs +0 -68
  126. package/schematics/migrations/template-var-assignment/template-var-assignment.externs.js +0 -0
  127. package/schematics/migrations/undecorated-classes-with-decorated-fields/index.mjs +0 -92
  128. package/schematics/migrations/undecorated-classes-with-decorated-fields/transform.mjs +0 -286
  129. package/schematics/migrations/undecorated-classes-with-decorated-fields/undecorated-classes-with-decorated-fields.externs.js +0 -0
  130. package/schematics/migrations/undecorated-classes-with-decorated-fields/update_recorder.mjs +0 -9
  131. package/schematics/migrations/undecorated-classes-with-di/create_ngc_program.mjs +0 -43
  132. package/schematics/migrations/undecorated-classes-with-di/decorator_rewrite/convert_directive_metadata.mjs +0 -82
  133. package/schematics/migrations/undecorated-classes-with-di/decorator_rewrite/decorator_rewriter.mjs +0 -102
  134. package/schematics/migrations/undecorated-classes-with-di/decorator_rewrite/import_rewrite_visitor.mjs +0 -111
  135. package/schematics/migrations/undecorated-classes-with-di/decorator_rewrite/path_format.mjs +0 -17
  136. package/schematics/migrations/undecorated-classes-with-di/decorator_rewrite/source_file_exports.mjs +0 -51
  137. package/schematics/migrations/undecorated-classes-with-di/index.mjs +0 -162
  138. package/schematics/migrations/undecorated-classes-with-di/ng_declaration_collector.mjs +0 -124
  139. package/schematics/migrations/undecorated-classes-with-di/transform.mjs +0 -356
  140. package/schematics/migrations/undecorated-classes-with-di/undecorated-classes-with-di.externs.js +0 -0
  141. package/schematics/migrations/undecorated-classes-with-di/update_recorder.mjs +0 -9
  142. package/schematics/migrations/wait-for-async/index.mjs +0 -76
  143. package/schematics/migrations/wait-for-async/util.mjs +0 -23
  144. package/schematics/migrations/wait-for-async/wait-for-async.externs.js +0 -0
  145. package/schematics/migrations/xhr-factory/index.mjs +0 -91
  146. package/schematics/migrations/xhr-factory/xhr-factory.externs.js +0 -0
  147. package/schematics/utils/import_manager.mjs +0 -197
  148. package/schematics/utils/line_mappings.mjs +0 -60
  149. package/schematics/utils/ng_component_template.mjs +0 -96
  150. package/schematics/utils/ng_decorators.mjs +0 -23
  151. package/schematics/utils/parse_html.mjs +0 -24
  152. package/schematics/utils/project_tsconfig_paths.mjs +0 -74
  153. package/schematics/utils/schematics_prompt.mjs +0 -30
  154. package/schematics/utils/typescript/class_declaration.mjs +0 -33
  155. package/schematics/utils/typescript/compiler_host.mjs +0 -66
  156. package/schematics/utils/typescript/decorators.mjs +0 -20
  157. package/schematics/utils/typescript/find_base_classes.mjs +0 -30
  158. package/schematics/utils/typescript/functions.mjs +0 -28
  159. package/schematics/utils/typescript/imports.mjs +0 -91
  160. package/schematics/utils/typescript/nodes.mjs +0 -57
  161. package/schematics/utils/typescript/parse_tsconfig.mjs +0 -26
  162. package/schematics/utils/typescript/property_name.mjs +0 -23
  163. package/schematics/utils/typescript/symbol.mjs +0 -72
  164. package/schematics/utils/utils.externs.js +0 -0
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v12.1.0-next.6
2
+ * @license Angular v12.1.3
3
3
  * (c) 2010-2021 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -647,10 +647,16 @@
647
647
  r[k] = a[j];
648
648
  return r;
649
649
  }
650
- function __spreadArray(to, from) {
651
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
652
- to[j] = from[i];
653
- return to;
650
+ function __spreadArray(to, from, pack) {
651
+ if (pack || arguments.length === 2)
652
+ for (var i = 0, l = from.length, ar; i < l; i++) {
653
+ if (ar || !(i in from)) {
654
+ if (!ar)
655
+ ar = Array.prototype.slice.call(from, 0, i);
656
+ ar[i] = from[i];
657
+ }
658
+ }
659
+ return to.concat(ar || from);
654
660
  }
655
661
  function __await(v) {
656
662
  return this instanceof __await ? (this.v = v, this) : new __await(v);
@@ -1587,6 +1593,9 @@
1587
1593
  queueTypesFromModulesArrayRecur(maybeUnwrapFn(def.imports));
1588
1594
  queueTypesFromModulesArrayRecur(maybeUnwrapFn(def.exports));
1589
1595
  }
1596
+ else if (isModuleWithProviders(value)) {
1597
+ queueTypesFromModulesArrayRecur([value.ngModule]);
1598
+ }
1590
1599
  }
1591
1600
  }
1592
1601
  catch (e_4_1) { e_4 = { error: e_4_1 }; }
@@ -1928,6 +1937,11 @@
1928
1937
  * Use of this source code is governed by an MIT-style license that can be
1929
1938
  * found in the LICENSE file at https://angular.io/license
1930
1939
  */
1940
+ /**
1941
+ * Whether test modules should be torn down by default.
1942
+ * Currently disabled for backwards-compatibility reasons.
1943
+ */
1944
+ var TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT = false;
1931
1945
  /**
1932
1946
  * An abstract class for inserting the root test component element in a platform independent way.
1933
1947
  *
@@ -1937,6 +1951,7 @@
1937
1951
  function TestComponentRenderer() {
1938
1952
  }
1939
1953
  TestComponentRenderer.prototype.insertRootElement = function (rootElementId) { };
1954
+ TestComponentRenderer.prototype.removeAllRootElements = function () { };
1940
1955
  return TestComponentRenderer;
1941
1956
  }());
1942
1957
  /**
@@ -1989,9 +2004,9 @@
1989
2004
  *
1990
2005
  * @publicApi
1991
2006
  */
1992
- TestBedRender3.initTestEnvironment = function (ngModule, platform, aotSummaries) {
2007
+ TestBedRender3.initTestEnvironment = function (ngModule, platform, summariesOrOptions) {
1993
2008
  var testBed = _getTestBedRender3();
1994
- testBed.initTestEnvironment(ngModule, platform, aotSummaries);
2009
+ testBed.initTestEnvironment(ngModule, platform, summariesOrOptions);
1995
2010
  return testBed;
1996
2011
  };
1997
2012
  /**
@@ -2072,6 +2087,12 @@
2072
2087
  _getTestBedRender3().resetTestingModule();
2073
2088
  return TestBedRender3;
2074
2089
  };
2090
+ TestBedRender3.shouldTearDownTestingModule = function () {
2091
+ return _getTestBedRender3().shouldTearDownTestingModule();
2092
+ };
2093
+ TestBedRender3.tearDownTestingModule = function () {
2094
+ _getTestBedRender3().tearDownTestingModule();
2095
+ };
2075
2096
  /**
2076
2097
  * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
2077
2098
  * angular module. These are common to every test in the suite.
@@ -2085,10 +2106,14 @@
2085
2106
  *
2086
2107
  * @publicApi
2087
2108
  */
2088
- TestBedRender3.prototype.initTestEnvironment = function (ngModule, platform, aotSummaries) {
2109
+ TestBedRender3.prototype.initTestEnvironment = function (ngModule, platform, summariesOrOptions) {
2089
2110
  if (this.platform || this.ngModule) {
2090
2111
  throw new Error('Cannot set base providers because it has already been called');
2091
2112
  }
2113
+ // If `summariesOrOptions` is a function, it means that it's
2114
+ // an AOT summaries factory which Ivy doesn't support.
2115
+ TestBedRender3._environmentTeardownOptions =
2116
+ typeof summariesOrOptions === 'function' ? undefined : summariesOrOptions === null || summariesOrOptions === void 0 ? void 0 : summariesOrOptions.teardown;
2092
2117
  this.platform = platform;
2093
2118
  this.ngModule = ngModule;
2094
2119
  this._compiler = new R3TestBedCompiler(this.platform, this.ngModule);
@@ -2103,6 +2128,7 @@
2103
2128
  this._compiler = null;
2104
2129
  this.platform = null;
2105
2130
  this.ngModule = null;
2131
+ TestBedRender3._environmentTeardownOptions = undefined;
2106
2132
  };
2107
2133
  TestBedRender3.prototype.resetTestingModule = function () {
2108
2134
  this.checkGlobalCompilationFinished();
@@ -2111,8 +2137,23 @@
2111
2137
  this.compiler.restoreOriginalState();
2112
2138
  }
2113
2139
  this._compiler = new R3TestBedCompiler(this.platform, this.ngModule);
2114
- this._testModuleRef = null;
2115
- this.destroyActiveFixtures();
2140
+ // We have to chain a couple of try/finally blocks, because each step can
2141
+ // throw errors and we don't want it to interrupt the next step and we also
2142
+ // want an error to be thrown at the end.
2143
+ try {
2144
+ this.destroyActiveFixtures();
2145
+ }
2146
+ finally {
2147
+ try {
2148
+ if (this.shouldTearDownTestingModule()) {
2149
+ this.tearDownTestingModule();
2150
+ }
2151
+ }
2152
+ finally {
2153
+ this._testModuleRef = null;
2154
+ this._instanceTeardownOptions = undefined;
2155
+ }
2156
+ }
2116
2157
  };
2117
2158
  TestBedRender3.prototype.configureCompiler = function (config) {
2118
2159
  if (config.useJit != null) {
@@ -2124,6 +2165,9 @@
2124
2165
  };
2125
2166
  TestBedRender3.prototype.configureTestingModule = function (moduleDef) {
2126
2167
  this.assertNotInstantiated('R3TestBed.configureTestingModule', 'configure the test module');
2168
+ // Always re-assign the teardown options, even if they're undefined.
2169
+ // This ensures that we don't carry the options between tests.
2170
+ this._instanceTeardownOptions = moduleDef.teardown;
2127
2171
  this.compiler.configureTestingModule(moduleDef);
2128
2172
  };
2129
2173
  TestBedRender3.prototype.compileComponents = function () {
@@ -2254,11 +2298,13 @@
2254
2298
  this._globalCompilationChecked = true;
2255
2299
  };
2256
2300
  TestBedRender3.prototype.destroyActiveFixtures = function () {
2301
+ var errorCount = 0;
2257
2302
  this._activeFixtures.forEach(function (fixture) {
2258
2303
  try {
2259
2304
  fixture.destroy();
2260
2305
  }
2261
2306
  catch (e) {
2307
+ errorCount++;
2262
2308
  console.error('Error during cleanup of component', {
2263
2309
  component: fixture.componentInstance,
2264
2310
  stacktrace: e,
@@ -2266,6 +2312,52 @@
2266
2312
  }
2267
2313
  });
2268
2314
  this._activeFixtures = [];
2315
+ if (errorCount > 0 && this.shouldRethrowTeardownErrors()) {
2316
+ throw Error(errorCount + " " + (errorCount === 1 ? 'component' : 'components') + " " +
2317
+ "threw errors during cleanup");
2318
+ }
2319
+ };
2320
+ TestBedRender3.prototype.shouldRethrowTeardownErrors = function () {
2321
+ var _a, _b;
2322
+ var instanceOptions = this._instanceTeardownOptions;
2323
+ var environmentOptions = TestBedRender3._environmentTeardownOptions;
2324
+ // If the new teardown behavior hasn't been configured, preserve the old behavior.
2325
+ if (!instanceOptions && !environmentOptions) {
2326
+ return false;
2327
+ }
2328
+ // Otherwise use the configured behavior or default to rethrowing.
2329
+ 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;
2330
+ };
2331
+ TestBedRender3.prototype.shouldTearDownTestingModule = function () {
2332
+ var _a, _b, _c, _d;
2333
+ 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;
2334
+ };
2335
+ TestBedRender3.prototype.tearDownTestingModule = function () {
2336
+ var _a;
2337
+ // If the module ref has already been destroyed, we won't be able to get a test renderer.
2338
+ if (this._testModuleRef === null) {
2339
+ return;
2340
+ }
2341
+ // Resolve the renderer ahead of time, because we want to remove the root elements as the very
2342
+ // last step, but the injector will be destroyed as a part of the module ref destruction.
2343
+ var testRenderer = this.inject(TestComponentRenderer);
2344
+ try {
2345
+ this._testModuleRef.destroy();
2346
+ }
2347
+ catch (e) {
2348
+ if (this.shouldRethrowTeardownErrors()) {
2349
+ throw e;
2350
+ }
2351
+ else {
2352
+ console.error('Error during cleanup of a testing module', {
2353
+ component: this._testModuleRef.instance,
2354
+ stacktrace: e,
2355
+ });
2356
+ }
2357
+ }
2358
+ finally {
2359
+ (_a = testRenderer.removeAllRootElements) === null || _a === void 0 ? void 0 : _a.call(testRenderer);
2360
+ }
2269
2361
  };
2270
2362
  return TestBedRender3;
2271
2363
  }());
@@ -2361,6 +2453,7 @@
2361
2453
  this._compiler = null;
2362
2454
  this._moduleRef = null;
2363
2455
  this._moduleFactory = null;
2456
+ this._pendingModuleFactory = null;
2364
2457
  this._compilerOptions = [];
2365
2458
  this._moduleOverrides = [];
2366
2459
  this._componentOverrides = [];
@@ -2390,9 +2483,9 @@
2390
2483
  * Test modules and platforms for individual platforms are available from
2391
2484
  * '@angular/<platform_name>/testing'.
2392
2485
  */
2393
- TestBedViewEngine.initTestEnvironment = function (ngModule, platform, aotSummaries) {
2486
+ TestBedViewEngine.initTestEnvironment = function (ngModule, platform, summariesOrOptions) {
2394
2487
  var testBed = _getTestBedViewEngine();
2395
- testBed.initTestEnvironment(ngModule, platform, aotSummaries);
2488
+ testBed.initTestEnvironment(ngModule, platform, summariesOrOptions);
2396
2489
  return testBed;
2397
2490
  };
2398
2491
  /**
@@ -2475,6 +2568,12 @@
2475
2568
  TestBedViewEngine.createComponent = function (component) {
2476
2569
  return _getTestBedViewEngine().createComponent(component);
2477
2570
  };
2571
+ TestBedViewEngine.shouldTearDownTestingModule = function () {
2572
+ return _getTestBedViewEngine().shouldTearDownTestingModule();
2573
+ };
2574
+ TestBedViewEngine.tearDownTestingModule = function () {
2575
+ _getTestBedViewEngine().tearDownTestingModule();
2576
+ };
2478
2577
  /**
2479
2578
  * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
2480
2579
  * angular module. These are common to every test in the suite.
@@ -2486,14 +2585,19 @@
2486
2585
  * Test modules and platforms for individual platforms are available from
2487
2586
  * '@angular/<platform_name>/testing'.
2488
2587
  */
2489
- TestBedViewEngine.prototype.initTestEnvironment = function (ngModule, platform, aotSummaries) {
2588
+ TestBedViewEngine.prototype.initTestEnvironment = function (ngModule, platform, summariesOrOptions) {
2490
2589
  if (this.platform || this.ngModule) {
2491
2590
  throw new Error('Cannot set base providers because it has already been called');
2492
2591
  }
2493
2592
  this.platform = platform;
2494
2593
  this.ngModule = ngModule;
2495
- if (aotSummaries) {
2496
- this._testEnvAotSummaries = aotSummaries;
2594
+ if (typeof summariesOrOptions === 'function') {
2595
+ this._testEnvAotSummaries = summariesOrOptions;
2596
+ TestBedViewEngine._environmentTeardownOptions = undefined;
2597
+ }
2598
+ else {
2599
+ this._testEnvAotSummaries = (summariesOrOptions === null || summariesOrOptions === void 0 ? void 0 : summariesOrOptions.aotSummaries) || (function () { return []; });
2600
+ TestBedViewEngine._environmentTeardownOptions = summariesOrOptions === null || summariesOrOptions === void 0 ? void 0 : summariesOrOptions.teardown;
2497
2601
  }
2498
2602
  };
2499
2603
  /**
@@ -2504,6 +2608,7 @@
2504
2608
  this.platform = null;
2505
2609
  this.ngModule = null;
2506
2610
  this._testEnvAotSummaries = function () { return []; };
2611
+ TestBedViewEngine._environmentTeardownOptions = undefined;
2507
2612
  };
2508
2613
  TestBedViewEngine.prototype.resetTestingModule = function () {
2509
2614
  core.ɵclearOverrides();
@@ -2516,49 +2621,57 @@
2516
2621
  this._pipeOverrides = [];
2517
2622
  this._isRoot = true;
2518
2623
  this._rootProviderOverrides = [];
2519
- this._moduleRef = null;
2520
2624
  this._moduleFactory = null;
2625
+ this._pendingModuleFactory = null;
2521
2626
  this._compilerOptions = [];
2522
2627
  this._providers = [];
2523
2628
  this._declarations = [];
2524
2629
  this._imports = [];
2525
2630
  this._schemas = [];
2526
- this._instantiated = false;
2527
- this._activeFixtures.forEach(function (fixture) {
2631
+ // We have to chain a couple of try/finally blocks, because each step can
2632
+ // throw errors and we don't want it to interrupt the next step and we also
2633
+ // want an error to be thrown at the end.
2634
+ try {
2635
+ this.destroyActiveFixtures();
2636
+ }
2637
+ finally {
2528
2638
  try {
2529
- fixture.destroy();
2639
+ if (this.shouldTearDownTestingModule()) {
2640
+ this.tearDownTestingModule();
2641
+ }
2530
2642
  }
2531
- catch (e) {
2532
- console.error('Error during cleanup of component', {
2533
- component: fixture.componentInstance,
2534
- stacktrace: e,
2535
- });
2643
+ finally {
2644
+ this._moduleRef = null;
2645
+ this._instanceTeardownOptions = undefined;
2646
+ this._instantiated = false;
2536
2647
  }
2537
- });
2538
- this._activeFixtures = [];
2648
+ }
2539
2649
  };
2540
2650
  TestBedViewEngine.prototype.configureCompiler = function (config) {
2541
2651
  this._assertNotInstantiated('TestBed.configureCompiler', 'configure the compiler');
2542
2652
  this._compilerOptions.push(config);
2543
2653
  };
2544
2654
  TestBedViewEngine.prototype.configureTestingModule = function (moduleDef) {
2545
- var _a, _b, _c, _d;
2655
+ var _f, _g, _h, _j;
2546
2656
  this._assertNotInstantiated('TestBed.configureTestingModule', 'configure the test module');
2547
2657
  if (moduleDef.providers) {
2548
- (_a = this._providers).push.apply(_a, __spreadArray([], __read(moduleDef.providers)));
2658
+ (_f = this._providers).push.apply(_f, __spreadArray([], __read(moduleDef.providers)));
2549
2659
  }
2550
2660
  if (moduleDef.declarations) {
2551
- (_b = this._declarations).push.apply(_b, __spreadArray([], __read(moduleDef.declarations)));
2661
+ (_g = this._declarations).push.apply(_g, __spreadArray([], __read(moduleDef.declarations)));
2552
2662
  }
2553
2663
  if (moduleDef.imports) {
2554
- (_c = this._imports).push.apply(_c, __spreadArray([], __read(moduleDef.imports)));
2664
+ (_h = this._imports).push.apply(_h, __spreadArray([], __read(moduleDef.imports)));
2555
2665
  }
2556
2666
  if (moduleDef.schemas) {
2557
- (_d = this._schemas).push.apply(_d, __spreadArray([], __read(moduleDef.schemas)));
2667
+ (_j = this._schemas).push.apply(_j, __spreadArray([], __read(moduleDef.schemas)));
2558
2668
  }
2559
2669
  if (moduleDef.aotSummaries) {
2560
2670
  this._aotSummaries.push(moduleDef.aotSummaries);
2561
2671
  }
2672
+ // Always re-assign the teardown options, even if they're undefined.
2673
+ // This ensures that we don't carry the options between tests.
2674
+ this._instanceTeardownOptions = moduleDef.teardown;
2562
2675
  };
2563
2676
  TestBedViewEngine.prototype.compileComponents = function () {
2564
2677
  var _this = this;
@@ -2566,13 +2679,19 @@
2566
2679
  return Promise.resolve(null);
2567
2680
  }
2568
2681
  var moduleType = this._createCompilerAndModule();
2569
- return this._compiler.compileModuleAndAllComponentsAsync(moduleType)
2570
- .then(function (moduleAndComponentFactories) {
2571
- _this._moduleFactory = moduleAndComponentFactories.ngModuleFactory;
2682
+ this._pendingModuleFactory = moduleType;
2683
+ return this._compiler.compileModuleAndAllComponentsAsync(moduleType).then(function (result) {
2684
+ // If the module mismatches by the time the promise resolves, it means that the module has
2685
+ // already been destroyed and a new compilation has started. If that's the case, avoid
2686
+ // overwriting the module factory, because it can cause downstream errors.
2687
+ if (_this._pendingModuleFactory === moduleType) {
2688
+ _this._moduleFactory = result.ngModuleFactory;
2689
+ _this._pendingModuleFactory = null;
2690
+ }
2572
2691
  });
2573
2692
  };
2574
2693
  TestBedViewEngine.prototype._initIfNeeded = function () {
2575
- var e_1, _a;
2694
+ var e_1, _f;
2576
2695
  if (this._instantiated) {
2577
2696
  return;
2578
2697
  }
@@ -2594,8 +2713,8 @@
2594
2713
  }
2595
2714
  }
2596
2715
  try {
2597
- for (var _b = __values(this._templateOverrides), _c = _b.next(); !_c.done; _c = _b.next()) {
2598
- var _d = _c.value, component = _d.component, templateOf = _d.templateOf;
2716
+ for (var _g = __values(this._templateOverrides), _h = _g.next(); !_h.done; _h = _g.next()) {
2717
+ var _j = _h.value, component = _j.component, templateOf = _j.templateOf;
2599
2718
  var compFactory = this._compiler.getComponentFactory(templateOf);
2600
2719
  core.ɵoverrideComponentView(component, compFactory);
2601
2720
  }
@@ -2603,7 +2722,7 @@
2603
2722
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
2604
2723
  finally {
2605
2724
  try {
2606
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2725
+ if (_h && !_h.done && (_f = _g.return)) _f.call(_g);
2607
2726
  }
2608
2727
  finally { if (e_1) throw e_1.error; }
2609
2728
  }
@@ -2621,7 +2740,7 @@
2621
2740
  this._instantiated = true;
2622
2741
  };
2623
2742
  TestBedViewEngine.prototype._createCompilerAndModule = function () {
2624
- var e_2, _a;
2743
+ var e_2, _f;
2625
2744
  var _this = this;
2626
2745
  var providers = this._providers.concat([{ provide: TestBed, useValue: this }]);
2627
2746
  var declarations = __spreadArray(__spreadArray([], __read(this._declarations)), __read(this._templateOverrides.map(function (entry) { return entry.templateOf; })));
@@ -2655,15 +2774,15 @@
2655
2774
  var compilerFactory = this.platform.injector.get(TestingCompilerFactory);
2656
2775
  this._compiler = compilerFactory.createTestingCompiler(this._compilerOptions);
2657
2776
  try {
2658
- for (var _b = __values(__spreadArray([this._testEnvAotSummaries], __read(this._aotSummaries))), _c = _b.next(); !_c.done; _c = _b.next()) {
2659
- var summary = _c.value;
2777
+ for (var _g = __values(__spreadArray([this._testEnvAotSummaries], __read(this._aotSummaries))), _h = _g.next(); !_h.done; _h = _g.next()) {
2778
+ var summary = _h.value;
2660
2779
  this._compiler.loadAotSummaries(summary);
2661
2780
  }
2662
2781
  }
2663
2782
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
2664
2783
  finally {
2665
2784
  try {
2666
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2785
+ if (_h && !_h.done && (_f = _g.return)) _f.call(_g);
2667
2786
  }
2668
2787
  finally { if (e_2) throw e_2.error; }
2669
2788
  }
@@ -2802,6 +2921,68 @@
2802
2921
  this._activeFixtures.push(fixture);
2803
2922
  return fixture;
2804
2923
  };
2924
+ TestBedViewEngine.prototype.destroyActiveFixtures = function () {
2925
+ var errorCount = 0;
2926
+ this._activeFixtures.forEach(function (fixture) {
2927
+ try {
2928
+ fixture.destroy();
2929
+ }
2930
+ catch (e) {
2931
+ errorCount++;
2932
+ console.error('Error during cleanup of component', {
2933
+ component: fixture.componentInstance,
2934
+ stacktrace: e,
2935
+ });
2936
+ }
2937
+ });
2938
+ this._activeFixtures = [];
2939
+ if (errorCount > 0 && this.shouldRethrowTeardownErrors()) {
2940
+ throw Error(errorCount + " " + (errorCount === 1 ? 'component' : 'components') + " " +
2941
+ "threw errors during cleanup");
2942
+ }
2943
+ };
2944
+ TestBedViewEngine.prototype.shouldRethrowTeardownErrors = function () {
2945
+ var _a, _b;
2946
+ var instanceOptions = this._instanceTeardownOptions;
2947
+ var environmentOptions = TestBedViewEngine._environmentTeardownOptions;
2948
+ // If the new teardown behavior hasn't been configured, preserve the old behavior.
2949
+ if (!instanceOptions && !environmentOptions) {
2950
+ return false;
2951
+ }
2952
+ // Otherwise use the configured behavior or default to rethrowing.
2953
+ 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;
2954
+ };
2955
+ TestBedViewEngine.prototype.shouldTearDownTestingModule = function () {
2956
+ var _a, _b, _c, _d;
2957
+ 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;
2958
+ };
2959
+ TestBedViewEngine.prototype.tearDownTestingModule = function () {
2960
+ var _a, _b, _c, _d, _e;
2961
+ // If the module ref has already been destroyed, we won't be able to get a test renderer.
2962
+ if (this._moduleRef === null) {
2963
+ return;
2964
+ }
2965
+ // Resolve the renderer ahead of time, because we want to remove the root elements as the very
2966
+ // last step, but the injector will be destroyed as a part of the module ref destruction.
2967
+ var testRenderer = this.inject(TestComponentRenderer);
2968
+ try {
2969
+ this._moduleRef.destroy();
2970
+ }
2971
+ catch (e) {
2972
+ 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) {
2973
+ throw e;
2974
+ }
2975
+ else {
2976
+ console.error('Error during cleanup of a testing module', {
2977
+ component: this._moduleRef.instance,
2978
+ stacktrace: e,
2979
+ });
2980
+ }
2981
+ }
2982
+ finally {
2983
+ (_e = testRenderer === null || testRenderer === void 0 ? void 0 : testRenderer.removeAllRootElements) === null || _e === void 0 ? void 0 : _e.call(testRenderer);
2984
+ }
2985
+ };
2805
2986
  return TestBedViewEngine;
2806
2987
  }());
2807
2988
  /**
@@ -2902,10 +3083,22 @@
2902
3083
  var _global = (typeof window === 'undefined' ? global : window);
2903
3084
  // Reset the test providers and the fake async zone before each test.
2904
3085
  if (_global.beforeEach) {
2905
- _global.beforeEach(function () {
2906
- TestBed.resetTestingModule();
2907
- resetFakeAsyncZone();
2908
- });
3086
+ _global.beforeEach(getCleanupHook(false));
3087
+ }
3088
+ // We provide both a `beforeEach` and `afterEach`, because the updated behavior for
3089
+ // tearing down the module is supposed to run after the test so that we can associate
3090
+ // teardown errors with the correct test.
3091
+ if (_global.afterEach) {
3092
+ _global.afterEach(getCleanupHook(true));
3093
+ }
3094
+ function getCleanupHook(expectedTeardownValue) {
3095
+ return function () {
3096
+ if (TestBed.shouldTearDownTestingModule() ===
3097
+ expectedTeardownValue) {
3098
+ TestBed.resetTestingModule();
3099
+ resetFakeAsyncZone();
3100
+ }
3101
+ };
2909
3102
  }
2910
3103
  /**
2911
3104
  * This API should be removed. But doing so seems to break `google3` and so it requires a bit of