From 3d50fd7cac5573b06a4a24dab5c92e4b55b84dac Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Sun, 17 Dec 2017 15:10:54 -0800 Subject: [PATCH] build: add bazel test rules for remainder of packages (#21053) PR Close #21053 --- BUILD.bazel | 5 +- packages/_testing_init/init_browser_spec.ts | 4 + packages/_testing_init/init_node_spec.ts | 3 + .../render/timeline_animation_engine_spec.ts | 2 +- .../transition_animation_engine_spec.ts | 2 +- .../test/metric/multi_metric_spec.ts | 2 +- .../test/metric/perflog_metric_spec.ts | 2 +- .../test/metric/user_metric_spec.ts | 2 +- .../test/reporter/multi_reporter_spec.ts | 2 +- .../test/web_driver_extension_spec.ts | 2 +- packages/common/http/testing/BUILD.bazel | 4 +- packages/common/test/BUILD.bazel | 4 +- .../test/pipes/deprecated/number_pipe_spec.ts | 2 +- .../test/css_parser/css_lexer_spec.ts | 2 +- .../test/css_parser/css_visitor_spec.ts | 2 +- .../test/expression_parser/parser_spec.ts | 2 +- .../test/i18n/serializers/xliff2_spec.ts | 2 +- .../test/i18n/serializers/xliff_spec.ts | 2 +- .../template_parser/template_parser_spec.ts | 2 +- .../core/ts/metadata/lifecycle_hooks_spec.ts | 2 +- packages/forms/BUILD.bazel | 21 ++ packages/forms/test/BUILD.bazel | 38 ++++ packages/forms/test/directives_spec.ts | 2 +- packages/forms/test/form_array_spec.ts | 4 +- packages/forms/test/form_builder_spec.ts | 2 +- packages/forms/test/form_control_spec.ts | 4 +- packages/forms/test/form_group_spec.ts | 6 +- .../forms/test/reactive_integration_spec.ts | 1 + .../forms/test/template_integration_spec.ts | 15 +- packages/forms/test/validators_spec.ts | 6 +- .../test/value_accessor_integration_spec.ts | 15 ++ packages/http/test/BUILD.bazel | 39 ++++ .../http/test/backends/jsonp_backend_spec.ts | 39 ++-- .../http/test/backends/mock_backend_spec.ts | 11 +- .../http/test/backends/xhr_backend_spec.ts | 36 ++-- .../http/test/base_request_options_spec.ts | 6 +- packages/http/test/headers_spec.ts | 2 +- packages/http/test/http_spec.ts | 2 +- packages/http/test/static_request_spec.ts | 11 +- packages/http/test/static_response_spec.ts | 4 +- packages/http/test/url_search_params_spec.ts | 2 +- packages/language-service/BUILD.bazel | 21 ++ .../language-service/src/reflector_host.ts | 2 +- packages/language-service/test/BUILD.bazel | 25 +++ .../platform-browser-dynamic/test/BUILD.bazel | 43 +++++ .../test/metadata_overrider_spec.ts | 2 +- packages/platform-browser/test/BUILD.bazel | 49 +++++ .../test/browser/bootstrap_spec.ts | 10 +- .../test/browser/transfer_state_spec.ts | 2 +- packages/platform-server/test/BUILD.bazel | 33 ++++ .../platform-server/test/integration_spec.ts | 2 +- .../platform-webworker-dynamic/BUILD.bazel | 23 +++ packages/platform-webworker/BUILD.bazel | 23 +++ .../platform-webworker/test/BUILD.1.bazel | 20 ++ packages/platform-webworker/test/BUILD.bazel | 41 ++++ .../shared/service_message_broker_spec.ts | 9 +- .../shared/web_worker_test_util.ts | 4 +- .../worker/platform_location_spec.ts | 6 +- .../worker/renderer_v2_integration_spec.ts | 4 +- packages/router/karma-test-shim.js | 3 + packages/router/test/BUILD.bazel | 46 +++++ packages/router/test/apply_redirects.spec.ts | 12 +- packages/router/test/bootstrap.spec.ts | 4 +- .../router/test/create_router_state.spec.ts | 18 +- packages/router/test/create_url_tree.spec.ts | 8 +- packages/router/test/helpers.ts | 2 +- packages/router/test/integration.spec.ts | 10 +- packages/router/test/recognize.spec.ts | 179 +++++++++--------- packages/router/test/router.spec.ts | 42 ++-- packages/router/test/router_preloader.spec.ts | 94 ++++----- packages/router/test/router_state.spec.ts | 26 +-- .../test/spy_ng_module_factory_loader.spec.ts | 2 +- packages/router/test/utils/tree.spec.ts | 14 +- packages/service-worker/test/BUILD.bazel | 42 ++++ packages/service-worker/test/comm_spec.ts | 4 +- .../service-worker/test/integration_spec.ts | 2 +- packages/service-worker/testing/BUILD.bazel | 13 ++ .../service-worker/worker/test/BUILD.bazel | 2 - .../service-worker/worker/test/data_spec.ts | 2 +- .../service-worker/worker/test/happy_spec.ts | 2 +- .../service-worker/worker/test/idle_spec.ts | 2 +- .../worker/test/prefetch_spec.ts | 2 +- packages/types.d.ts | 3 + packages/upgrade/BUILD.bazel | 20 ++ packages/upgrade/test/BUILD.bazel | 35 ++++ packages/upgrade/test/dynamic/upgrade_spec.ts | 4 + test-main.js | 3 + tools/cjs-jasmine/index.ts | 3 + 88 files changed, 912 insertions(+), 322 deletions(-) create mode 100644 packages/forms/BUILD.bazel create mode 100644 packages/forms/test/BUILD.bazel create mode 100644 packages/http/test/BUILD.bazel create mode 100644 packages/language-service/BUILD.bazel create mode 100644 packages/language-service/test/BUILD.bazel create mode 100644 packages/platform-browser-dynamic/test/BUILD.bazel create mode 100644 packages/platform-browser/test/BUILD.bazel create mode 100644 packages/platform-server/test/BUILD.bazel create mode 100644 packages/platform-webworker-dynamic/BUILD.bazel create mode 100644 packages/platform-webworker/BUILD.bazel create mode 100644 packages/platform-webworker/test/BUILD.1.bazel create mode 100644 packages/platform-webworker/test/BUILD.bazel create mode 100644 packages/router/test/BUILD.bazel create mode 100644 packages/service-worker/test/BUILD.bazel create mode 100644 packages/service-worker/testing/BUILD.bazel create mode 100644 packages/upgrade/BUILD.bazel create mode 100644 packages/upgrade/test/BUILD.bazel diff --git a/BUILD.bazel b/BUILD.bazel index a86bcabe3c..dd358ff530 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,6 +1,9 @@ package(default_visibility = ["//visibility:public"]) -exports_files(["tsconfig.json"]) +exports_files([ + "tsconfig.json", + "node_modules/angular/angular.js", +]) # This rule belongs in node_modules/BUILD # It's here as a workaround for diff --git a/packages/_testing_init/init_browser_spec.ts b/packages/_testing_init/init_browser_spec.ts index c12a0bebad..138328b734 100644 --- a/packages/_testing_init/init_browser_spec.ts +++ b/packages/_testing_init/init_browser_spec.ts @@ -12,3 +12,7 @@ import {NoopAnimationsModule} from '@angular/platform-browser/animations'; TestBed.initTestEnvironment( [BrowserDynamicTestingModule, NoopAnimationsModule], platformBrowserDynamicTesting()); + +(window as any).isNode = false; +(window as any).isBrowser = true; +(window as any).global = window; \ No newline at end of file diff --git a/packages/_testing_init/init_node_spec.ts b/packages/_testing_init/init_node_spec.ts index 9f5b086346..8647db3b85 100644 --- a/packages/_testing_init/init_node_spec.ts +++ b/packages/_testing_init/init_node_spec.ts @@ -32,6 +32,9 @@ jasmineCore.boot = function() { // 5) Patch jasmine ENV with code which understands ProxyZone. import 'zone.js/dist/jasmine-patch.js'; +(global as any).isNode = true; +(global as any).isBrowser = false; + // Init TestBed import {TestBed} from '@angular/core/testing'; import {ServerTestingModule, platformServerTesting} from '@angular/platform-server/testing/src/server'; diff --git a/packages/animations/browser/test/render/timeline_animation_engine_spec.ts b/packages/animations/browser/test/render/timeline_animation_engine_spec.ts index fccdd08215..5842fae27f 100644 --- a/packages/animations/browser/test/render/timeline_animation_engine_spec.ts +++ b/packages/animations/browser/test/render/timeline_animation_engine_spec.ts @@ -12,7 +12,7 @@ import {AnimationDriver} from '../../src/render/animation_driver'; import {TimelineAnimationEngine} from '../../src/render/timeline_animation_engine'; import {MockAnimationDriver, MockAnimationPlayer} from '../../testing/src/mock_animation_driver'; -(function(){ +(function() { const defaultDriver = new MockAnimationDriver(); function makeEngine(driver?: AnimationDriver, normalizer?: AnimationStyleNormalizer) { diff --git a/packages/animations/browser/test/render/transition_animation_engine_spec.ts b/packages/animations/browser/test/render/transition_animation_engine_spec.ts index 5206a7f8d1..c1e25e0dd3 100644 --- a/packages/animations/browser/test/render/transition_animation_engine_spec.ts +++ b/packages/animations/browser/test/render/transition_animation_engine_spec.ts @@ -16,7 +16,7 @@ import {MockAnimationDriver, MockAnimationPlayer} from '../../testing/src/mock_a const DEFAULT_NAMESPACE_ID = 'id'; -(function(){ +(function() { const driver = new MockAnimationDriver(); // these tests are only mean't to be run within the DOM diff --git a/packages/benchpress/test/metric/multi_metric_spec.ts b/packages/benchpress/test/metric/multi_metric_spec.ts index 20f754f541..1eb8bda5bc 100644 --- a/packages/benchpress/test/metric/multi_metric_spec.ts +++ b/packages/benchpress/test/metric/multi_metric_spec.ts @@ -10,7 +10,7 @@ import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/te import {Injector, Metric, MultiMetric} from '../../index'; -(function(){ +(function() { function createMetric(ids: any[]) { const m = Injector .create([ diff --git a/packages/benchpress/test/metric/perflog_metric_spec.ts b/packages/benchpress/test/metric/perflog_metric_spec.ts index be578c2bbf..bd96f15215 100644 --- a/packages/benchpress/test/metric/perflog_metric_spec.ts +++ b/packages/benchpress/test/metric/perflog_metric_spec.ts @@ -12,7 +12,7 @@ import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@ang import {Injector, Metric, Options, PerfLogEvent, PerfLogFeatures, PerflogMetric, WebDriverExtension} from '../../index'; import {TraceEventFactory} from '../trace_event_factory'; -(function(){ +(function() { let commandLog: any[]; const eventFactory = new TraceEventFactory('timeline', 'pid0'); diff --git a/packages/benchpress/test/metric/user_metric_spec.ts b/packages/benchpress/test/metric/user_metric_spec.ts index 681635362a..15e8a1b85f 100644 --- a/packages/benchpress/test/metric/user_metric_spec.ts +++ b/packages/benchpress/test/metric/user_metric_spec.ts @@ -11,7 +11,7 @@ import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/te import {Options, PerfLogEvent, PerfLogFeatures, UserMetric, WebDriverAdapter} from '../../index'; -(function(){ +(function() { let wdAdapter: MockDriverAdapter; function createMetric( diff --git a/packages/benchpress/test/reporter/multi_reporter_spec.ts b/packages/benchpress/test/reporter/multi_reporter_spec.ts index db395128c0..4bfeb5ff82 100644 --- a/packages/benchpress/test/reporter/multi_reporter_spec.ts +++ b/packages/benchpress/test/reporter/multi_reporter_spec.ts @@ -10,7 +10,7 @@ import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/te import {Injector, MeasureValues, MultiReporter, Reporter} from '../../index'; -(function(){ +(function() { function createReporters(ids: any[]) { const r = Injector .create([ diff --git a/packages/benchpress/test/web_driver_extension_spec.ts b/packages/benchpress/test/web_driver_extension_spec.ts index 9183d58990..907c464eaa 100644 --- a/packages/benchpress/test/web_driver_extension_spec.ts +++ b/packages/benchpress/test/web_driver_extension_spec.ts @@ -10,7 +10,7 @@ import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/te import {Injector, Options, WebDriverExtension} from '../index'; -(function(){ +(function() { function createExtension(ids: any[], caps: any) { return new Promise((res, rej) => { try { diff --git a/packages/common/http/testing/BUILD.bazel b/packages/common/http/testing/BUILD.bazel index b8ba9a1f7a..6cf5ff72b7 100644 --- a/packages/common/http/testing/BUILD.bazel +++ b/packages/common/http/testing/BUILD.bazel @@ -5,10 +5,12 @@ load("@build_bazel_rules_typescript//:defs.bzl", "ts_library") ts_library( name = "testing", testonly = 1, - srcs = glob(["testing/**/*.ts"]), + srcs = glob(["**/*.ts"]), module_name = "@angular/common/http/testing", tsconfig = "//packages:tsconfig", deps = [ "//packages/common/http", + "//packages/core", + "@rxjs", ], ) diff --git a/packages/common/test/BUILD.bazel b/packages/common/test/BUILD.bazel index 18527a78f9..7d634254aa 100644 --- a/packages/common/test/BUILD.bazel +++ b/packages/common/test/BUILD.bazel @@ -10,14 +10,14 @@ ts_library( ), tsconfig = "//packages:tsconfig", deps = [ - "//packages/compiler", "//packages/common", "//packages/common/locales", + "//packages/compiler", "//packages/core", "//packages/core/testing", "//packages/platform-browser", - "//packages/platform-browser/testing", "//packages/platform-browser-dynamic", + "//packages/platform-browser/testing", ], ) diff --git a/packages/common/test/pipes/deprecated/number_pipe_spec.ts b/packages/common/test/pipes/deprecated/number_pipe_spec.ts index d4dcda69fd..d879c2f7c8 100644 --- a/packages/common/test/pipes/deprecated/number_pipe_spec.ts +++ b/packages/common/test/pipes/deprecated/number_pipe_spec.ts @@ -10,7 +10,7 @@ import {DeprecatedCurrencyPipe, DeprecatedDecimalPipe, DeprecatedPercentPipe} fr import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal'; import {browserDetection} from '@angular/platform-browser/testing/src/browser_util'; -(function(){ +(function() { function isNumeric(value: any): boolean { return !isNaN(value - parseFloat(value)); } // Between the symbol and the number, Edge adds a no breaking space and IE11 adds a standard space diff --git a/packages/compiler/test/css_parser/css_lexer_spec.ts b/packages/compiler/test/css_parser/css_lexer_spec.ts index 4bf82d5613..a5551fc195 100644 --- a/packages/compiler/test/css_parser/css_lexer_spec.ts +++ b/packages/compiler/test/css_parser/css_lexer_spec.ts @@ -9,7 +9,7 @@ import {describe, expect, it} from '../../../core/testing/src/testing_internal'; import {CssLexer, CssLexerMode, CssToken, CssTokenType, cssScannerError, getRawMessage, getToken} from '../../src/css_parser/css_lexer'; -(function(){ +(function() { function tokenize( code: string, trackComments: boolean = false, mode: CssLexerMode = CssLexerMode.ALL): CssToken[] { diff --git a/packages/compiler/test/css_parser/css_visitor_spec.ts b/packages/compiler/test/css_parser/css_visitor_spec.ts index 248d61df85..7f617ab053 100644 --- a/packages/compiler/test/css_parser/css_visitor_spec.ts +++ b/packages/compiler/test/css_parser/css_visitor_spec.ts @@ -115,7 +115,7 @@ function _getCaptureAst(capture: any[], index = 0): CssAst { return capture[index][0]; } -(function(){ +(function() { function parse(cssCode: string, ignoreErrors: boolean = false) { const output = new CssParser().parse(cssCode, 'some-fake-css-file.css'); const errors = output.errors; diff --git a/packages/compiler/test/expression_parser/parser_spec.ts b/packages/compiler/test/expression_parser/parser_spec.ts index 7a127b852f..0d08b4b4a1 100644 --- a/packages/compiler/test/expression_parser/parser_spec.ts +++ b/packages/compiler/test/expression_parser/parser_spec.ts @@ -15,7 +15,7 @@ import {expect} from '@angular/platform-browser/testing/src/matchers'; import {unparse} from './unparser'; import {validate} from './validator'; -(function(){ +(function() { function createParser() { return new Parser(new Lexer()); } function parseAction(text: string, location: any = null): ASTWithSource { diff --git a/packages/compiler/test/i18n/serializers/xliff2_spec.ts b/packages/compiler/test/i18n/serializers/xliff2_spec.ts index 1c934a13e8..937dcf0eb8 100644 --- a/packages/compiler/test/i18n/serializers/xliff2_spec.ts +++ b/packages/compiler/test/i18n/serializers/xliff2_spec.ts @@ -242,7 +242,7 @@ lignes `; -(function(){ +(function() { const serializer = new Xliff2(); function toXliff(html: string, locale: string | null = null): string { diff --git a/packages/compiler/test/i18n/serializers/xliff_spec.ts b/packages/compiler/test/i18n/serializers/xliff_spec.ts index 623f98f9b2..010bace00d 100644 --- a/packages/compiler/test/i18n/serializers/xliff_spec.ts +++ b/packages/compiler/test/i18n/serializers/xliff_spec.ts @@ -226,7 +226,7 @@ lignes `; -(function(){ +(function() { const serializer = new Xliff(); function toXliff(html: string, locale: string | null = null): string { diff --git a/packages/compiler/test/template_parser/template_parser_spec.ts b/packages/compiler/test/template_parser/template_parser_spec.ts index cffdbbf8a5..f5943068c1 100644 --- a/packages/compiler/test/template_parser/template_parser_spec.ts +++ b/packages/compiler/test/template_parser/template_parser_spec.ts @@ -323,7 +323,7 @@ class ArrayConsole implements Console { } -(function(){ +(function() { let ngIf: CompileDirectiveSummary; let parse: ( template: string, directives: CompileDirectiveSummary[], pipes?: CompilePipeSummary[], diff --git a/packages/examples/core/ts/metadata/lifecycle_hooks_spec.ts b/packages/examples/core/ts/metadata/lifecycle_hooks_spec.ts index 30186709d9..197f64fa46 100644 --- a/packages/examples/core/ts/metadata/lifecycle_hooks_spec.ts +++ b/packages/examples/core/ts/metadata/lifecycle_hooks_spec.ts @@ -9,7 +9,7 @@ import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, Component, DoCheck, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, Type} from '@angular/core'; import {TestBed} from '@angular/core/testing'; -(function(){ +(function() { describe('lifecycle hooks examples', () => { it('should work with ngOnInit', () => { // #docregion OnInit diff --git a/packages/forms/BUILD.bazel b/packages/forms/BUILD.bazel new file mode 100644 index 0000000000..50c41d4527 --- /dev/null +++ b/packages/forms/BUILD.bazel @@ -0,0 +1,21 @@ +package(default_visibility = ["//visibility:public"]) + +load("@angular//:index.bzl", "ng_module") +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library") + +ng_module( + name = "forms", + srcs = glob( + [ + "*.ts", + "src/**/*.ts", + ], + ), + module_name = "@angular/forms", + tsconfig = "//packages:tsconfig", + deps = [ + "//packages/core", + "//packages/platform-browser", + "@rxjs", + ], +) diff --git a/packages/forms/test/BUILD.bazel b/packages/forms/test/BUILD.bazel new file mode 100644 index 0000000000..ef3cb90ec8 --- /dev/null +++ b/packages/forms/test/BUILD.bazel @@ -0,0 +1,38 @@ +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test") + +ts_library( + name = "test_lib", + testonly = 1, + srcs = glob(["**/*.ts"]), + tsconfig = "//packages:tsconfig", + deps = [ + "//packages/core", + "//packages/core/testing", + "//packages/forms", + "//packages/platform-browser", + "//packages/platform-browser/testing", + "@rxjs", + ], +) + +jasmine_node_test( + name = "test", + bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"], + deps = [ + ":test_lib", + "//packages/_testing_init:node", + ], +) + +ts_web_test( + name = "test_web", + bootstrap = [ + "//:angular_bootstrap_scripts", + ], + # do not sort + deps = [ + "//packages/_testing_init:browser", + ":test_lib", + ], +) diff --git a/packages/forms/test/directives_spec.ts b/packages/forms/test/directives_spec.ts index cd9c63a81d..dd81a8b4f0 100644 --- a/packages/forms/test/directives_spec.ts +++ b/packages/forms/test/directives_spec.ts @@ -10,7 +10,7 @@ import {SimpleChange} from '@angular/core'; import {fakeAsync, flushMicrotasks, tick} from '@angular/core/testing'; import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal'; import {AbstractControl, CheckboxControlValueAccessor, ControlValueAccessor, DefaultValueAccessor, FormArray, FormArrayName, FormControl, FormControlDirective, FormControlName, FormGroup, FormGroupDirective, FormGroupName, NgControl, NgForm, NgModel, NgModelGroup, SelectControlValueAccessor, SelectMultipleControlValueAccessor, ValidationErrors, Validator, Validators} from '@angular/forms'; -import {composeValidators, selectValueAccessor} from '../src/directives/shared'; +import {composeValidators, selectValueAccessor} from '@angular/forms/src/directives/shared'; import {SpyNgControl, SpyValueAccessor} from './spies'; class DummyControlValueAccessor implements ControlValueAccessor { diff --git a/packages/forms/test/form_array_spec.ts b/packages/forms/test/form_array_spec.ts index ec0a30992d..6e6d45a41b 100644 --- a/packages/forms/test/form_array_spec.ts +++ b/packages/forms/test/form_array_spec.ts @@ -9,10 +9,10 @@ import {fakeAsync, tick} from '@angular/core/testing'; import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal'; import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors} from '@angular/forms'; +import {Validators} from '@angular/forms/src/validators'; import {of } from 'rxjs/observable/of'; -import {Validators} from '../src/validators'; -(function(){ +(function() { function asyncValidator(expected: string, timeouts = {}) { return (c: AbstractControl) => { let resolve: (result: any) => void = undefined !; diff --git a/packages/forms/test/form_builder_spec.ts b/packages/forms/test/form_builder_spec.ts index b8c112be3c..1a2ecea2c0 100644 --- a/packages/forms/test/form_builder_spec.ts +++ b/packages/forms/test/form_builder_spec.ts @@ -9,7 +9,7 @@ import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal'; import {FormBuilder} from '@angular/forms'; -(function(){ +(function() { function syncValidator(_: any /** TODO #9100 */): any /** TODO #9100 */ { return null; } function asyncValidator(_: any /** TODO #9100 */) { return Promise.resolve(null); } diff --git a/packages/forms/test/form_control_spec.ts b/packages/forms/test/form_control_spec.ts index 902c7af226..043f910138 100644 --- a/packages/forms/test/form_control_spec.ts +++ b/packages/forms/test/form_control_spec.ts @@ -11,9 +11,9 @@ import {fakeAsync, tick} from '@angular/core/testing'; import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal'; import {FormControl, FormGroup, Validators} from '@angular/forms'; -import {FormArray} from '../src/model'; +import {FormArray} from '@angular/forms/src/model'; -(function(){ +(function() { function asyncValidator(expected: string, timeouts = {}) { return (c: FormControl) => { let resolve: (result: any) => void = undefined !; diff --git a/packages/forms/test/form_group_spec.ts b/packages/forms/test/form_group_spec.ts index c5edd1112f..07f0cf3ec0 100644 --- a/packages/forms/test/form_group_spec.ts +++ b/packages/forms/test/form_group_spec.ts @@ -13,7 +13,7 @@ import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors, Va import {of } from 'rxjs/observable/of'; -(function(){ +(function() { function simpleValidator(c: AbstractControl): ValidationErrors|null { return c.get('one') !.value === 'correct' ? null : {'broken': true}; } @@ -1070,12 +1070,12 @@ import {of } from 'rxjs/observable/of'; }); it('should update tree validity', () => { - form._updateTreeValidity(); + (form as any)._updateTreeValidity(); expect(logger).toEqual(['one', 'two', 'nested', 'three', 'form']); }); it('should not emit events when turned off', () => { - form._updateTreeValidity({emitEvent: false}); + (form as any)._updateTreeValidity({emitEvent: false}); expect(logger).toEqual([]); }); diff --git a/packages/forms/test/reactive_integration_spec.ts b/packages/forms/test/reactive_integration_spec.ts index 78ea96ad6c..f9a014d73c 100644 --- a/packages/forms/test/reactive_integration_spec.ts +++ b/packages/forms/test/reactive_integration_spec.ts @@ -1560,6 +1560,7 @@ import {MyInput, MyInputForm} from './value_accessor_integration_spec'; })); it('should not update the view when the value initially came from the view', fakeAsync(() => { + if (isNode) return; const fixture = initTest(FormControlNgModel); fixture.componentInstance.control = new FormControl(''); fixture.detectChanges(); diff --git a/packages/forms/test/template_integration_spec.ts b/packages/forms/test/template_integration_spec.ts index d4a459a71a..7426b74fda 100644 --- a/packages/forms/test/template_integration_spec.ts +++ b/packages/forms/test/template_integration_spec.ts @@ -295,7 +295,7 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat const form = fixture.debugElement.children[0].injector.get(NgForm); const name = form.control.get('name') as FormControl; - expect(name._updateOn).toBeUndefined(); + expect((name as any)._updateOn).toBeUndefined(); expect(name.updateOn).toEqual('change'); })); @@ -309,7 +309,7 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat const form = fixture.debugElement.children[0].injector.get(NgForm); const name = form.control.get('name') as FormControl; - expect(name._updateOn).toEqual('blur'); + expect((name as any)._updateOn).toEqual('blur'); expect(name.updateOn).toEqual('blur'); })); @@ -555,7 +555,7 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat const form = fixture.debugElement.children[0].injector.get(NgForm); const name = form.control.get('name') as FormControl; - expect(name._updateOn).toEqual('submit'); + expect((name as any)._updateOn).toEqual('submit'); expect(name.updateOn).toEqual('submit'); })); @@ -891,12 +891,12 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat const form = fixture.debugElement.children[0].injector.get(NgForm); const controlOne = form.control.get('one') !as FormControl; - expect(controlOne._updateOn).toBeUndefined(); + expect((controlOne as any)._updateOn).toBeUndefined(); expect(controlOne.updateOn) .toEqual('blur', 'Expected first control to inherit updateOn from parent form.'); const controlTwo = form.control.get('two') !as FormControl; - expect(controlTwo._updateOn).toBeUndefined(); + expect((controlTwo as any)._updateOn).toBeUndefined(); expect(controlTwo.updateOn) .toEqual('blur', 'Expected last control to inherit updateOn from parent form.'); })); @@ -932,12 +932,13 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat const form = fixture.debugElement.children[0].injector.get(NgForm); const controlOne = form.control.get('one') !as FormControl; - expect(controlOne._updateOn).toBeUndefined(); + expect((controlOne as any)._updateOn).toBeUndefined(); expect(controlOne.updateOn) .toEqual('change', 'Expected control updateOn to inherit form updateOn.'); const controlTwo = form.control.get('two') !as FormControl; - expect(controlTwo._updateOn).toEqual('blur', 'Expected control to set blur override.'); + expect((controlTwo as any)._updateOn) + .toEqual('blur', 'Expected control to set blur override.'); expect(controlTwo.updateOn) .toEqual('blur', 'Expected control updateOn to override form updateOn.'); })); diff --git a/packages/forms/test/validators_spec.ts b/packages/forms/test/validators_spec.ts index 8ff86ae504..1cd9acdbb1 100644 --- a/packages/forms/test/validators_spec.ts +++ b/packages/forms/test/validators_spec.ts @@ -9,15 +9,15 @@ import {fakeAsync, tick} from '@angular/core/testing'; import {describe, expect, it} from '@angular/core/testing/src/testing_internal'; import {AbstractControl, AsyncValidatorFn, FormArray, FormControl, Validators} from '@angular/forms'; +import {normalizeAsyncValidator} from '@angular/forms/src/directives/normalize_validator'; +import {AsyncValidator, ValidationErrors, ValidatorFn} from '@angular/forms/src/directives/validators'; import {Observable} from 'rxjs/Observable'; import {of } from 'rxjs/observable/of'; import {timer} from 'rxjs/observable/timer'; import {first} from 'rxjs/operator/first'; import {map} from 'rxjs/operator/map'; -import {normalizeAsyncValidator} from '../src/directives/normalize_validator'; -import {AsyncValidator, ValidationErrors, ValidatorFn} from '../src/directives/validators'; -(function(){ +(function() { function validator(key: string, error: any): ValidatorFn { return (c: AbstractControl) => { const r: ValidationErrors = {}; diff --git a/packages/forms/test/value_accessor_integration_spec.ts b/packages/forms/test/value_accessor_integration_spec.ts index 8703bb7b81..dec9d7e418 100644 --- a/packages/forms/test/value_accessor_integration_spec.ts +++ b/packages/forms/test/value_accessor_integration_spec.ts @@ -164,6 +164,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util' describe('in reactive forms', () => { it(`should support primitive values`, () => { + if (isNode) return; const fixture = initTest(FormControlNameSelect); fixture.detectChanges(); @@ -183,6 +184,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util' }); it(`should support objects`, () => { + if (isNode) return; const fixture = initTest(FormControlSelectNgValue); fixture.detectChanges(); @@ -201,6 +203,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util' }); it('should compare options using provided compareWith function', () => { + if (isNode) return; const fixture = initTest(FormControlSelectWithCompareFn); fixture.detectChanges(); @@ -211,6 +214,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util' }); it('should support re-assigning the options array with compareWith', () => { + if (isNode) return; const fixture = initTest(FormControlSelectWithCompareFn); fixture.detectChanges(); @@ -239,6 +243,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util' describe('in template-driven forms', () => { it('with option values that are objects', fakeAsync(() => { + if (isNode) return; const fixture = initTest(NgModelSelectForm); const comp = fixture.componentInstance; comp.cities = [{'name': 'SF'}, {'name': 'NYC'}, {'name': 'Buffalo'}]; @@ -263,6 +268,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util' })); it('when new options are added', fakeAsync(() => { + if (isNode) return; const fixture = initTest(NgModelSelectForm); const comp = fixture.componentInstance; comp.cities = [{'name': 'SF'}, {'name': 'NYC'}]; @@ -300,6 +306,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util' })); it('when option values have same content, but different identities', fakeAsync(() => { + if (isNode) return; const fixture = initTest(NgModelSelectForm); const comp = fixture.componentInstance; comp.cities = [{'name': 'SF'}, {'name': 'NYC'}, {'name': 'NYC'}]; @@ -347,6 +354,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util' }); it('should compare options using provided compareWith function', fakeAsync(() => { + if (isNode) return; const fixture = initTest(NgModelSelectWithCustomCompareFnForm); const comp = fixture.componentInstance; comp.selectedCity = {id: 1, name: 'SF'}; @@ -361,6 +369,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util' })); it('should support re-assigning the options array with compareWith', fakeAsync(() => { + if (isNode) return; const fixture = initTest(NgModelSelectWithCustomCompareFnForm); fixture.componentInstance.selectedCity = {id: 1, name: 'SF'}; fixture.componentInstance.cities = [{id: 1, name: 'SF'}, {id: 2, name: 'NY'}]; @@ -400,6 +409,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util' describe('in reactive forms', () => { it('should support primitive values', () => { + if (isNode) return; const fixture = initTest(FormControlSelectMultiple); fixture.detectChanges(); @@ -410,6 +420,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util' }); it('should support objects', () => { + if (isNode) return; const fixture = initTest(FormControlSelectMultipleNgValue); fixture.detectChanges(); @@ -427,6 +438,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util' }); it('should compare options using provided compareWith function', fakeAsync(() => { + if (isNode) return; const fixture = initTest(FormControlSelectMultipleWithCompareFn); fixture.detectChanges(); tick(); @@ -478,6 +490,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util' it('should reflect state of model after option selected and new options subsequently added', fakeAsync(() => { + if (isNode) return; setSelectedCities([]); selectOptionViaUI('1: Object'); @@ -491,6 +504,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util' it('should reflect state of model after option selected and then other options removed', fakeAsync(() => { + if (isNode) return; setSelectedCities([]); selectOptionViaUI('1: Object'); @@ -512,6 +526,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util' }); it('should compare options using provided compareWith function', fakeAsync(() => { + if (isNode) return; const fixture = initTest(NgModelSelectMultipleWithCustomCompareFnForm); const comp = fixture.componentInstance; comp.cities = [{id: 1, name: 'SF'}, {id: 2, name: 'LA'}]; diff --git a/packages/http/test/BUILD.bazel b/packages/http/test/BUILD.bazel new file mode 100644 index 0000000000..56ffd0730f --- /dev/null +++ b/packages/http/test/BUILD.bazel @@ -0,0 +1,39 @@ +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test") + +ts_library( + name = "test_lib", + testonly = 1, + srcs = glob(["**/*.ts"]), + tsconfig = "//packages:tsconfig", + deps = [ + "//packages/core", + "//packages/core/testing", + "//packages/http", + "//packages/http/testing", + "//packages/platform-browser", + "//packages/platform-browser/testing", + "@rxjs", + ], +) + +jasmine_node_test( + name = "test", + bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"], + deps = [ + ":test_lib", + "//packages/_testing_init:node", + ], +) + +ts_web_test( + name = "test_web", + bootstrap = [ + "//:angular_bootstrap_scripts", + ], + # do not sort + deps = [ + "//packages/_testing_init:browser", + ":test_lib", + ], +) diff --git a/packages/http/test/backends/jsonp_backend_spec.ts b/packages/http/test/backends/jsonp_backend_spec.ts index 4f98ca8066..f9fc4f4f35 100644 --- a/packages/http/test/backends/jsonp_backend_spec.ts +++ b/packages/http/test/backends/jsonp_backend_spec.ts @@ -8,13 +8,14 @@ import {Injector} from '@angular/core'; import {AsyncTestCompleter, SpyObject, afterEach, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal'; +import {BrowserJsonp} from '@angular/http/src/backends/browser_jsonp'; +import {JSONPBackend, JSONPConnection} from '@angular/http/src/backends/jsonp_backend'; +import {BaseRequestOptions, RequestOptions} from '@angular/http/src/base_request_options'; +import {BaseResponseOptions, ResponseOptions} from '@angular/http/src/base_response_options'; +import {ReadyState, RequestMethod, ResponseType} from '@angular/http/src/enums'; +import {Request} from '@angular/http/src/static_request'; +import {Response} from '@angular/http/src/static_response'; import {expect} from '@angular/platform-browser/testing/src/matchers'; -import {BrowserJsonp} from '../../src/backends/browser_jsonp'; -import {JSONPBackend, JSONPConnection} from '../../src/backends/jsonp_backend'; -import {BaseRequestOptions, RequestOptions} from '../../src/base_request_options'; -import {BaseResponseOptions, ResponseOptions} from '../../src/base_response_options'; -import {ReadyState, RequestMethod, ResponseType} from '../../src/enums'; -import {Request} from '../../src/static_request'; let existingScripts: MockBrowserJsonp[] = []; @@ -75,10 +76,10 @@ class MockBrowserJsonp extends BrowserJsonp { describe('JSONPConnection', () => { it('should use the injected BaseResponseOptions to create the response', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - const connection = new JSONPConnection( + const connection = new (JSONPConnection as any)( sampleRequest, new MockBrowserJsonp(), new ResponseOptions({type: ResponseType.Error})); - connection.response.subscribe(res => { + connection.response.subscribe((res: Response) => { expect(res.type).toBe(ResponseType.Error); async.done(); }); @@ -88,7 +89,7 @@ class MockBrowserJsonp extends BrowserJsonp { it('should ignore load/callback when disposed', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - const connection = new JSONPConnection(sampleRequest, new MockBrowserJsonp()); + const connection = new (JSONPConnection as any)(sampleRequest, new MockBrowserJsonp()); const spy = new SpyObject(); const loadSpy = spy.spy('load'); const errorSpy = spy.spy('error'); @@ -111,13 +112,13 @@ class MockBrowserJsonp extends BrowserJsonp { it('should report error if loaded without invoking callback', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - const connection = new JSONPConnection(sampleRequest, new MockBrowserJsonp()); + const connection = new (JSONPConnection as any)(sampleRequest, new MockBrowserJsonp()); connection.response.subscribe( - res => { + (res: Response) => { expect('response listener called').toBe(false); async.done(); }, - err => { + (err: Response) => { expect(err.text()).toEqual('JSONP injected script did not invoke callback.'); async.done(); }); @@ -127,14 +128,14 @@ class MockBrowserJsonp extends BrowserJsonp { it('should report error if script contains error', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - const connection = new JSONPConnection(sampleRequest, new MockBrowserJsonp()); + const connection = new (JSONPConnection as any)(sampleRequest, new MockBrowserJsonp()); connection.response.subscribe( - res => { + (res: Response) => { expect('response listener called').toBe(false); async.done(); }, - err => { + (err: Response) => { expect(err.text()).toBe('Oops!'); async.done(); }); @@ -149,16 +150,18 @@ class MockBrowserJsonp extends BrowserJsonp { const base = new BaseRequestOptions(); const req = new Request(base.merge( new RequestOptions({url: 'https://google.com', method: method})) as any); - expect(() => new JSONPConnection(req, new MockBrowserJsonp()).response.subscribe()) + expect( + () => new (JSONPConnection as any)(req, new MockBrowserJsonp()) + .response.subscribe()) .toThrowError(); }); }); it('should respond with data passed to callback', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - const connection = new JSONPConnection(sampleRequest, new MockBrowserJsonp()); + const connection = new (JSONPConnection as any)(sampleRequest, new MockBrowserJsonp()); - connection.response.subscribe(res => { + connection.response.subscribe((res: Response) => { expect(res.json()).toEqual(({fake_payload: true, blob_id: 12345})); async.done(); }); diff --git a/packages/http/test/backends/mock_backend_spec.ts b/packages/http/test/backends/mock_backend_spec.ts index 88883251e5..06fd11e45d 100644 --- a/packages/http/test/backends/mock_backend_spec.ts +++ b/packages/http/test/backends/mock_backend_spec.ts @@ -8,15 +8,14 @@ import {Injector} from '@angular/core'; import {AsyncTestCompleter, beforeEach, describe, inject, it, xit} from '@angular/core/testing/src/testing_internal'; +import {BaseRequestOptions, RequestOptions} from '@angular/http/src/base_request_options'; +import {BaseResponseOptions, ResponseOptions} from '@angular/http/src/base_response_options'; +import {Request} from '@angular/http/src/static_request'; +import {Response} from '@angular/http/src/static_response'; +import {MockBackend, MockConnection} from '@angular/http/testing/src/mock_backend'; import {expect} from '@angular/platform-browser/testing/src/matchers'; import {ReplaySubject} from 'rxjs/ReplaySubject'; -import {BaseRequestOptions, RequestOptions} from '../../src/base_request_options'; -import {BaseResponseOptions, ResponseOptions} from '../../src/base_response_options'; -import {Request} from '../../src/static_request'; -import {Response} from '../../src/static_response'; -import {MockBackend, MockConnection} from '../../testing/src/mock_backend'; - { describe('MockBackend', () => { diff --git a/packages/http/test/backends/xhr_backend_spec.ts b/packages/http/test/backends/xhr_backend_spec.ts index 7c4b117aa6..c9d966177b 100644 --- a/packages/http/test/backends/xhr_backend_spec.ts +++ b/packages/http/test/backends/xhr_backend_spec.ts @@ -8,17 +8,17 @@ import {Injectable} from '@angular/core'; import {AsyncTestCompleter, SpyObject, afterEach, beforeEach, beforeEachProviders, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal'; +import {BrowserXhr} from '@angular/http/src/backends/browser_xhr'; +import {CookieXSRFStrategy, XHRBackend, XHRConnection} from '@angular/http/src/backends/xhr_backend'; +import {BaseRequestOptions, RequestOptions} from '@angular/http/src/base_request_options'; +import {BaseResponseOptions, ResponseOptions} from '@angular/http/src/base_response_options'; +import {ResponseContentType, ResponseType} from '@angular/http/src/enums'; +import {Headers} from '@angular/http/src/headers'; +import {XSRFStrategy} from '@angular/http/src/interfaces'; +import {Request} from '@angular/http/src/static_request'; +import {Response} from '@angular/http/src/static_response'; +import {URLSearchParams} from '@angular/http/src/url_search_params'; import {ɵgetDOM as getDOM} from '@angular/platform-browser'; -import {BrowserXhr} from '../../src/backends/browser_xhr'; -import {CookieXSRFStrategy, XHRBackend, XHRConnection} from '../../src/backends/xhr_backend'; -import {BaseRequestOptions, RequestOptions} from '../../src/base_request_options'; -import {BaseResponseOptions, ResponseOptions} from '../../src/base_response_options'; -import {ResponseContentType, ResponseType} from '../../src/enums'; -import {Headers} from '../../src/headers'; -import {XSRFStrategy} from '../../src/interfaces'; -import {Request} from '../../src/static_request'; -import {Response} from '../../src/static_response'; -import {URLSearchParams} from '../../src/url_search_params'; let abortSpy: any; let sendSpy: any; @@ -422,7 +422,7 @@ class MockBrowserXHR extends BrowserXhr { (res: Response) => { }, - errRes => { + (errRes: Response) => { expect(errRes.status).toBe(statusCode); async.done(); }); @@ -444,7 +444,7 @@ class MockBrowserXHR extends BrowserXhr { nextCalled = true; expect(res.status).toBe(statusCode); }, - errRes => { errorCalled = true; }, + (errRes: Response) => { errorCalled = true; }, () => { expect(nextCalled).toBe(true); expect(errorCalled).toBe(false); @@ -461,7 +461,7 @@ class MockBrowserXHR extends BrowserXhr { const connection = new XHRConnection( sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode})); - connection.response.subscribe(res => { + connection.response.subscribe((res: Response) => { expect(res.ok).toBe(true); async.done(); }); @@ -477,8 +477,8 @@ class MockBrowserXHR extends BrowserXhr { sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode})); connection.response.subscribe( - res => { throw 'should not be called'; }, - errRes => { + (res: Response) => { throw 'should not be called'; }, + (errRes: Response) => { expect(errRes.ok).toBe(false); async.done(); }); @@ -497,7 +497,7 @@ class MockBrowserXHR extends BrowserXhr { connection.response.subscribe( (res: Response) => { nextCalled = true; }, - errRes => { + (errRes: Response) => { expect(errRes.status).toBe(statusCode); expect(nextCalled).toBe(false); async.done(); @@ -553,8 +553,8 @@ class MockBrowserXHR extends BrowserXhr { connection1.response.subscribe((res: Response) => { expect(res.text()).toBe(responseBody); - connection2.response.subscribe(ress => { - expect(ress.text()).toBe(responseBody); + connection2.response.subscribe((res: Response) => { + expect(res.text()).toBe(responseBody); async.done(); }); existingXHRs[1].setStatusCode(200); diff --git a/packages/http/test/base_request_options_spec.ts b/packages/http/test/base_request_options_spec.ts index bf694d9870..ce2b0811c1 100644 --- a/packages/http/test/base_request_options_spec.ts +++ b/packages/http/test/base_request_options_spec.ts @@ -7,9 +7,9 @@ */ import {describe, expect, it} from '@angular/core/testing/src/testing_internal'; -import {BaseRequestOptions, RequestOptions} from '../src/base_request_options'; -import {RequestMethod} from '../src/enums'; -import {Headers} from '../src/headers'; +import {BaseRequestOptions, RequestOptions} from '@angular/http/src/base_request_options'; +import {RequestMethod} from '@angular/http/src/enums'; +import {Headers} from '@angular/http/src/headers'; { describe('BaseRequestOptions', () => { diff --git a/packages/http/test/headers_spec.ts b/packages/http/test/headers_spec.ts index 8bf97cd58a..f5684ceeb9 100644 --- a/packages/http/test/headers_spec.ts +++ b/packages/http/test/headers_spec.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Headers} from '../src/headers'; +import {Headers} from '@angular/http/src/headers'; { describe('Headers', () => { diff --git a/packages/http/test/http_spec.ts b/packages/http/test/http_spec.ts index 383180376f..72389b6f46 100644 --- a/packages/http/test/http_spec.ts +++ b/packages/http/test/http_spec.ts @@ -9,12 +9,12 @@ import {Injector} from '@angular/core'; import {TestBed, getTestBed} from '@angular/core/testing'; import {AsyncTestCompleter, afterEach, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal'; +import {stringToArrayBuffer} from '@angular/http/src/http_utils'; import {expect} from '@angular/platform-browser/testing/src/matchers'; import {Observable} from 'rxjs/Observable'; import {zip} from 'rxjs/observable/zip'; import {BaseRequestOptions, ConnectionBackend, Http, HttpModule, JSONPBackend, Jsonp, JsonpModule, Request, RequestMethod, RequestOptions, Response, ResponseContentType, ResponseOptions, URLSearchParams, XHRBackend} from '../index'; -import {stringToArrayBuffer} from '../src/http_utils'; import {MockBackend, MockConnection} from '../testing/src/mock_backend'; { diff --git a/packages/http/test/static_request_spec.ts b/packages/http/test/static_request_spec.ts index 95e080ba08..06072d045a 100644 --- a/packages/http/test/static_request_spec.ts +++ b/packages/http/test/static_request_spec.ts @@ -7,14 +7,13 @@ */ import {describe, expect, it} from '@angular/core/testing/src/testing_internal'; +import {RequestOptions} from '@angular/http/src/base_request_options'; +import {ContentType} from '@angular/http/src/enums'; +import {Headers} from '@angular/http/src/headers'; +import {stringToArrayBuffer, stringToArrayBuffer8} from '@angular/http/src/http_utils'; +import {ArrayBuffer, Request} from '@angular/http/src/static_request'; import {ɵgetDOM as getDOM} from '@angular/platform-browser'; -import {RequestOptions} from '../src/base_request_options'; -import {ContentType} from '../src/enums'; -import {Headers} from '../src/headers'; -import {stringToArrayBuffer, stringToArrayBuffer8} from '../src/http_utils'; -import {ArrayBuffer, Request} from '../src/static_request'; - { describe('Request', () => { describe('detectContentType', () => { diff --git a/packages/http/test/static_response_spec.ts b/packages/http/test/static_response_spec.ts index de369f27c7..00300ef137 100644 --- a/packages/http/test/static_response_spec.ts +++ b/packages/http/test/static_response_spec.ts @@ -8,8 +8,8 @@ import {describe, expect, it} from '@angular/core/testing/src/testing_internal'; -import {ResponseOptions} from '../src/base_response_options'; -import {Response} from '../src/static_response'; +import {ResponseOptions} from '@angular/http/src/base_response_options'; +import {Response} from '@angular/http/src/static_response'; diff --git a/packages/http/test/url_search_params_spec.ts b/packages/http/test/url_search_params_spec.ts index d707dcdc57..8144ce95ae 100644 --- a/packages/http/test/url_search_params_spec.ts +++ b/packages/http/test/url_search_params_spec.ts @@ -7,7 +7,7 @@ */ import {describe, expect, it} from '@angular/core/testing/src/testing_internal'; -import {URLSearchParams} from '../src/url_search_params'; +import {URLSearchParams} from '@angular/http/src/url_search_params'; { describe('URLSearchParams', () => { diff --git a/packages/language-service/BUILD.bazel b/packages/language-service/BUILD.bazel new file mode 100644 index 0000000000..99274760a5 --- /dev/null +++ b/packages/language-service/BUILD.bazel @@ -0,0 +1,21 @@ +package(default_visibility = ["//visibility:public"]) + +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library") + +ts_library( + name = "language-service", + srcs = glob( + [ + "*.ts", + "src/**/*.ts", + ], + ), + module_name = "@angular/language-service", + tsconfig = "//packages:tsconfig", + deps = [ + "//packages:types", + "//packages/compiler", + "//packages/compiler-cli", + "//packages/core", + ], +) diff --git a/packages/language-service/src/reflector_host.ts b/packages/language-service/src/reflector_host.ts index 99511fad06..0fb95143a0 100644 --- a/packages/language-service/src/reflector_host.ts +++ b/packages/language-service/src/reflector_host.ts @@ -72,7 +72,7 @@ export class ReflectorHost implements StaticSymbolResolverHost { containingFile = path.join(this.options.basePath !, 'index.ts'); } const resolved = - ts.resolveModuleName(moduleName, containingFile, this.options, this.hostAdapter) + ts.resolveModuleName(moduleName, containingFile !, this.options, this.hostAdapter) .resolvedModule; return resolved ? resolved.resolvedFileName : null; } diff --git a/packages/language-service/test/BUILD.bazel b/packages/language-service/test/BUILD.bazel new file mode 100644 index 0000000000..d165805049 --- /dev/null +++ b/packages/language-service/test/BUILD.bazel @@ -0,0 +1,25 @@ +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test") + +ts_library( + name = "test_lib", + testonly = 1, + srcs = glob(["**/*.ts"]), + tsconfig = "//packages:tsconfig", + deps = [ + "//packages:types", + "//packages/compiler", + "//packages/language-service", + ], +) + +jasmine_node_test( + name = "test", + bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"], + # dissable since tests are running but not yet passing + tags = ["manual"], + deps = [ + ":test_lib", + "//packages/_testing_init:node", + ], +) diff --git a/packages/platform-browser-dynamic/test/BUILD.bazel b/packages/platform-browser-dynamic/test/BUILD.bazel new file mode 100644 index 0000000000..cb2aef562f --- /dev/null +++ b/packages/platform-browser-dynamic/test/BUILD.bazel @@ -0,0 +1,43 @@ +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test") + +ts_library( + name = "test_lib", + testonly = 1, + srcs = glob(["**/*.ts"]), + tsconfig = "//packages:tsconfig", + deps = [ + "//packages:types", + "//packages/compiler", + "//packages/core", + "//packages/core/testing", + "//packages/platform-browser-dynamic", + "//packages/platform-browser-dynamic/testing", + "//packages/platform-browser/testing", + ], +) + +jasmine_node_test( + name = "test", + bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"], + # dissable since tests are running but not yet passing + tags = ["manual"], + deps = [ + ":test_lib", + "//packages/_testing_init:node", + ], +) + +ts_web_test( + name = "test_web", + bootstrap = [ + "//:angular_bootstrap_scripts", + ], + # dissable since tests are running but not yet passing + tags = ["manual"], + # do not sort + deps = [ + "//packages/_testing_init:browser", + ":test_lib", + ], +) diff --git a/packages/platform-browser-dynamic/test/metadata_overrider_spec.ts b/packages/platform-browser-dynamic/test/metadata_overrider_spec.ts index 91183e9ceb..05367b167f 100644 --- a/packages/platform-browser-dynamic/test/metadata_overrider_spec.ts +++ b/packages/platform-browser-dynamic/test/metadata_overrider_spec.ts @@ -6,8 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ +import {MetadataOverrider} from '@angular/platform-browser-dynamic/testing/src/metadata_overrider'; import {expect} from '@angular/platform-browser/testing/src/matchers'; -import {MetadataOverrider} from '../testing/src/metadata_overrider'; interface SomeMetadataType { plainProp?: string; diff --git a/packages/platform-browser/test/BUILD.bazel b/packages/platform-browser/test/BUILD.bazel new file mode 100644 index 0000000000..bb58950daf --- /dev/null +++ b/packages/platform-browser/test/BUILD.bazel @@ -0,0 +1,49 @@ +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test") + +ts_library( + name = "test_lib", + testonly = 1, + srcs = glob(["**/*.ts"]), + tsconfig = "//packages:tsconfig", + deps = [ + "//packages:types", + "//packages/animations", + "//packages/animations/browser", + "//packages/animations/browser/testing", + "//packages/common", + "//packages/compiler", + "//packages/core", + "//packages/core/testing", + "//packages/platform-browser", + "//packages/platform-browser-dynamic", + "//packages/platform-browser/animations", + "//packages/platform-browser/testing", + "@rxjs", + ], +) + +jasmine_node_test( + name = "test", + bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"], + # dissable since tests are running but not yet passing + tags = ["manual"], + deps = [ + ":test_lib", + "//packages/_testing_init:node", + ], +) + +ts_web_test( + name = "test_web", + bootstrap = [ + "//:angular_bootstrap_scripts", + ], + # dissable since tests are running but not yet passing + tags = ["manual"], + # do not sort + deps = [ + "//packages/_testing_init:browser", + ":test_lib", + ], +) diff --git a/packages/platform-browser/test/browser/bootstrap_spec.ts b/packages/platform-browser/test/browser/bootstrap_spec.ts index f08204ba83..947ef60773 100644 --- a/packages/platform-browser/test/browser/bootstrap_spec.ts +++ b/packages/platform-browser/test/browser/bootstrap_spec.ts @@ -161,7 +161,7 @@ function bootstrap( inject([AsyncTestCompleter], (done: AsyncTestCompleter) => { const logger = new MockConsole(); const errorHandler = new ErrorHandler(); - errorHandler._console = logger as any; + (errorHandler as any)._console = logger as any; expect( () => bootstrap( HelloRootDirectiveIsNotCmp, [{provide: ErrorHandler, useValue: errorHandler}])) @@ -173,7 +173,7 @@ function bootstrap( inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { const logger = new MockConsole(); const errorHandler = new ErrorHandler(); - errorHandler._console = logger as any; + (errorHandler as any)._console = logger as any; bootstrap(NonExistentComp, [ {provide: ErrorHandler, useValue: errorHandler} ]).then(null, (reason) => { @@ -187,7 +187,7 @@ function bootstrap( it('should throw if no provider', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { const logger = new MockConsole(); const errorHandler = new ErrorHandler(); - errorHandler._console = logger as any; + (errorHandler as any)._console = logger as any; class IDontExist {} @@ -223,7 +223,7 @@ function bootstrap( inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { const logger = new MockConsole(); const errorHandler = new ErrorHandler(); - errorHandler._console = logger as any; + (errorHandler as any)._console = logger as any; const refPromise = bootstrap(NonExistentComp, [{provide: ErrorHandler, useValue: errorHandler}]); @@ -238,7 +238,7 @@ function bootstrap( inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { const logger = new MockConsole(); const errorHandler = new ErrorHandler(); - errorHandler._console = logger as any; + (errorHandler as any)._console = logger as any; const refPromise = bootstrap(NonExistentComp, [{provide: ErrorHandler, useValue: errorHandler}]); diff --git a/packages/platform-browser/test/browser/transfer_state_spec.ts b/packages/platform-browser/test/browser/transfer_state_spec.ts index 975be183ba..9235ffbb6c 100644 --- a/packages/platform-browser/test/browser/transfer_state_spec.ts +++ b/packages/platform-browser/test/browser/transfer_state_spec.ts @@ -12,7 +12,7 @@ import {BrowserModule, BrowserTransferStateModule, TransferState} from '@angular import {StateKey, escapeHtml, makeStateKey, unescapeHtml} from '@angular/platform-browser/src/browser/transfer_state'; import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens'; -(function(){ +(function() { function removeScriptTag(doc: Document, id: string) { const existing = doc.getElementById(id); if (existing) { diff --git a/packages/platform-server/test/BUILD.bazel b/packages/platform-server/test/BUILD.bazel new file mode 100644 index 0000000000..de549a4b07 --- /dev/null +++ b/packages/platform-server/test/BUILD.bazel @@ -0,0 +1,33 @@ +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test") + +ts_library( + name = "test_lib", + testonly = 1, + srcs = glob(["**/*.ts"]), + tsconfig = "//packages:tsconfig", + deps = [ + "//packages:types", + "//packages/animations", + "//packages/common", + "//packages/common/http", + "//packages/common/http/testing", + "//packages/compiler", + "//packages/core", + "//packages/core/testing", + "//packages/http", + "//packages/http/testing", + "//packages/platform-browser", + "//packages/platform-server", + "@rxjs", + ], +) + +jasmine_node_test( + name = "test", + bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"], + deps = [ + ":test_lib", + "//packages/_testing_init:node", + ], +) diff --git a/packages/platform-server/test/integration_spec.ts b/packages/platform-server/test/integration_spec.ts index bfabca348c..a545e5925d 100644 --- a/packages/platform-server/test/integration_spec.ts +++ b/packages/platform-server/test/integration_spec.ts @@ -298,7 +298,7 @@ class TransferStoreModule { class EscapedTransferStoreModule { } -(function(){ +(function() { if (getDOM().supportsDOMEvents()) return; // NODE only describe('platform-server integration', () => { diff --git a/packages/platform-webworker-dynamic/BUILD.bazel b/packages/platform-webworker-dynamic/BUILD.bazel new file mode 100644 index 0000000000..8db8972d90 --- /dev/null +++ b/packages/platform-webworker-dynamic/BUILD.bazel @@ -0,0 +1,23 @@ +package(default_visibility = ["//visibility:public"]) + +load("@angular//:index.bzl", "ng_module") +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library") + +ts_library( + name = "platform-webworker-dynamic", + srcs = glob( + [ + "*.ts", + "src/**/*.ts", + ], + ), + module_name = "@angular/platform-webworker-dynamic", + tsconfig = "//packages:tsconfig", + deps = [ + "//packages:types", + "//packages/common", + "//packages/compiler", + "//packages/core", + "//packages/platform-browser-dynamic", + ], +) diff --git a/packages/platform-webworker/BUILD.bazel b/packages/platform-webworker/BUILD.bazel new file mode 100644 index 0000000000..0aa29e4a5c --- /dev/null +++ b/packages/platform-webworker/BUILD.bazel @@ -0,0 +1,23 @@ +package(default_visibility = ["//visibility:public"]) + +load("@angular//:index.bzl", "ng_module") +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library") + +ts_library( + name = "platform-webworker", + srcs = glob( + [ + "*.ts", + "src/**/*.ts", + ], + ), + module_name = "@angular/platform-webworker", + tsconfig = "//packages:tsconfig", + deps = [ + "//packages:types", + "//packages/common", + "//packages/compiler", + "//packages/core", + "//packages/platform-browser", + ], +) diff --git a/packages/platform-webworker/test/BUILD.1.bazel b/packages/platform-webworker/test/BUILD.1.bazel new file mode 100644 index 0000000000..3a3086d679 --- /dev/null +++ b/packages/platform-webworker/test/BUILD.1.bazel @@ -0,0 +1,20 @@ +package(default_visibility = ["//visibility:public"]) + +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library") + +ts_library( + name = "testing", + testonly = 1, + srcs = glob(["**/*.ts"]), + module_name = "@angular/platform-browser-dynamic/testing", + tsconfig = "//packages:tsconfig", + deps = [ + "//packages/compiler", + "//packages/compiler/testing", + "//packages/core", + "//packages/core/testing", + "//packages/platform-browser", + "//packages/platform-browser-dynamic", + "//packages/platform-browser/testing", + ], +) diff --git a/packages/platform-webworker/test/BUILD.bazel b/packages/platform-webworker/test/BUILD.bazel new file mode 100644 index 0000000000..8b6bf8ea74 --- /dev/null +++ b/packages/platform-webworker/test/BUILD.bazel @@ -0,0 +1,41 @@ +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test") + +ts_library( + name = "test_lib", + testonly = 1, + srcs = glob(["**/*.ts"]), + tsconfig = "//packages:tsconfig", + deps = [ + "//packages:types", + "//packages/compiler", + "//packages/core", + "//packages/core/testing", + "//packages/platform-browser", + "//packages/platform-browser-dynamic", + "//packages/platform-browser-dynamic/testing", + "//packages/platform-browser/testing", + "//packages/platform-webworker", + ], +) + +jasmine_node_test( + name = "test", + bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"], + deps = [ + ":test_lib", + "//packages/_testing_init:node", + ], +) + +ts_web_test( + name = "test_web", + bootstrap = [ + "//:angular_bootstrap_scripts", + ], + # do not sort + deps = [ + "//packages/_testing_init:browser", + ":test_lib", + ], +) diff --git a/packages/platform-webworker/test/web_workers/shared/service_message_broker_spec.ts b/packages/platform-webworker/test/web_workers/shared/service_message_broker_spec.ts index e4e19b3bce..03ed2934ce 100644 --- a/packages/platform-webworker/test/web_workers/shared/service_message_broker_spec.ts +++ b/packages/platform-webworker/test/web_workers/shared/service_message_broker_spec.ts @@ -34,9 +34,10 @@ import {createPairedMessageBuses} from './web_worker_test_util'; }); it('should call registered method with correct arguments', inject([Serializer], (serializer: Serializer) => { - const broker = new ServiceMessageBroker(messageBuses.ui, serializer, CHANNEL); + const broker = new (ServiceMessageBroker as any)(messageBuses.ui, serializer, CHANNEL); broker.registerMethod( - TEST_METHOD, [SerializerTypes.PRIMITIVE, SerializerTypes.PRIMITIVE], (arg1, arg2) => { + TEST_METHOD, [SerializerTypes.PRIMITIVE, SerializerTypes.PRIMITIVE], + (arg1: any, arg2: any) => { expect(arg1).toEqual(PASSED_ARG_1); expect(arg2).toEqual(PASSED_ARG_2); }); @@ -47,8 +48,8 @@ import {createPairedMessageBuses} from './web_worker_test_util'; })); it('should return promises to the worker', inject([Serializer], (serializer: Serializer) => { - const broker = new ServiceMessageBroker(messageBuses.ui, serializer, CHANNEL); - broker.registerMethod(TEST_METHOD, [SerializerTypes.PRIMITIVE], (arg1) => { + const broker = new (ServiceMessageBroker as any)(messageBuses.ui, serializer, CHANNEL); + broker.registerMethod(TEST_METHOD, [SerializerTypes.PRIMITIVE], (arg1: any) => { expect(arg1).toEqual(PASSED_ARG_1); return new Promise((res, rej) => { try { diff --git a/packages/platform-webworker/test/web_workers/shared/web_worker_test_util.ts b/packages/platform-webworker/test/web_workers/shared/web_worker_test_util.ts index 34bcf7965f..16abca11fa 100644 --- a/packages/platform-webworker/test/web_workers/shared/web_worker_test_util.ts +++ b/packages/platform-webworker/test/web_workers/shared/web_worker_test_util.ts @@ -130,7 +130,9 @@ export class MockMessageBus extends MessageBus { attachToZone(zone: NgZone) {} } -export class MockMessageBrokerFactory extends ClientMessageBrokerFactory { +export const _ClientMessageBrokerFactory: {new (a: any, b: any): ClientMessageBrokerFactory} = + ClientMessageBrokerFactory; +export class MockMessageBrokerFactory extends _ClientMessageBrokerFactory { constructor(private _messageBroker: ClientMessageBroker) { super(null !, null !); } createMessageBroker(channel: string, runInZone = true) { return this._messageBroker; } } diff --git a/packages/platform-webworker/test/web_workers/worker/platform_location_spec.ts b/packages/platform-webworker/test/web_workers/worker/platform_location_spec.ts index eae82a00b6..9599f0c3dd 100644 --- a/packages/platform-webworker/test/web_workers/worker/platform_location_spec.ts +++ b/packages/platform-webworker/test/web_workers/worker/platform_location_spec.ts @@ -67,18 +67,18 @@ import {SpyMessageBroker} from './spies'; it('should get location on init', () => { const platformLocation = createWebWorkerPlatformLocation(null !); expectBrokerCall(broker, 'getLocation'); - platformLocation.init(); + (platformLocation as any).init(); }); it('should throw if set pathname is called before init finishes', () => { const platformLocation = createWebWorkerPlatformLocation(null !); - platformLocation.init(); + (platformLocation as any).init(); expect(() => platformLocation.pathname = 'TEST').toThrowError(); }); it('should send pathname to render thread', done => { const platformLocation = createWebWorkerPlatformLocation(TEST_LOCATION); - platformLocation.init().then((_) => { + (platformLocation as any).init().then((_: any) => { const PATHNAME = '/test'; expectBrokerCall(broker, 'setPathname', [PATHNAME]); platformLocation.pathname = PATHNAME; diff --git a/packages/platform-webworker/test/web_workers/worker/renderer_v2_integration_spec.ts b/packages/platform-webworker/test/web_workers/worker/renderer_v2_integration_spec.ts index 91db66762a..04fed7095c 100644 --- a/packages/platform-webworker/test/web_workers/worker/renderer_v2_integration_spec.ts +++ b/packages/platform-webworker/test/web_workers/worker/renderer_v2_integration_spec.ts @@ -184,10 +184,10 @@ function createWebWorkerBrokerFactory( const wwMessageBus = messageBuses.worker; // set up the worker side - const wwBrokerFactory = new ClientMessageBrokerFactory(wwMessageBus, wwSerializer); + const wwBrokerFactory = new (ClientMessageBrokerFactory as any)(wwMessageBus, wwSerializer); // set up the ui side - const uiBrokerFactory = new ServiceMessageBrokerFactory(uiMessageBus, uiSerializer); + const uiBrokerFactory = new (ServiceMessageBrokerFactory as any)(uiMessageBus, uiSerializer); const renderer = new MessageBasedRenderer2( uiBrokerFactory, uiMessageBus, uiSerializer, uiRenderStore, domRendererFactory); renderer.start(); diff --git a/packages/router/karma-test-shim.js b/packages/router/karma-test-shim.js index 4450b37d81..61d9c5d0c5 100644 --- a/packages/router/karma-test-shim.js +++ b/packages/router/karma-test-shim.js @@ -12,6 +12,9 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; __karma__.loaded = function() {}; +window.isNode = false; +window.isBrowser = true; + function isJsFile(path) { return path.slice(-3) == '.js'; } diff --git a/packages/router/test/BUILD.bazel b/packages/router/test/BUILD.bazel new file mode 100644 index 0000000000..7bf747d48c --- /dev/null +++ b/packages/router/test/BUILD.bazel @@ -0,0 +1,46 @@ +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test") + +ts_library( + name = "test_lib", + testonly = 1, + srcs = glob(["**/*.ts"]), + tsconfig = "//packages:tsconfig", + deps = [ + "//packages/common", + "//packages/common/testing", + "//packages/core", + "//packages/core/testing", + "//packages/platform-browser", + "//packages/platform-browser-dynamic", + "//packages/platform-browser/testing", + "//packages/router", + "//packages/router/testing", + "@rxjs", + ], +) + +jasmine_node_test( + name = "test", + bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"], + # dissable since tests are running but not yet passing + tags = ["manual"], + deps = [ + ":test_lib", + "//packages/_testing_init:node", + ], +) + +ts_web_test( + name = "test_web", + bootstrap = [ + "//:angular_bootstrap_scripts", + ], + # dissable since tests are running but not yet passing + tags = ["manual"], + # do not sort + deps = [ + "//packages/_testing_init:browser", + ":test_lib", + ], +) diff --git a/packages/router/test/apply_redirects.spec.ts b/packages/router/test/apply_redirects.spec.ts index 82ca451824..185ae8be81 100644 --- a/packages/router/test/apply_redirects.spec.ts +++ b/packages/router/test/apply_redirects.spec.ts @@ -178,7 +178,7 @@ describe('applyRedirects', () => { applyRedirects(testModule.injector, loader, serializer, tree('a/b'), config) .forEach(r => { expectTreeToBe(r, '/a/b'); - expect(config[0]._loadedConfig).toBe(loadedConfig); + expect((config[0] as any)._loadedConfig).toBe(loadedConfig); }); }); @@ -304,7 +304,7 @@ describe('applyRedirects', () => { applyRedirects(testModule.injector, loader, serializer, tree(''), config).forEach(r => { expectTreeToBe(r, 'a'); - expect(config[1]._loadedConfig).toBe(loadedConfig); + expect((config[1] as any)._loadedConfig).toBe(loadedConfig); }); }); @@ -329,7 +329,7 @@ describe('applyRedirects', () => { .subscribe( r => { expectTreeToBe(r, 'a?k2'); - expect(config[0]._loadedConfig).toBe(loadedConfig); + expect((config[0] as any)._loadedConfig).toBe(loadedConfig); }, (e) => { throw 'Should not reach'; }); }); @@ -342,7 +342,7 @@ describe('applyRedirects', () => { const config: Routes = [{path: '**', loadChildren: 'children'}]; applyRedirects(testModule.injector, loader, serializer, tree('xyz'), config) - .forEach(r => { expect(config[0]._loadedConfig).toBe(loadedConfig); }); + .forEach(r => { expect((config[0] as any)._loadedConfig).toBe(loadedConfig); }); }); it('should load the configuration after a local redirect from a wildcard route', () => { @@ -354,7 +354,7 @@ describe('applyRedirects', () => { [{path: 'not-found', loadChildren: 'children'}, {path: '**', redirectTo: 'not-found'}]; applyRedirects(testModule.injector, loader, serializer, tree('xyz'), config) - .forEach(r => { expect(config[0]._loadedConfig).toBe(loadedConfig); }); + .forEach(r => { expect((config[0] as any)._loadedConfig).toBe(loadedConfig); }); }); it('should load the configuration after an absolute redirect from a wildcard route', () => { @@ -366,7 +366,7 @@ describe('applyRedirects', () => { [{path: 'not-found', loadChildren: 'children'}, {path: '**', redirectTo: '/not-found'}]; applyRedirects(testModule.injector, loader, serializer, tree('xyz'), config) - .forEach(r => { expect(config[0]._loadedConfig).toBe(loadedConfig); }); + .forEach(r => { expect((config[0] as any)._loadedConfig).toBe(loadedConfig); }); }); }); diff --git a/packages/router/test/bootstrap.spec.ts b/packages/router/test/bootstrap.spec.ts index 0cc8d86301..1c7789eb53 100644 --- a/packages/router/test/bootstrap.spec.ts +++ b/packages/router/test/bootstrap.spec.ts @@ -214,7 +214,7 @@ describe('bootstrap', () => { const appRef: ApplicationRef = res.injector.get(ApplicationRef); appRef.bootstrap(SecondRootCmp); - expect(router.resetRootComponentType).not.toHaveBeenCalled(); + expect((router as any).resetRootComponentType).not.toHaveBeenCalled(); done(); }); @@ -240,7 +240,7 @@ describe('bootstrap', () => { const appRef: ApplicationRef = res.injector.get(ApplicationRef); appRef.components[0].onDestroy(() => { appRef.bootstrap(SecondRootCmp); - expect(router.resetRootComponentType).toHaveBeenCalled(); + expect((router as any).resetRootComponentType).toHaveBeenCalled(); done(); }); diff --git a/packages/router/test/create_router_state.spec.ts b/packages/router/test/create_router_state.spec.ts index 9c87327aff..2c1f6428a0 100644 --- a/packages/router/test/create_router_state.spec.ts +++ b/packages/router/test/create_router_state.spec.ts @@ -18,8 +18,8 @@ import {TreeNode} from '../src/utils/tree'; describe('create router state', () => { const reuseStrategy = new DefaultRouteReuseStrategy(); - const emptyState = () => - createEmptyState(new UrlTree(new UrlSegmentGroup([], {}), {}, null !), RootComponent); + const emptyState = () => createEmptyState( + new (UrlTree as any)(new UrlSegmentGroup([], {}), {}, null !), RootComponent); it('should work create new state', () => { const state = createRouterState( @@ -34,7 +34,7 @@ describe('create router state', () => { checkActivatedRoute(state.root, RootComponent); - const c = state.children(state.root); + const c = (state as any).children(state.root); checkActivatedRoute(c[0], ComponentA); checkActivatedRoute(c[1], ComponentB, 'left'); checkActivatedRoute(c[2], ComponentC, 'right'); @@ -52,8 +52,8 @@ describe('create router state', () => { const state = createRouterState(reuseStrategy, createState(config, 'a(left:c)'), prevState); expect(prevState.root).toBe(state.root); - const prevC = prevState.children(prevState.root); - const currC = state.children(state.root); + const prevC = (prevState as any).children(prevState.root); + const currC = (state as any).children(state.root); expect(prevC[0]).toBe(currC[0]); expect(prevC[1]).not.toBe(currC[1]); @@ -76,11 +76,11 @@ describe('create router state', () => { createRouterState(reuseStrategy, createState(config, 'a/2;p=22/(b//right:c)'), prevState); expect(prevState.root).toBe(state.root); - const prevP = prevState.firstChild(prevState.root) !; - const currP = state.firstChild(state.root) !; + const prevP = (prevState as any).firstChild(prevState.root) !; + const currP = (state as any).firstChild(state.root) !; expect(prevP).toBe(currP); - const currC = state.children(currP); + const currC = (state as any).children(currP); expect(currP._futureSnapshot.params).toEqual({id: '2', p: '22'}); expect(currP._futureSnapshot.paramMap.get('id')).toEqual('2'); @@ -91,7 +91,7 @@ describe('create router state', () => { }); function advanceState(state: RouterState): void { - advanceNode(state._root); + advanceNode((state as any)._root); } function advanceNode(node: TreeNode): void { diff --git a/packages/router/test/create_url_tree.spec.ts b/packages/router/test/create_url_tree.spec.ts index 726faff2bd..0208292667 100644 --- a/packages/router/test/create_url_tree.spec.ts +++ b/packages/router/test/create_url_tree.spec.ts @@ -243,10 +243,10 @@ describe('createUrlTree', () => { }); function createRoot(tree: UrlTree, commands: any[], queryParams?: Params, fragment?: string) { - const s = new ActivatedRouteSnapshot( + const s = new (ActivatedRouteSnapshot as any)( [], {}, {}, '', {}, PRIMARY_OUTLET, 'someComponent', null, tree.root, -1, null); - const a = new ActivatedRoute( + const a = new (ActivatedRoute as any)( new BehaviorSubject(null !), new BehaviorSubject(null !), new BehaviorSubject(null !), new BehaviorSubject(null !), new BehaviorSubject(null !), PRIMARY_OUTLET, 'someComponent', s); advanceActivatedRoute(a); @@ -259,10 +259,10 @@ function create( if (!segment) { expect(segment).toBeDefined(); } - const s = new ActivatedRouteSnapshot( + const s = new (ActivatedRouteSnapshot as any)( [], {}, {}, '', {}, PRIMARY_OUTLET, 'someComponent', null, segment, startIndex, null); - const a = new ActivatedRoute( + const a = new (ActivatedRoute as any)( new BehaviorSubject(null !), new BehaviorSubject(null !), new BehaviorSubject(null !), new BehaviorSubject(null !), new BehaviorSubject(null !), PRIMARY_OUTLET, 'someComponent', s); advanceActivatedRoute(a); diff --git a/packages/router/test/helpers.ts b/packages/router/test/helpers.ts index bce80a60c7..674a1db8d3 100644 --- a/packages/router/test/helpers.ts +++ b/packages/router/test/helpers.ts @@ -42,7 +42,7 @@ export declare type ARSArgs = { }; export function createActivatedRouteSnapshot(args: ARSArgs): ActivatedRouteSnapshot { - return new ActivatedRouteSnapshot( + return new (ActivatedRouteSnapshot as any)( args.url || [], args.params || {}, args.queryParams || null, args.fragment || null, args.data || null, args.outlet || null, args.component, args.routeConfig || {}, args.urlSegment || null, diff --git a/packages/router/test/integration.spec.ts b/packages/router/test/integration.spec.ts index 0f2c0eabbd..8df1c43ef8 100644 --- a/packages/router/test/integration.spec.ts +++ b/packages/router/test/integration.spec.ts @@ -7,12 +7,12 @@ */ import {CommonModule, Location} from '@angular/common'; +import {SpyLocation} from '@angular/common/testing'; import {ChangeDetectionStrategy, Component, Injectable, NgModule, NgModuleFactoryLoader, NgModuleRef} from '@angular/core'; import {ComponentFixture, TestBed, fakeAsync, inject, tick} from '@angular/core/testing'; import {By} from '@angular/platform-browser/src/dom/debug/by'; import {expect} from '@angular/platform-browser/testing/src/matchers'; import {ActivatedRoute, ActivatedRouteSnapshot, ActivationEnd, ActivationStart, CanActivate, CanDeactivate, ChildActivationEnd, ChildActivationStart, DetachedRouteHandle, Event, GuardsCheckEnd, GuardsCheckStart, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, PRIMARY_OUTLET, ParamMap, Params, PreloadAllModules, PreloadingStrategy, Resolve, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, RouteReuseStrategy, Router, RouterEvent, RouterModule, RouterPreloader, RouterStateSnapshot, RoutesRecognized, RunGuardsAndResolvers, UrlHandlingStrategy, UrlSegmentGroup, UrlTree} from '@angular/router'; -import {SpyLocation} from 'common/testing'; import {Observable} from 'rxjs/Observable'; import {Observer} from 'rxjs/Observer'; import {of } from 'rxjs/observable/of'; @@ -3527,7 +3527,7 @@ describe('Integration', () => { router.navigateByUrl('/blank'); advance(fixture); - const config = router.config; + const config = router.config as any; const firstConfig = config[1]._loadedConfig !; expect(firstConfig).toBeDefined(); @@ -3553,7 +3553,7 @@ describe('Integration', () => { children[PRIMARY_OUTLET] = oldRoot.children[PRIMARY_OUTLET]; } const root = new UrlSegmentGroup(oldRoot.segments, children); - return new UrlTree(root, url.queryParams, url.fragment); + return new (UrlTree as any)(root, url.queryParams, url.fragment); } merge(newUrlPart: UrlTree, wholeUrl: UrlTree): UrlTree { @@ -3571,7 +3571,7 @@ describe('Integration', () => { v.parent = this; }); const root = new UrlSegmentGroup(oldRoot.segments, children); - return new UrlTree(root, newUrlPart.queryParams, newUrlPart.fragment); + return new (UrlTree as any)(root, newUrlPart.queryParams, newUrlPart.fragment); } } @@ -3992,7 +3992,7 @@ class ComponentRecordingRoutePathAndUrl { private url: any; constructor(router: Router, route: ActivatedRoute) { - this.path = router.routerState.pathFromRoot(route); + this.path = (router.routerState as any).pathFromRoot(route); this.url = router.url.toString(); } } diff --git a/packages/router/test/recognize.spec.ts b/packages/router/test/recognize.spec.ts index edab240b93..f224f0e0ab 100644 --- a/packages/router/test/recognize.spec.ts +++ b/packages/router/test/recognize.spec.ts @@ -8,13 +8,13 @@ import {Routes} from '../src/config'; import {recognize} from '../src/recognize'; -import {ActivatedRouteSnapshot, ParamsInheritanceStrategy, RouterStateSnapshot, inheritedParamsDataResolve} from '../src/router_state'; +import {ActivatedRouteSnapshot, RouterStateSnapshot} from '../src/router_state'; import {PRIMARY_OUTLET, Params} from '../src/shared'; import {DefaultUrlSerializer, UrlTree} from '../src/url_tree'; describe('recognize', () => { it('should work', () => { - checkRecognize([{path: 'a', component: ComponentA}], 'a', (s: RouterStateSnapshot) => { + checkRecognize([{path: 'a', component: ComponentA}], 'a', (s: any) => { checkActivatedRoute(s.root, '', {}, RootComponent); checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA); }); @@ -23,7 +23,7 @@ describe('recognize', () => { it('should freeze params object', () => { checkRecognize([{path: 'a/:id', component: ComponentA}], 'a/10', (s: RouterStateSnapshot) => { checkActivatedRoute(s.root, '', {}, RootComponent); - const child = s.firstChild(s.root) !; + const child = (s as any).firstChild(s.root) !; expect(Object.isFrozen(child.params)).toBeTruthy(); }); }); @@ -35,7 +35,7 @@ describe('recognize', () => { {path: 'c', component: ComponentC, outlet: 'right'} ], 'a(left:b//right:c)', (s: RouterStateSnapshot) => { - const c = s.children(s.root); + const c = (s as any).children(s.root); checkActivatedRoute(c[0], 'a', {}, ComponentA); checkActivatedRoute(c[1], 'b', {}, ComponentB, 'left'); checkActivatedRoute(c[2], 'c', {}, ComponentC, 'right'); @@ -51,18 +51,18 @@ describe('recognize', () => { {path: 'c', component: ComponentC, outlet: 'right'} ], url, 'a(left:b//right:c)') - .subscribe((s) => { + .subscribe((s: any) => { expect(s.root._urlSegment).toBe(url.root); expect(s.root._lastPathIndex).toBe(-1); - const c = s.children(s.root); - expect(c[0]._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]); + const c = (s as any).children(s.root); + expect(c[0]._urlSegment).toBe((url.root as any).children[PRIMARY_OUTLET]); expect(c[0]._lastPathIndex).toBe(0); - expect(c[1]._urlSegment).toBe(url.root.children['left']); + expect(c[1]._urlSegment).toBe((url.root as any).children['left']); expect(c[1]._lastPathIndex).toBe(0); - expect(c[2]._urlSegment).toBe(url.root.children['right']); + expect(c[2]._urlSegment).toBe((url.root as any).children['right']); expect(c[2]._lastPathIndex).toBe(0); }); }); @@ -76,15 +76,15 @@ describe('recognize', () => { ], url, 'a/b/c') .subscribe((s: RouterStateSnapshot) => { - expect(s.root._urlSegment).toBe(url.root); - expect(s.root._lastPathIndex).toBe(-1); + expect((s.root as any)._urlSegment).toBe(url.root); + expect((s.root as any)._lastPathIndex).toBe(-1); - const compA = s.firstChild(s.root) !; - expect(compA._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]); + const compA = (s as any).firstChild(s.root) !; + expect(compA._urlSegment).toBe((url.root as any).children[PRIMARY_OUTLET]); expect(compA._lastPathIndex).toBe(1); - const compC = s.firstChild(compA) !; - expect(compC._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]); + const compC = (s as any).firstChild(compA) !; + expect(compC._urlSegment).toBe((url.root as any).children[PRIMARY_OUTLET]); expect(compC._lastPathIndex).toBe(2); }); }); @@ -97,16 +97,16 @@ describe('recognize', () => { {path: 'a', component: ComponentA, children: [{path: '**', component: ComponentB}]}, ], url, 'a/b/c') - .subscribe((s: RouterStateSnapshot) => { + .subscribe((s: any) => { expect(s.root._urlSegment).toBe(url.root); expect(s.root._lastPathIndex).toBe(-1); - const compA = s.firstChild(s.root) !; - expect(compA._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]); + const compA = (s as any).firstChild(s.root) !; + expect(compA._urlSegment).toBe((url as any).root.children[PRIMARY_OUTLET]); expect(compA._lastPathIndex).toBe(0); - const compC = s.firstChild(compA) !; - expect(compC._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]); + const compC = (s as any).firstChild(compA) !; + expect(compC._urlSegment).toBe((url as any).root.children[PRIMARY_OUTLET]); expect(compC._lastPathIndex).toBe(2); }); }); @@ -119,16 +119,18 @@ describe('recognize', () => { ], 'a/paramA', (s: RouterStateSnapshot) => { checkActivatedRoute(s.root, '', {}, RootComponent); - checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA); + checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA); checkActivatedRoute( - s.firstChild(s.firstChild(s.root)) !, 'paramA', {id: 'paramA'}, ComponentB); + (s as any).firstChild((s as any).firstChild(s.root)) !, 'paramA', {id: 'paramA'}, + ComponentB); }); checkRecognize( [{path: 'a', component: ComponentA}, {path: 'a/:id', component: ComponentC}], 'a/paramA', (s: RouterStateSnapshot) => { checkActivatedRoute(s.root, '', {}, RootComponent); - checkActivatedRoute(s.firstChild(s.root) !, 'a/paramA', {id: 'paramA'}, ComponentC); + checkActivatedRoute( + (s as any).firstChild(s.root) !, 'a/paramA', {id: 'paramA'}, ComponentC); }); }); @@ -139,7 +141,7 @@ describe('recognize', () => { {path: 'b', component: ComponentC, outlet: 'right'} ], 'a(right:b)', (s: RouterStateSnapshot) => { - const c = s.children(s.root); + const c = (s as any).children(s.root); checkActivatedRoute(c[0], 'a', {}, ComponentA); checkActivatedRoute(c[1], 'b', {}, ComponentC, 'right'); }); @@ -158,7 +160,7 @@ describe('recognize', () => { }, ], 'a/(b//left:c)', (s: RouterStateSnapshot) => { - const c = s.children(s.firstChild(s.root)); + const c = (s as any).children((s as any).firstChild(s.root)); checkActivatedRoute(c[0], 'b', {}, ComponentB, PRIMARY_OUTLET); checkActivatedRoute(c[1], 'c', {}, ComponentC, 'left'); }); @@ -171,7 +173,7 @@ describe('recognize', () => { {path: 'b', component: ComponentB, outlet: 'b'} ], 'a(c:c//b:b)', (s: RouterStateSnapshot) => { - const c = s.children(s.root); + const c = (s as any).children(s.root); checkActivatedRoute(c[0], 'a', {}, ComponentA); checkActivatedRoute(c[1], 'b', {}, ComponentB, 'b'); checkActivatedRoute(c[2], 'c', {}, ComponentC, 'c'); @@ -185,9 +187,10 @@ describe('recognize', () => { {path: 'c', component: ComponentC, outlet: 'left'} ], 'a;a1=11;a2=22/b;b1=111;b2=222(left:c;c1=1111;c2=2222)', (s: RouterStateSnapshot) => { - const c = s.children(s.root); + const c = (s as any).children(s.root); checkActivatedRoute(c[0], 'a', {a1: '11', a2: '22'}, ComponentA); - checkActivatedRoute(s.firstChild(c[0]) !, 'b', {b1: '111', b2: '222'}, ComponentB); + checkActivatedRoute( + (s as any).firstChild(c[0]) !, 'b', {b1: '111', b2: '222'}, ComponentB); checkActivatedRoute(c[1], 'c', {c1: '1111', c2: '2222'}, ComponentC, 'left'); }); }); @@ -196,7 +199,7 @@ describe('recognize', () => { it('should set static data', () => { checkRecognize( [{path: 'a', data: {one: 1}, component: ComponentA}], 'a', (s: RouterStateSnapshot) => { - const r: ActivatedRouteSnapshot = s.firstChild(s.root) !; + const r: ActivatedRouteSnapshot = (s as any).firstChild(s.root) !; expect(r.data).toEqual({one: 1}); }); }); @@ -209,7 +212,8 @@ describe('recognize', () => { children: [{path: 'b', data: {two: 2}, component: ComponentB}] }], 'a/b', (s: RouterStateSnapshot) => { - const r: ActivatedRouteSnapshot = s.firstChild(s.firstChild(s.root)) !; + const r: ActivatedRouteSnapshot = + (s as any).firstChild((s as any).firstChild(s.root)) !; expect(r.data).toEqual({one: 1, two: 2}); }); }); @@ -222,7 +226,7 @@ describe('recognize', () => { data: {one: 1}, children: [{path: 'b', data: {two: 2}, component: ComponentB}] }], - 'a/b', (s: RouterStateSnapshot) => { + 'a/b', (s: any /* RouterStateSnapshot */) => { const r: ActivatedRouteSnapshot = s.firstChild(s.firstChild(s.root)) !; expect(r.data).toEqual({two: 2}); }); @@ -236,7 +240,7 @@ describe('recognize', () => { data: {one: 1}, children: [{path: 'b', data: {two: 2}, component: ComponentB}] }], - 'a/b', (s: RouterStateSnapshot) => { + 'a/b', (s: any /* RouterStateSnapshot */) => { const r: ActivatedRouteSnapshot = s.firstChild(s.firstChild(s.root)) !; expect(r.data).toEqual({one: 1, two: 2}); }, 'always'); @@ -244,9 +248,8 @@ describe('recognize', () => { it('should set resolved data', () => { checkRecognize( - [{path: 'a', resolve: {one: 'some-token'}, component: ComponentA}], 'a', - (s: RouterStateSnapshot) => { - const r: ActivatedRouteSnapshot = s.firstChild(s.root) !; + [{path: 'a', resolve: {one: 'some-token'}, component: ComponentA}], 'a', (s: any) => { + const r: any = s.firstChild(s.root) !; expect(r._resolve).toEqual({one: 'some-token'}); }); }); @@ -256,7 +259,7 @@ describe('recognize', () => { describe('root', () => { it('should work', () => { checkRecognize([{path: '', component: ComponentA}], '', (s: RouterStateSnapshot) => { - checkActivatedRoute(s.firstChild(s.root) !, '', {}, ComponentA); + checkActivatedRoute((s as any).firstChild(s.root) !, '', {}, ComponentA); }); }); @@ -264,7 +267,7 @@ describe('recognize', () => { checkRecognize( [{path: '', pathMatch: 'full', component: ComponentA}], '', (s: RouterStateSnapshot) => { - checkActivatedRoute(s.firstChild(s.root) !, '', {}, ComponentA); + checkActivatedRoute((s as any).firstChild(s.root) !, '', {}, ComponentA); }); }); @@ -272,18 +275,19 @@ describe('recognize', () => { checkRecognize( [{path: '', component: ComponentA, children: [{path: '', component: ComponentB}]}], '', (s: RouterStateSnapshot) => { - checkActivatedRoute(s.firstChild(s.root) !, '', {}, ComponentA); - checkActivatedRoute(s.firstChild(s.firstChild(s.root)) !, '', {}, ComponentB); + checkActivatedRoute((s as any).firstChild(s.root) !, '', {}, ComponentA); + checkActivatedRoute( + (s as any).firstChild((s as any).firstChild(s.root)) !, '', {}, ComponentB); }); }); it('should set url segment and index properly', () => { - const url = tree(''); + const url = tree('') as any; recognize( RootComponent, [{path: '', component: ComponentA, children: [{path: '', component: ComponentB}]}], url, '') - .forEach((s: RouterStateSnapshot) => { + .forEach((s: any) => { expect(s.root._urlSegment).toBe(url.root); expect(s.root._lastPathIndex).toBe(-1); @@ -307,10 +311,13 @@ describe('recognize', () => { ] }], '/a;p=1', (s: RouterStateSnapshot) => { - checkActivatedRoute(s.firstChild(s.root) !, 'a', {p: '1'}, ComponentA); - checkActivatedRoute(s.firstChild(s.firstChild(s.root) !) !, '', {p: '1'}, ComponentB); + checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {p: '1'}, ComponentA); checkActivatedRoute( - s.firstChild(s.firstChild(s.firstChild(s.root) !) !) !, '', {p: '1'}, ComponentC); + (s as any).firstChild((s as any).firstChild(s.root) !) !, '', {p: '1'}, + ComponentB); + checkActivatedRoute( + (s as any).firstChild((s as any).firstChild((s as any).firstChild(s.root) !) !) !, + '', {p: '1'}, ComponentC); }); }); }); @@ -327,9 +334,9 @@ describe('recognize', () => { ] }], 'a/b', (s: RouterStateSnapshot) => { - checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA); + checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA); - const c = s.children(s.firstChild(s.root) !); + const c = (s as any).children((s as any).firstChild(s.root) !); checkActivatedRoute(c[0], 'b', {}, ComponentB); checkActivatedRoute(c[1], '', {}, ComponentC, 'aux'); }); @@ -358,13 +365,13 @@ describe('recognize', () => { checkRecognize(config, 'parent/b', (s: RouterStateSnapshot) => { checkActivatedRoute(s.root, '', {}, RootComponent); - checkActivatedRoute(s.firstChild(s.root) !, 'parent', {}, undefined !); + checkActivatedRoute((s as any).firstChild(s.root) !, 'parent', {}, undefined !); - const cc = s.children(s.firstChild(s.root) !); + const cc = (s as any).children((s as any).firstChild(s.root) !); checkActivatedRoute(cc[0], '', {}, ComponentA); checkActivatedRoute(cc[1], '', {}, ComponentD, 'secondary'); - checkActivatedRoute(s.firstChild(cc[0]) !, 'b', {}, ComponentB); + checkActivatedRoute((s as any).firstChild(cc[0]) !, 'b', {}, ComponentB); }); }); @@ -379,16 +386,16 @@ describe('recognize', () => { ] }], 'a/b', (s: RouterStateSnapshot) => { - checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA); + checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA); - const c = s.children(s.firstChild(s.root) !); + const c = (s as any).children((s as any).firstChild(s.root) !); expect(c.length).toEqual(1); checkActivatedRoute(c[0], 'b', {}, ComponentB); }); }); it('should set url segment and index properly', () => { - const url = tree('a/b'); + const url = tree('a/b') as any; recognize( RootComponent, [{ path: 'a', @@ -399,7 +406,7 @@ describe('recognize', () => { ] }], url, 'a/b') - .forEach((s: RouterStateSnapshot) => { + .forEach((s: any) => { expect(s.root._urlSegment).toBe(url.root); expect(s.root._lastPathIndex).toBe(-1); @@ -418,7 +425,7 @@ describe('recognize', () => { }); it('should set url segment and index properly when nested empty-path segments', () => { - const url = tree('a'); + const url = tree('a') as any; recognize( RootComponent, [{ path: 'a', @@ -427,7 +434,7 @@ describe('recognize', () => { ] }], url, 'a') - .forEach((s: RouterStateSnapshot) => { + .forEach((s: any) => { expect(s.root._urlSegment).toBe(url.root); expect(s.root._lastPathIndex).toBe(-1); @@ -455,19 +462,19 @@ describe('recognize', () => { ] }], url, '') - .forEach((s: RouterStateSnapshot) => { + .forEach((s: any) => { expect(s.root._urlSegment).toBe(url.root); expect(s.root._lastPathIndex).toBe(-1); - const a = s.firstChild(s.root) !; + const a = (s as any).firstChild(s.root) !; expect(a._urlSegment).toBe(url.root); expect(a._lastPathIndex).toBe(-1); - const b = s.firstChild(a) !; + const b = (s as any).firstChild(a) !; expect(b._urlSegment).toBe(url.root); expect(b._lastPathIndex).toBe(-1); - const c = s.firstChild(b) !; + const c = (s as any).firstChild(b) !; expect(c._urlSegment).toBe(url.root); expect(c._lastPathIndex).toBe(-1); }); @@ -486,9 +493,9 @@ describe('recognize', () => { ] }], 'a', (s: RouterStateSnapshot) => { - checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA); + checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA); - const c = s.children(s.firstChild(s.root) !); + const c = (s as any).children((s as any).firstChild(s.root) !); checkActivatedRoute(c[0], '', {}, ComponentB); checkActivatedRoute(c[1], '', {}, ComponentC, 'aux'); }); @@ -505,9 +512,9 @@ describe('recognize', () => { ] }], 'a', (s: RouterStateSnapshot) => { - checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA); + checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA); - const c = s.children(s.firstChild(s.root) !); + const c = (s as any).children((s as any).firstChild(s.root) !); checkActivatedRoute(c[0], '', {}, ComponentB); checkActivatedRoute(c[1], '', {}, ComponentC, 'aux'); }); @@ -524,9 +531,9 @@ describe('recognize', () => { ] }], 'a/(aux:c)', (s: RouterStateSnapshot) => { - checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA); + checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA); - const c = s.children(s.firstChild(s.root) !); + const c = (s as any).children((s as any).firstChild(s.root) !); checkActivatedRoute(c[0], '', {}, ComponentB); checkActivatedRoute(c[1], 'c', {}, ComponentC, 'aux'); }); @@ -541,7 +548,7 @@ describe('recognize', () => { '(aux:c)', (s: RouterStateSnapshot) => { checkActivatedRoute(s.root, '', {}, RootComponent); - const children = s.children(s.root); + const children = (s as any).children(s.root); expect(children.length).toEqual(2); checkActivatedRoute(children[0], '', {}, ComponentA); checkActivatedRoute(children[1], 'c', {}, ComponentC, 'aux'); @@ -566,13 +573,13 @@ describe('recognize', () => { ] }], 'a/(d//aux:e)', (s: RouterStateSnapshot) => { - checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA); + checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA); - const c = s.children(s.firstChild(s.root) !); + const c = (s as any).children((s as any).firstChild(s.root) !); checkActivatedRoute(c[0], '', {}, ComponentB); - checkActivatedRoute(s.firstChild(c[0]) !, 'd', {}, ComponentD); + checkActivatedRoute((s as any).firstChild(c[0]) !, 'd', {}, ComponentD); checkActivatedRoute(c[1], '', {}, ComponentC, 'aux'); - checkActivatedRoute(s.firstChild(c[1]) !, 'e', {}, ComponentE); + checkActivatedRoute((s as any).firstChild(c[1]) !, 'e', {}, ComponentE); }); }); }); @@ -582,7 +589,7 @@ describe('recognize', () => { it('should support simple wildcards', () => { checkRecognize( [{path: '**', component: ComponentA}], 'a/b/c/d;a1=11', (s: RouterStateSnapshot) => { - checkActivatedRoute(s.firstChild(s.root) !, 'a/b/c/d', {a1: '11'}, ComponentA); + checkActivatedRoute((s as any).firstChild(s.root) !, 'a/b/c/d', {a1: '11'}, ComponentA); }); }); }); @@ -598,10 +605,10 @@ describe('recognize', () => { ] }], 'p/11;pp=22/(a;pa=33//aux:b;pb=44)', (s: RouterStateSnapshot) => { - const p = s.firstChild(s.root) !; + const p = (s as any).firstChild(s.root) !; checkActivatedRoute(p, 'p/11', {id: '11', pp: '22'}, undefined !); - const c = s.children(p); + const c = (s as any).children(p); checkActivatedRoute(c[0], 'a', {id: '11', pp: '22', pa: '33'}, ComponentA); checkActivatedRoute(c[1], 'b', {id: '11', pp: '22', pb: '44'}, ComponentB, 'aux'); }); @@ -621,16 +628,16 @@ describe('recognize', () => { }] }], 'p/11/a/victor/b/c', (s: RouterStateSnapshot) => { - const p = s.firstChild(s.root) !; + const p = (s as any).firstChild(s.root) !; checkActivatedRoute(p, 'p/11', {id: '11'}, undefined !); - const a = s.firstChild(p) !; + const a = (s as any).firstChild(p) !; checkActivatedRoute(a, 'a/victor', {id: '11', name: 'victor'}, undefined !); - const b = s.firstChild(a) !; + const b = (s as any).firstChild(a) !; checkActivatedRoute(b, 'b', {id: '11', name: 'victor'}, ComponentB); - const c = s.firstChild(b) !; + const c = (s as any).firstChild(b) !; checkActivatedRoute(c, 'c', {}, ComponentC); }); }); @@ -648,7 +655,7 @@ describe('recognize', () => { }] }] }], - 'p/11/a/victor/b/c', (s: RouterStateSnapshot) => { + 'p/11/a/victor/b/c', (s: any /* RouterStateSnapshot */) => { const c = s.firstChild(s.firstChild(s.firstChild(s.firstChild(s.root) !) !) !) !; checkActivatedRoute(c, 'c', {id: '11', name: 'victor'}, ComponentC); }, 'always'); @@ -660,7 +667,7 @@ describe('recognize', () => { checkRecognize( [{path: 'a', component: ComponentA, children: [{path: 'b', component: ComponentB}]}], '/a', (s: RouterStateSnapshot) => { - const a = s.firstChild(s.root); + const a = (s as any).firstChild(s.root); checkActivatedRoute(a !, 'a', {}, ComponentA); }); }); @@ -676,9 +683,9 @@ describe('recognize', () => { ] }], '/a', (s: RouterStateSnapshot) => { - const a = s.firstChild(s.root) !; + const a = (s as any).firstChild(s.root) !; checkActivatedRoute(a, 'a', {}, ComponentA); - checkActivatedRoute(a.children[0], '', {}, ComponentC, 'aux'); + checkActivatedRoute((a as any).children[0], '', {}, ComponentC, 'aux'); }); }); }); @@ -700,9 +707,9 @@ describe('recognize', () => { children: [{path: 'b', component: ComponentB}] }] as any, '/a/1;p=99/b', (s: RouterStateSnapshot) => { - const a = s.root.firstChild !; + const a = (s as any).root.firstChild !; checkActivatedRoute(a, 'a/1', {id: '1', p: '99'}, ComponentA); - checkActivatedRoute(a.firstChild !, 'b', {}, ComponentB); + checkActivatedRoute((a as any).firstChild !, 'b', {}, ComponentB); }); }); @@ -710,7 +717,7 @@ describe('recognize', () => { const matcher = (s: any, g: any, r: any) => s.length === 0 ? ({consumed: s}) : null; checkRecognize([{matcher, component: ComponentA}] as any, '', (s: RouterStateSnapshot) => { - const a = s.root.firstChild !; + const a = (s as any).root.firstChild !; checkActivatedRoute(a, '', {}, ComponentA); }); }); @@ -721,7 +728,7 @@ describe('recognize', () => { checkRecognize( [{path: 'a', component: ComponentA, children: [{matcher, component: ComponentB}]}] as any, 'a', (s: RouterStateSnapshot) => { - const a = s.root.firstChild !; + const a = (s as any).root.firstChild !; checkActivatedRoute(a, 'a', {}, ComponentA); }); }); @@ -771,7 +778,7 @@ describe('recognize', () => { function checkRecognize( config: Routes, url: string, callback: any, - paramsInheritanceStrategy?: ParamsInheritanceStrategy): void { + paramsInheritanceStrategy?: 'emptyOnly' | 'always'): void { recognize(RootComponent, config, tree(url), url, paramsInheritanceStrategy) .subscribe(callback, e => { throw e; }); } diff --git a/packages/router/test/router.spec.ts b/packages/router/test/router.spec.ts index 2a3ed2ea2a..c9dd46045b 100644 --- a/packages/router/test/router.spec.ts +++ b/packages/router/test/router.spec.ts @@ -31,7 +31,7 @@ describe('Router', () => { const r: Router = TestBed.get(Router); const root = r.routerState.root; - r.resetRootComponentType(NewRootComponent); + (r as any).resetRootComponentType(NewRootComponent); expect(r.routerState.root).toBe(root); }); @@ -103,7 +103,7 @@ describe('Router', () => { let result = false; const childSnapshot = createActivatedRouteSnapshot({component: 'child', routeConfig: {path: 'child'}}); - const futureState = new RouterStateSnapshot( + const futureState = new (RouterStateSnapshot as any)( 'url', new TreeNode(empty.root, [new TreeNode(childSnapshot, [])])); const p = new PreActivation(futureState, empty, TestBed, (evt) => { events.push(evt); }); @@ -132,7 +132,7 @@ describe('Router', () => { {component: 'grandchild', routeConfig: {path: 'grandchild'}}); const greatGrandchildSnapshot = createActivatedRouteSnapshot( {component: 'great-grandchild', routeConfig: {path: 'great-grandchild'}}); - const futureState = new RouterStateSnapshot( + const futureState = new (RouterStateSnapshot as any)( 'url', new TreeNode( empty.root, [new TreeNode(childSnapshot, [ @@ -164,9 +164,9 @@ describe('Router', () => { createActivatedRouteSnapshot({component: 'child', routeConfig: {path: 'child'}}); const grandchildSnapshot = createActivatedRouteSnapshot( {component: 'grandchild', routeConfig: {path: 'grandchild'}}); - const currentState = new RouterStateSnapshot( + const currentState = new (RouterStateSnapshot as any)( 'url', new TreeNode(empty.root, [new TreeNode(childSnapshot, [])])); - const futureState = new RouterStateSnapshot( + const futureState = new (RouterStateSnapshot as any)( 'url', new TreeNode( empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])])); @@ -203,11 +203,11 @@ describe('Router', () => { {component: 'greatgrandchild', routeConfig: {path: 'greatgrandchild'}}); const greatGreatGrandchildSnapshot = createActivatedRouteSnapshot( {component: 'great-greatgrandchild', routeConfig: {path: 'great-greatgrandchild'}}); - const currentState = new RouterStateSnapshot( + const currentState = new (RouterStateSnapshot as any)( 'url', new TreeNode( empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])])); - const futureState = new RouterStateSnapshot( + const futureState = new (RouterStateSnapshot as any)( 'url', new TreeNode( empty.root, @@ -252,7 +252,7 @@ describe('Router', () => { const grandchildSnapshot = createActivatedRouteSnapshot( {component: 'grandchild', routeConfig: {canActivate: [CA_GRANDCHILD]}}); - const futureState = new RouterStateSnapshot( + const futureState = new (RouterStateSnapshot as any)( 'url', new TreeNode( empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])])); @@ -279,7 +279,7 @@ describe('Router', () => { const grandchildSnapshot = createActivatedRouteSnapshot( {component: 'grandchild', routeConfig: {canActivate: [CA_GRANDCHILD]}}); - const futureState = new RouterStateSnapshot( + const futureState = new (RouterStateSnapshot as any)( 'url', new TreeNode( empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])])); @@ -306,7 +306,7 @@ describe('Router', () => { const grandchildSnapshot = createActivatedRouteSnapshot( {component: 'grandchild', routeConfig: {canActivate: [CA_GRANDCHILD]}}); - const futureState = new RouterStateSnapshot( + const futureState = new (RouterStateSnapshot as any)( 'url', new TreeNode( empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])])); @@ -337,10 +337,10 @@ describe('Router', () => { const grandchildSnapshot = createActivatedRouteSnapshot( {component: 'grandchild', routeConfig: {canActivate: [CA_GRANDCHILD]}}); - const currentState = new RouterStateSnapshot( + const currentState = new (RouterStateSnapshot as any)( 'prev', new TreeNode(empty.root, [new TreeNode(prevSnapshot, [])])); - const futureState = new RouterStateSnapshot( + const futureState = new (RouterStateSnapshot as any)( 'url', new TreeNode( empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])])); @@ -368,9 +368,9 @@ describe('Router', () => { const grandchildSnapshot = createActivatedRouteSnapshot( {component: 'grandchild', routeConfig: {canActivate: [CA_GRANDCHILD]}}); - const currentState = new RouterStateSnapshot( + const currentState = new (RouterStateSnapshot as any)( 'prev', new TreeNode(empty.root, [new TreeNode(prevSnapshot, [])])); - const futureState = new RouterStateSnapshot( + const futureState = new (RouterStateSnapshot as any)( 'url', new TreeNode( empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])])); @@ -400,12 +400,12 @@ describe('Router', () => { const grandchildSnapshot = createActivatedRouteSnapshot( {component: 'grandchild', routeConfig: {canActivate: [CA_GRANDCHILD]}}); - const currentState = new RouterStateSnapshot( + const currentState = new (RouterStateSnapshot as any)( 'prev', new TreeNode(empty.root, [ new TreeNode(prevChildSnapshot, [new TreeNode(prevGrandchildSnapshot, [])]) ])); - const futureState = new RouterStateSnapshot( + const futureState = new (RouterStateSnapshot as any)( 'url', new TreeNode( empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])])); @@ -435,7 +435,8 @@ describe('Router', () => { */ const r = {data: 'resolver'}; const n = createActivatedRouteSnapshot({component: 'a', resolve: r}); - const s = new RouterStateSnapshot('url', new TreeNode(empty.root, [new TreeNode(n, [])])); + const s = new (RouterStateSnapshot as any)( + 'url', new TreeNode(empty.root, [new TreeNode(n, [])])); checkResolveData(s, empty, inj, () => { expect(s.root.firstChild !.data).toEqual({data: 'resolver_value'}); @@ -456,7 +457,7 @@ describe('Router', () => { const parent = createActivatedRouteSnapshot({component: null !, resolve: parentResolve}); const child = createActivatedRouteSnapshot({component: 'b', resolve: childResolve}); - const s = new RouterStateSnapshot( + const s = new (RouterStateSnapshot as any)( 'url', new TreeNode(empty.root, [new TreeNode(parent, [new TreeNode(child, [])])])); const inj = {get: (token: any) => () => Promise.resolve(`${token}_value`)}; @@ -478,12 +479,13 @@ describe('Router', () => { const r2 = {data: 'resolver2'}; const n1 = createActivatedRouteSnapshot({component: 'a', resolve: r1}); - const s1 = new RouterStateSnapshot('url', new TreeNode(empty.root, [new TreeNode(n1, [])])); + const s1 = new (RouterStateSnapshot as any)( + 'url', new TreeNode(empty.root, [new TreeNode(n1, [])])); checkResolveData(s1, empty, inj, () => {}); const n21 = createActivatedRouteSnapshot({component: 'a', resolve: r1}); const n22 = createActivatedRouteSnapshot({component: 'b', resolve: r2}); - const s2 = new RouterStateSnapshot( + const s2 = new (RouterStateSnapshot as any)( 'url', new TreeNode(empty.root, [new TreeNode(n21, [new TreeNode(n22, [])])])); checkResolveData(s2, s1, inj, () => { expect(s2.root.firstChild !.data).toEqual({data: 'resolver1_value'}); diff --git a/packages/router/test/router_preloader.spec.ts b/packages/router/test/router_preloader.spec.ts index 3e12280f3a..7e63bd62ab 100644 --- a/packages/router/test/router_preloader.spec.ts +++ b/packages/router/test/router_preloader.spec.ts @@ -46,7 +46,7 @@ describe('RouterPreloader', () => { tick(); const c = router.config; - expect(c[0]._loadedConfig).not.toBeDefined(); + expect((c[0] as any)._loadedConfig).not.toBeDefined(); }))); }); @@ -97,12 +97,13 @@ describe('RouterPreloader', () => { const c = router.config; expect(c[0].loadChildren).toEqual('expected'); - const loadedConfig: LoadedRouterConfig = c[0]._loadedConfig !; + const loadedConfig: LoadedRouterConfig = (c[0] as any)._loadedConfig !; const module: any = loadedConfig.module; expect(loadedConfig.routes[0].path).toEqual('LoadedModule1'); expect(module._parent).toBe(testModule); - const loadedConfig2: LoadedRouterConfig = loadedConfig.routes[0]._loadedConfig !; + const loadedConfig2: LoadedRouterConfig = + (loadedConfig.routes[0] as any)._loadedConfig !; const module2: any = loadedConfig2.module; expect(loadedConfig2.routes[0].path).toEqual('LoadedModule2'); expect(module2._parent).toBe(module); @@ -124,56 +125,57 @@ describe('RouterPreloader', () => { }); }); - it('should work', - fakeAsync(inject( - [NgModuleFactoryLoader, RouterPreloader, Router, NgModuleRef, Compiler], - (loader: SpyNgModuleFactoryLoader, preloader: RouterPreloader, router: Router, - testModule: NgModuleRef, compiler: Compiler) => { - @NgModule() - class LoadedModule2 { - } + it('should work', fakeAsync(inject( + [NgModuleFactoryLoader, RouterPreloader, Router, NgModuleRef, Compiler], + (loader: SpyNgModuleFactoryLoader, preloader: RouterPreloader, + router: Router, testModule: NgModuleRef, compiler: Compiler) => { + @NgModule() + class LoadedModule2 { + } - const module2 = compiler.compileModuleSync(LoadedModule2).create(null); + const module2 = compiler.compileModuleSync(LoadedModule2).create(null); - @NgModule({ - imports: [RouterModule.forChild([ - { - path: 'LoadedModule2', - loadChildren: 'no', - _loadedConfig: { - routes: [{path: 'LoadedModule3', loadChildren: 'expected3'}], - module: module2, - } - }, - ])] - }) - class LoadedModule1 { - } + @NgModule({ + imports: [RouterModule.forChild([ + { + path: 'LoadedModule2', + loadChildren: 'no', + _loadedConfig: { + routes: [{path: 'LoadedModule3', loadChildren: 'expected3'}], + module: module2, + } + }, + ])] + }) + class LoadedModule1 { + } - @NgModule({imports: [RouterModule.forChild([])]}) - class LoadedModule3 { - } + @NgModule({imports: [RouterModule.forChild([])]}) + class LoadedModule3 { + } - loader.stubbedModules = { - expected: LoadedModule1, - expected3: LoadedModule3, - }; + loader.stubbedModules = { + expected: LoadedModule1, + expected3: LoadedModule3, + }; - preloader.preload().subscribe(() => {}); + preloader.preload().subscribe(() => {}); - tick(); + tick(); - const c = router.config; + const c = router.config; - const loadedConfig: LoadedRouterConfig = c[0]._loadedConfig !; - const module: any = loadedConfig.module; - expect(module._parent).toBe(testModule); + const loadedConfig: LoadedRouterConfig = (c[0] as any)._loadedConfig !; + const module: any = loadedConfig.module; + expect(module._parent).toBe(testModule); - const loadedConfig2: LoadedRouterConfig = loadedConfig.routes[0]._loadedConfig !; - const loadedConfig3: LoadedRouterConfig = loadedConfig2.routes[0]._loadedConfig !; - const module3: any = loadedConfig3.module; - expect(module3._parent).toBe(module2); - }))); + const loadedConfig2: LoadedRouterConfig = + (loadedConfig.routes[0] as any)._loadedConfig !; + const loadedConfig3: LoadedRouterConfig = + (loadedConfig2.routes[0] as any)._loadedConfig !; + const module3: any = loadedConfig3.module; + expect(module3._parent).toBe(module2); + }))); }); describe('should ignore errors', () => { @@ -204,8 +206,8 @@ describe('RouterPreloader', () => { tick(); const c = router.config; - expect(c[0]._loadedConfig).not.toBeDefined(); - expect(c[1]._loadedConfig).toBeDefined(); + expect((c[0] as any)._loadedConfig).not.toBeDefined(); + expect((c[1] as any)._loadedConfig).toBeDefined(); }))); }); }); diff --git a/packages/router/test/router_state.spec.ts b/packages/router/test/router_state.spec.ts index f813d6c050..49518e263b 100644 --- a/packages/router/test/router_state.spec.ts +++ b/packages/router/test/router_state.spec.ts @@ -27,7 +27,7 @@ describe('RouterState & Snapshot', () => { const root = new TreeNode(a, [new TreeNode(b, []), new TreeNode(c, [])]); - state = new RouterStateSnapshot('url', root); + state = new (RouterStateSnapshot as any)('url', root); }); it('should return first child', () => { expect(state.root.firstChild).toBe(b); }); @@ -69,7 +69,7 @@ describe('RouterState & Snapshot', () => { const root = new TreeNode(a, [new TreeNode(b, []), new TreeNode(c, [])]); - state = new RouterState(root, null); + state = new (RouterState as any)(root, null); }); it('should return first child', () => { expect(state.root.firstChild).toBe(b); }); @@ -100,10 +100,10 @@ describe('RouterState & Snapshot', () => { describe('equalParamsAndUrlSegments', () => { function createSnapshot(params: Params, url: UrlSegment[]): ActivatedRouteSnapshot { - const snapshot = new ActivatedRouteSnapshot( + const snapshot = new (ActivatedRouteSnapshot as any)( url, params, null, null, null, null, null, null, null, -1, null !); - snapshot._routerState = new RouterStateSnapshot('', new TreeNode(snapshot, [])); + snapshot._routerState = new (RouterStateSnapshot as any)('', new TreeNode(snapshot, [])); return snapshot; } @@ -116,10 +116,10 @@ describe('RouterState & Snapshot', () => { const snapshot1Parent = createSnapshot(parentParams[0], [new UrlSegment(urls[0], {})]); const snapshot2Parent = createSnapshot(parentParams[1], [new UrlSegment(urls[1], {})]); - snapshot1._routerState = - new RouterStateSnapshot('', new TreeNode(snapshot1Parent, [new TreeNode(snapshot1, [])])); - snapshot2._routerState = - new RouterStateSnapshot('', new TreeNode(snapshot2Parent, [new TreeNode(snapshot2, [])])); + (snapshot1 as any)._routerState = new (RouterStateSnapshot as any)( + '', new TreeNode(snapshot1Parent, [new TreeNode(snapshot1, [])])); + (snapshot2 as any)._routerState = new (RouterStateSnapshot as any)( + '', new TreeNode(snapshot2Parent, [new TreeNode(snapshot2, [])])); return [snapshot1, snapshot2]; } @@ -175,10 +175,10 @@ describe('RouterState & Snapshot', () => { const queryParams = {}; const fragment = ''; const data = {}; - const snapshot = new ActivatedRouteSnapshot( + const snapshot = new (ActivatedRouteSnapshot as any)( url, params, queryParams, fragment, data, null, null, null, null, -1, null !); - const state = new RouterStateSnapshot('', new TreeNode(snapshot, [])); + const state = new (RouterStateSnapshot as any)('', new TreeNode(snapshot, [])); snapshot._routerState = state; return snapshot; } @@ -187,7 +187,7 @@ describe('RouterState & Snapshot', () => { const firstPlace = createSnapshot({a: 1}, []); const secondPlace = createSnapshot({a: 2}, []); route.snapshot = firstPlace; - route._futureSnapshot = secondPlace; + (route as any)._futureSnapshot = secondPlace; let hasSeenDataChange = false; route.data.forEach((data) => { hasSeenDataChange = true; }); @@ -198,13 +198,13 @@ describe('RouterState & Snapshot', () => { }); function createActivatedRouteSnapshot(cmp: string) { - return new ActivatedRouteSnapshot( + return new (ActivatedRouteSnapshot as any)( null, null, null, null, null, null, cmp, null, null, -1, null !); } function createActivatedRoute(cmp: string) { - return new ActivatedRoute( + return new (ActivatedRoute as any)( new BehaviorSubject([new UrlSegment('', {})]), new BehaviorSubject({}), null, null, new BehaviorSubject({}), null, cmp, null); } diff --git a/packages/router/test/spy_ng_module_factory_loader.spec.ts b/packages/router/test/spy_ng_module_factory_loader.spec.ts index 947aff8049..70809a1cdf 100644 --- a/packages/router/test/spy_ng_module_factory_loader.spec.ts +++ b/packages/router/test/spy_ng_module_factory_loader.spec.ts @@ -36,7 +36,7 @@ describe('SpyNgModuleFactoryLoader', () => { const r = new SpyNgModuleFactoryLoader(null); let error: any = null; - r.load('two').catch(e => error = e); + r.load('two').catch((e: any) => error = e); tick(); diff --git a/packages/router/test/utils/tree.spec.ts b/packages/router/test/utils/tree.spec.ts index 5534175733..a8260fec08 100644 --- a/packages/router/test/utils/tree.spec.ts +++ b/packages/router/test/utils/tree.spec.ts @@ -10,44 +10,44 @@ import {Tree, TreeNode} from '../../src/utils/tree'; describe('tree', () => { it('should return the root of the tree', () => { - const t = new Tree(new TreeNode(1, [])); + const t = new Tree(new TreeNode(1, [])) as any; expect(t.root).toEqual(1); }); it('should return the parent of a node', () => { - const t = new Tree(new TreeNode(1, [new TreeNode(2, [])])); + const t = new Tree(new TreeNode(1, [new TreeNode(2, [])])) as any; expect(t.parent(1)).toEqual(null); expect(t.parent(2)).toEqual(1); }); it('should return the parent of a node (second child)', () => { const t = new Tree( - new TreeNode(1, [new TreeNode(2, []), new TreeNode(3, [])])); + new TreeNode(1, [new TreeNode(2, []), new TreeNode(3, [])])) as any; expect(t.parent(1)).toEqual(null); expect(t.parent(3)).toEqual(1); }); it('should return the children of a node', () => { - const t = new Tree(new TreeNode(1, [new TreeNode(2, [])])); + const t = new Tree(new TreeNode(1, [new TreeNode(2, [])])) as any; expect(t.children(1)).toEqual([2]); expect(t.children(2)).toEqual([]); }); it('should return the first child of a node', () => { - const t = new Tree(new TreeNode(1, [new TreeNode(2, [])])); + const t = new Tree(new TreeNode(1, [new TreeNode(2, [])])) as any; expect(t.firstChild(1)).toEqual(2); expect(t.firstChild(2)).toEqual(null); }); it('should return the siblings of a node', () => { const t = new Tree( - new TreeNode(1, [new TreeNode(2, []), new TreeNode(3, [])])); + new TreeNode(1, [new TreeNode(2, []), new TreeNode(3, [])])) as any; expect(t.siblings(2)).toEqual([3]); expect(t.siblings(1)).toEqual([]); }); it('should return the path to the root', () => { - const t = new Tree(new TreeNode(1, [new TreeNode(2, [])])); + const t = new Tree(new TreeNode(1, [new TreeNode(2, [])])) as any; expect(t.pathFromRoot(2)).toEqual([1, 2]); }); }); diff --git a/packages/service-worker/test/BUILD.bazel b/packages/service-worker/test/BUILD.bazel new file mode 100644 index 0000000000..ed6ba86bb0 --- /dev/null +++ b/packages/service-worker/test/BUILD.bazel @@ -0,0 +1,42 @@ +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test") + +ts_library( + name = "test_lib", + testonly = 1, + srcs = glob(["**/*.ts"]), + tsconfig = "//packages:tsconfig", + deps = [ + "//packages:types", + "//packages/core", + "//packages/core/testing", + "//packages/service-worker", + "//packages/service-worker/testing", + "//packages/service-worker/worker", + "//packages/service-worker/worker/testing", + "@rxjs", + ], +) + +jasmine_node_test( + name = "test", + bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"], + deps = [ + ":test_lib", + "//packages/_testing_init:node", + ], +) + +ts_web_test( + name = "test_web", + bootstrap = [ + "//:angular_bootstrap_scripts", + ], + # dissable since tests are running but not yet passing + tags = ["manual"], + # do not sort + deps = [ + "//packages/_testing_init:browser", + ":test_lib", + ], +) diff --git a/packages/service-worker/test/comm_spec.ts b/packages/service-worker/test/comm_spec.ts index 09c22fb2e0..fcec448fd2 100644 --- a/packages/service-worker/test/comm_spec.ts +++ b/packages/service-worker/test/comm_spec.ts @@ -30,14 +30,14 @@ import {MockServiceWorkerContainer, MockServiceWorkerRegistration} from '../test mock.setupSw(); - comm.registration.subscribe(reg => { done(); }); + (comm as any).registration.subscribe((reg: any) => { done(); }); }); it('can access the registration when it comes after subscription', (done: DoneFn) => { const mock = new MockServiceWorkerContainer(); const comm = new NgswCommChannel(mock as any, 'browser'); const regPromise = mock.getRegistration() as any as MockServiceWorkerRegistration; - comm.registration.subscribe(reg => { done(); }); + (comm as any).registration.subscribe((reg: any) => { done(); }); mock.setupSw(); }); diff --git a/packages/service-worker/test/integration_spec.ts b/packages/service-worker/test/integration_spec.ts index b407286ead..8e1f846787 100644 --- a/packages/service-worker/test/integration_spec.ts +++ b/packages/service-worker/test/integration_spec.ts @@ -65,7 +65,7 @@ const server = new MockServerStateBuilder().withStaticFiles(dist).withManifest(m const serverUpdate = new MockServerStateBuilder().withStaticFiles(distUpdate).withManifest(manifestUpdate).build(); -(function(){ +(function() { // Skip environments that don't support the minimum APIs needed to run the SW tests. if (!SwTestHarness.envIsSupported()) { return; diff --git a/packages/service-worker/testing/BUILD.bazel b/packages/service-worker/testing/BUILD.bazel new file mode 100644 index 0000000000..db332e5daf --- /dev/null +++ b/packages/service-worker/testing/BUILD.bazel @@ -0,0 +1,13 @@ +package(default_visibility = ["//visibility:public"]) + +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library") + +ts_library( + name = "testing", + testonly = 1, + srcs = glob(["**/*.ts"]), + module_name = "@angular/service-worker/testing", + tsconfig = "//packages:tsconfig", + deps = [ + ], +) diff --git a/packages/service-worker/worker/test/BUILD.bazel b/packages/service-worker/worker/test/BUILD.bazel index 3b9560b5b2..b9ba5c8154 100644 --- a/packages/service-worker/worker/test/BUILD.bazel +++ b/packages/service-worker/worker/test/BUILD.bazel @@ -18,8 +18,6 @@ ts_library( jasmine_node_test( name = "test", srcs = [], - # TODO(alxhub): re-enable when need for main() is removed - tags = ["manual"], deps = [ ":test_lib", ], diff --git a/packages/service-worker/worker/test/data_spec.ts b/packages/service-worker/worker/test/data_spec.ts index 10ec69fa64..7d1f00b894 100644 --- a/packages/service-worker/worker/test/data_spec.ts +++ b/packages/service-worker/worker/test/data_spec.ts @@ -114,7 +114,7 @@ function asyncWrap(fn: () => Promise): (done: DoneFn) => void { return (done: DoneFn) => { fn().then(() => done(), err => done.fail(err)); }; } -(function(){ +(function() { // Skip environments that don't support the minimum APIs needed to run the SW tests. if (!SwTestHarness.envIsSupported()) { return; diff --git a/packages/service-worker/worker/test/happy_spec.ts b/packages/service-worker/worker/test/happy_spec.ts index 9a9bcec530..6e128249de 100644 --- a/packages/service-worker/worker/test/happy_spec.ts +++ b/packages/service-worker/worker/test/happy_spec.ts @@ -139,7 +139,7 @@ const scope = new SwTestHarnessBuilder().withServerState(server).build(); const manifestHash = sha1(JSON.stringify(manifest)); const manifestUpdateHash = sha1(JSON.stringify(manifestUpdate)); -(function(){ +(function() { // Skip environments that don't support the minimum APIs needed to run the SW tests. if (!SwTestHarness.envIsSupported()) { return; diff --git a/packages/service-worker/worker/test/idle_spec.ts b/packages/service-worker/worker/test/idle_spec.ts index b20c276365..c7cd1da1d6 100644 --- a/packages/service-worker/worker/test/idle_spec.ts +++ b/packages/service-worker/worker/test/idle_spec.ts @@ -10,7 +10,7 @@ import {IdleScheduler} from '../src/idle'; import {SwTestHarness, SwTestHarnessBuilder} from '../testing/scope'; import {async_beforeEach, async_fit, async_it} from './async'; -(function(){ +(function() { // Skip environments that don't support the minimum APIs needed to run the SW tests. if (!SwTestHarness.envIsSupported()) { return; diff --git a/packages/service-worker/worker/test/prefetch_spec.ts b/packages/service-worker/worker/test/prefetch_spec.ts index 05594f88f4..d77cccee10 100644 --- a/packages/service-worker/worker/test/prefetch_spec.ts +++ b/packages/service-worker/worker/test/prefetch_spec.ts @@ -29,7 +29,7 @@ const db = new CacheDatabase(scope, scope); -(function(){ +(function() { // Skip environments that don't support the minimum APIs needed to run the SW tests. if (!SwTestHarness.envIsSupported()) { return; diff --git a/packages/types.d.ts b/packages/types.d.ts index 30d6280539..1ec1d9f1e9 100644 --- a/packages/types.d.ts +++ b/packages/types.d.ts @@ -16,3 +16,6 @@ /// /// /// + +declare let isNode: boolean; +declare let isBrowser: boolean; \ No newline at end of file diff --git a/packages/upgrade/BUILD.bazel b/packages/upgrade/BUILD.bazel new file mode 100644 index 0000000000..413cf2f688 --- /dev/null +++ b/packages/upgrade/BUILD.bazel @@ -0,0 +1,20 @@ +package(default_visibility = ["//visibility:public"]) + +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library") + +ts_library( + name = "upgrade", + srcs = glob( + [ + "*.ts", + "src/**/*.ts", + ], + ), + module_name = "@angular/upgrade", + tsconfig = "//packages:tsconfig", + deps = [ + "//packages/core", + "//packages/platform-browser", + "//packages/platform-browser-dynamic", + ], +) diff --git a/packages/upgrade/test/BUILD.bazel b/packages/upgrade/test/BUILD.bazel new file mode 100644 index 0000000000..de019c673d --- /dev/null +++ b/packages/upgrade/test/BUILD.bazel @@ -0,0 +1,35 @@ +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test") + +ts_library( + name = "test_lib", + testonly = 1, + srcs = glob(["**/*.ts"]), + tsconfig = "//packages:tsconfig", + deps = [ + "//packages:types", + "//packages/core", + "//packages/core/testing", + "//packages/platform-browser", + "//packages/platform-browser-dynamic", + "//packages/platform-browser/testing", + "//packages/upgrade", + "//packages/upgrade/static", + "@rxjs", + ], +) + +ts_web_test( + name = "test_web", + bootstrap = [ + "//:angular_bootstrap_scripts", + "//:node_modules/angular/angular.js", + ], + # dissable since tests are running but not yet passing + tags = ["manual"], + # do not sort + deps = [ + "//packages/_testing_init:browser", + ":test_lib", + ], +) diff --git a/packages/upgrade/test/dynamic/upgrade_spec.ts b/packages/upgrade/test/dynamic/upgrade_spec.ts index 8c6909a26d..8d09901f48 100644 --- a/packages/upgrade/test/dynamic/upgrade_spec.ts +++ b/packages/upgrade/test/dynamic/upgrade_spec.ts @@ -14,6 +14,10 @@ import * as angular from '@angular/upgrade/src/common/angular1'; import {UpgradeAdapter, UpgradeAdapterRef} from '@angular/upgrade/src/dynamic/upgrade_adapter'; import {$digest, html, multiTrim} from './test_helpers'; +declare global { + export var inject: Function; +} + { describe('adapter: ng1 to ng2', () => { beforeEach(() => destroyPlatform()); diff --git a/test-main.js b/test-main.js index a65ecb5970..a38712d3fd 100644 --- a/test-main.js +++ b/test-main.js @@ -15,6 +15,9 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 100; // we will call `__karma__.start()` later, once all the specs are loaded. __karma__.loaded = function() {}; +window.isNode = false; +window.isBrowser = true; + System.config({ baseURL: '/base', defaultJSExtensions: true, diff --git a/tools/cjs-jasmine/index.ts b/tools/cjs-jasmine/index.ts index 9527d0b843..a054257769 100644 --- a/tools/cjs-jasmine/index.ts +++ b/tools/cjs-jasmine/index.ts @@ -45,6 +45,9 @@ if (globsIndex < 0) { args = process.argv.slice(globsIndex + 1); } +(global as any).isNode = true; +(global as any).isBrowser = false; + var specFiles: any = args.map(function(globstr: string): string[] {