From 71a5314335e1dbdc3a6db1a7451e1c4ef5e6fb49 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Sun, 29 Nov 2020 10:58:23 +0100 Subject: [PATCH] test(compiler-cli): migrate providers compliance tests (#39878) Migrates the `r3_view_compiler_providers` compliance tests to the new format. PR Close #39878 --- .../GOLDEN_PARTIAL.js | 174 ++++++++++++++++++ .../TEST_CASES.json | 82 +++++++++ .../providers_feature_no_providers.ts | 9 + ...oviders_feature_no_providers_definition.js | 12 ++ .../providers_feature_no_providers_factory.js | 1 + ...rs_feature_providers_and_view_providers.ts | 24 +++ ...e_providers_and_view_providers_features.js | 1 + .../providers_feature_providers_only.ts | 23 +++ ...oviders_feature_providers_only_features.js | 1 + .../providers_feature_view_providers_only.ts | 19 ++ ...rs_feature_view_providers_only_features.js | 1 + 11 files changed, 347 insertions(+) create mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/GOLDEN_PARTIAL.js create mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/TEST_CASES.json create mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_no_providers.ts create mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_no_providers_definition.js create mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_no_providers_factory.js create mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_providers_and_view_providers.ts create mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_providers_and_view_providers_features.js create mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_providers_only.ts create mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_providers_only_features.js create mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_view_providers_only.ts create mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_view_providers_only_features.js diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/GOLDEN_PARTIAL.js b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/GOLDEN_PARTIAL.js new file mode 100644 index 0000000000..8239e93f39 --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/GOLDEN_PARTIAL.js @@ -0,0 +1,174 @@ +/**************************************************************************************************** + * PARTIAL FILE: providers_feature_providers_and_view_providers.js + ****************************************************************************************************/ +import { Component, NgModule } from '@angular/core'; +import * as i0 from "@angular/core"; +class Greeter { +} +class GreeterEN { + greet() { + return 'Hi'; + } +} +export class MyComponent { +} +MyComponent.ɵfac = function MyComponent_Factory(t) { return new (t || MyComponent)(); }; +MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ version: 1, type: MyComponent, selector: "my-component", providers: [GreeterEN, { provide: Greeter, useClass: GreeterEN }], ngImport: i0, template: { source: '
', isInline: true }, viewProviders: [GreeterEN] }); +/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(MyComponent, [{ + type: Component, + args: [{ + selector: 'my-component', + template: '
', + providers: [GreeterEN, { provide: Greeter, useClass: GreeterEN }], + viewProviders: [GreeterEN] + }] + }], null, null); })(); +export class MyModule { +} +MyModule.ɵmod = i0.ɵɵdefineNgModule({ type: MyModule }); +MyModule.ɵinj = i0.ɵɵdefineInjector({ factory: function MyModule_Factory(t) { return new (t || MyModule)(); } }); +(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(MyModule, { declarations: [MyComponent] }); })(); +/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(MyModule, [{ + type: NgModule, + args: [{ declarations: [MyComponent] }] + }], null, null); })(); + +/**************************************************************************************************** + * PARTIAL FILE: providers_feature_providers_and_view_providers.d.ts + ****************************************************************************************************/ +import * as i0 from "@angular/core"; +export declare class MyComponent { + static ɵfac: i0.ɵɵFactoryDef; + static ɵcmp: i0.ɵɵComponentDefWithMeta; +} +export declare class MyModule { + static ɵmod: i0.ɵɵNgModuleDefWithMeta; + static ɵinj: i0.ɵɵInjectorDef; +} + +/**************************************************************************************************** + * PARTIAL FILE: providers_feature_providers_only.js + ****************************************************************************************************/ +import { Component, NgModule } from '@angular/core'; +import * as i0 from "@angular/core"; +class Greeter { +} +class GreeterEN { + greet() { + return 'Hi'; + } +} +export class MyComponent { +} +MyComponent.ɵfac = function MyComponent_Factory(t) { return new (t || MyComponent)(); }; +MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ version: 1, type: MyComponent, selector: "my-component", providers: [GreeterEN, { provide: Greeter, useClass: GreeterEN }], ngImport: i0, template: { source: '
', isInline: true } }); +/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(MyComponent, [{ + type: Component, + args: [{ + selector: 'my-component', + template: '
', + providers: [GreeterEN, { provide: Greeter, useClass: GreeterEN }] + }] + }], null, null); })(); +export class MyModule { +} +MyModule.ɵmod = i0.ɵɵdefineNgModule({ type: MyModule }); +MyModule.ɵinj = i0.ɵɵdefineInjector({ factory: function MyModule_Factory(t) { return new (t || MyModule)(); } }); +(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(MyModule, { declarations: [MyComponent] }); })(); +/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(MyModule, [{ + type: NgModule, + args: [{ declarations: [MyComponent] }] + }], null, null); })(); + +/**************************************************************************************************** + * PARTIAL FILE: providers_feature_providers_only.d.ts + ****************************************************************************************************/ +import * as i0 from "@angular/core"; +export declare class MyComponent { + static ɵfac: i0.ɵɵFactoryDef; + static ɵcmp: i0.ɵɵComponentDefWithMeta; +} +export declare class MyModule { + static ɵmod: i0.ɵɵNgModuleDefWithMeta; + static ɵinj: i0.ɵɵInjectorDef; +} + +/**************************************************************************************************** + * PARTIAL FILE: providers_feature_view_providers_only.js + ****************************************************************************************************/ +import { Component, NgModule } from '@angular/core'; +import * as i0 from "@angular/core"; +class Greeter { +} +class GreeterEN { + greet() { + return 'Hi'; + } +} +export class MyComponent { +} +MyComponent.ɵfac = function MyComponent_Factory(t) { return new (t || MyComponent)(); }; +MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ version: 1, type: MyComponent, selector: "my-component", ngImport: i0, template: { source: '
', isInline: true }, viewProviders: [GreeterEN] }); +/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(MyComponent, [{ + type: Component, + args: [{ selector: 'my-component', template: '
', viewProviders: [GreeterEN] }] + }], null, null); })(); +export class MyModule { +} +MyModule.ɵmod = i0.ɵɵdefineNgModule({ type: MyModule }); +MyModule.ɵinj = i0.ɵɵdefineInjector({ factory: function MyModule_Factory(t) { return new (t || MyModule)(); } }); +(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(MyModule, { declarations: [MyComponent] }); })(); +/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(MyModule, [{ + type: NgModule, + args: [{ declarations: [MyComponent] }] + }], null, null); })(); + +/**************************************************************************************************** + * PARTIAL FILE: providers_feature_view_providers_only.d.ts + ****************************************************************************************************/ +import * as i0 from "@angular/core"; +export declare class MyComponent { + static ɵfac: i0.ɵɵFactoryDef; + static ɵcmp: i0.ɵɵComponentDefWithMeta; +} +export declare class MyModule { + static ɵmod: i0.ɵɵNgModuleDefWithMeta; + static ɵinj: i0.ɵɵInjectorDef; +} + +/**************************************************************************************************** + * PARTIAL FILE: providers_feature_no_providers.js + ****************************************************************************************************/ +import { Component, NgModule } from '@angular/core'; +import * as i0 from "@angular/core"; +export class MyComponent { +} +MyComponent.ɵfac = function MyComponent_Factory(t) { return new (t || MyComponent)(); }; +MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ version: 1, type: MyComponent, selector: "my-component", ngImport: i0, template: { source: '
', isInline: true } }); +/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(MyComponent, [{ + type: Component, + args: [{ selector: 'my-component', template: '
' }] + }], null, null); })(); +export class MyModule { +} +MyModule.ɵmod = i0.ɵɵdefineNgModule({ type: MyModule }); +MyModule.ɵinj = i0.ɵɵdefineInjector({ factory: function MyModule_Factory(t) { return new (t || MyModule)(); } }); +(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(MyModule, { declarations: [MyComponent] }); })(); +/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(MyModule, [{ + type: NgModule, + args: [{ declarations: [MyComponent] }] + }], null, null); })(); + +/**************************************************************************************************** + * PARTIAL FILE: providers_feature_no_providers.d.ts + ****************************************************************************************************/ +import * as i0 from "@angular/core"; +export declare class MyComponent { + static ɵfac: i0.ɵɵFactoryDef; + static ɵcmp: i0.ɵɵComponentDefWithMeta; +} +export declare class MyModule { + static ɵmod: i0.ɵɵNgModuleDefWithMeta; + static ɵinj: i0.ɵɵInjectorDef; +} + diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/TEST_CASES.json b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/TEST_CASES.json new file mode 100644 index 0000000000..2840fe1f80 --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/TEST_CASES.json @@ -0,0 +1,82 @@ +{ + "$schema": "../test_case_schema.json", + "cases": [ + { + "description": "should emit the ProvidersFeature feature when providers and viewProviders are used", + "inputFiles": [ + "providers_feature_providers_and_view_providers.ts" + ], + "expectations": [ + { + "files": [ + { + "expected": "providers_feature_providers_and_view_providers_features.js", + "generated": "providers_feature_providers_and_view_providers.js" + } + ], + "failureMessage": "Incorrect features" + } + ] + }, + { + "description": "should emit the ProvidersFeature feature when providers only", + "inputFiles": [ + "providers_feature_providers_only.ts" + ], + "expectations": [ + { + "files": [ + { + "expected": "providers_feature_providers_only_features.js", + "generated": "providers_feature_providers_only.js" + } + ], + "failureMessage": "Incorrect features" + } + ] + }, + { + "description": "should emit the ProvidersFeature feature when viewProviders only", + "inputFiles": [ + "providers_feature_view_providers_only.ts" + ], + "expectations": [ + { + "files": [ + { + "expected": "providers_feature_view_providers_only_features.js", + "generated": "providers_feature_view_providers_only.js" + } + ], + "failureMessage": "Incorrect features" + } + ] + }, + { + "description": "should not emit the ProvidersFeature feature when no providers", + "inputFiles": [ + "providers_feature_no_providers.ts" + ], + "expectations": [ + { + "files": [ + { + "expected": "providers_feature_no_providers_definition.js", + "generated": "providers_feature_no_providers.js" + } + ], + "failureMessage": "Incorrect definition" + }, + { + "files": [ + { + "expected": "providers_feature_no_providers_factory.js", + "generated": "providers_feature_no_providers.js" + } + ], + "failureMessage": "Incorrect factory" + } + ] + } + ] +} diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_no_providers.ts b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_no_providers.ts new file mode 100644 index 0000000000..86e7a0857b --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_no_providers.ts @@ -0,0 +1,9 @@ +import {Component, NgModule} from '@angular/core'; + +@Component({selector: 'my-component', template: '
'}) +export class MyComponent { +} + +@NgModule({declarations: [MyComponent]}) +export class MyModule { +} diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_no_providers_definition.js b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_no_providers_definition.js new file mode 100644 index 0000000000..55636b890b --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_no_providers_definition.js @@ -0,0 +1,12 @@ +MyComponent.ɵcmp = i0.ɵɵdefineComponent({ + type: MyComponent, + selectors: [["my-component"]], + decls: 1, + vars: 0, + template: function MyComponent_Template(rf, ctx) { + if (rf & 1) { + i0.ɵɵelement(0, "div"); + } + }, + encapsulation: 2 +}); diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_no_providers_factory.js b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_no_providers_factory.js new file mode 100644 index 0000000000..65ff7f57f5 --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_no_providers_factory.js @@ -0,0 +1 @@ +MyComponent.ɵfac = function MyComponent_Factory(t) { return new (t || MyComponent)(); }; diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_providers_and_view_providers.ts b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_providers_and_view_providers.ts new file mode 100644 index 0000000000..1e5ed6c62b --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_providers_and_view_providers.ts @@ -0,0 +1,24 @@ +import {Component, NgModule} from '@angular/core'; + +abstract class Greeter { + abstract greet(): string; +} + +class GreeterEN implements Greeter { + greet() { + return 'Hi'; + } +} + +@Component({ + selector: 'my-component', + template: '
', + providers: [GreeterEN, {provide: Greeter, useClass: GreeterEN}], + viewProviders: [GreeterEN] +}) +export class MyComponent { +} + +@NgModule({declarations: [MyComponent]}) +export class MyModule { +} diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_providers_and_view_providers_features.js b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_providers_and_view_providers_features.js new file mode 100644 index 0000000000..b2ca4ff263 --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_providers_and_view_providers_features.js @@ -0,0 +1 @@ +features: [i0.ɵɵProvidersFeature([GreeterEN, {provide: Greeter, useClass: GreeterEN}], [GreeterEN])], diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_providers_only.ts b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_providers_only.ts new file mode 100644 index 0000000000..81d9531ea1 --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_providers_only.ts @@ -0,0 +1,23 @@ +import {Component, NgModule} from '@angular/core'; + +abstract class Greeter { + abstract greet(): string; +} + +class GreeterEN implements Greeter { + greet() { + return 'Hi'; + } +} + +@Component({ + selector: 'my-component', + template: '
', + providers: [GreeterEN, {provide: Greeter, useClass: GreeterEN}] +}) +export class MyComponent { +} + +@NgModule({declarations: [MyComponent]}) +export class MyModule { +} diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_providers_only_features.js b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_providers_only_features.js new file mode 100644 index 0000000000..f5bfa85672 --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_providers_only_features.js @@ -0,0 +1 @@ +features: [i0.ɵɵProvidersFeature([GreeterEN, {provide: Greeter, useClass: GreeterEN}])], diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_view_providers_only.ts b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_view_providers_only.ts new file mode 100644 index 0000000000..eb80dd3b6b --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_view_providers_only.ts @@ -0,0 +1,19 @@ +import {Component, NgModule} from '@angular/core'; + +abstract class Greeter { + abstract greet(): string; +} + +class GreeterEN implements Greeter { + greet() { + return 'Hi'; + } +} + +@Component({selector: 'my-component', template: '
', viewProviders: [GreeterEN]}) +export class MyComponent { +} + +@NgModule({declarations: [MyComponent]}) +export class MyModule { +} diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_view_providers_only_features.js b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_view_providers_only_features.js new file mode 100644 index 0000000000..dc13c1f253 --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_providers/providers_feature_view_providers_only_features.js @@ -0,0 +1 @@ +features: [i0.ɵɵProvidersFeature([], [GreeterEN])],