Skip to content

Commit d9dc41a

Browse files
clydinAndrewKushnir
authored andcommitted
test(compiler-cli): add compliance tests for external runtime styles (angular#57613)
To ensure that the external runtime style component feature is correctly emitted by the Angular compiler, compliance tests have been added for file-based component styles. Additionally, the partial golden generator has been updated to work with file-based component styles. PR Close angular#57613
1 parent da250b2 commit d9dc41a

File tree

9 files changed

+145
-2
lines changed

9 files changed

+145
-2
lines changed

packages/compiler-cli/test/compliance/partial/partial_compliance_goldens.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def partial_compliance_golden(filePath):
1212
"//packages/compiler-cli/test/compliance/partial:generate_golden_partial_lib",
1313
"//packages/core:npm_package",
1414
filePath,
15-
] + native.glob(["%s/*.ts" % path, "%s/**/*.html" % path])
15+
] + native.glob(["%s/*.ts" % path, "%s/**/*.html" % path, "%s/**/*.css" % path])
1616

1717
nodejs_binary(
1818
name = generate_partial_name,

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/component_styles/GOLDEN_PARTIAL.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,43 @@ export declare class MyModule {
3535
static ɵinj: i0.ɵɵInjectorDeclaration<MyModule>;
3636
}
3737

38+
/****************************************************************************************************
39+
* PARTIAL FILE: encapsulation_emulated.js
40+
****************************************************************************************************/
41+
import { Component, NgModule, ViewEncapsulation } from '@angular/core';
42+
import * as i0 from "@angular/core";
43+
export class MyComponent {
44+
}
45+
MyComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
46+
MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: MyComponent, selector: "my-component", ngImport: i0, template: '...', isInline: true, styles: ["div.bar { color: blue; }\n", "div.baz { color: purple; }\n", "div.foo { color: red; }", ":host p:nth-child(even) { --webkit-transition: 1s linear all; }"] });
47+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyComponent, decorators: [{
48+
type: Component,
49+
args: [{ selector: 'my-component', encapsulation: ViewEncapsulation.Emulated, template: '...', styles: ["div.bar { color: blue; }\n", "div.baz { color: purple; }\n", "div.foo { color: red; }", ":host p:nth-child(even) { --webkit-transition: 1s linear all; }"] }]
50+
}] });
51+
export class MyModule {
52+
}
53+
MyModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
54+
MyModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyModule, declarations: [MyComponent] });
55+
MyModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyModule });
56+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyModule, decorators: [{
57+
type: NgModule,
58+
args: [{ declarations: [MyComponent] }]
59+
}] });
60+
61+
/****************************************************************************************************
62+
* PARTIAL FILE: encapsulation_emulated.d.ts
63+
****************************************************************************************************/
64+
import * as i0 from "@angular/core";
65+
export declare class MyComponent {
66+
static ɵfac: i0.ɵɵFactoryDeclaration<MyComponent, never>;
67+
static ɵcmp: i0.ɵɵComponentDeclaration<MyComponent, "my-component", never, {}, {}, never, never, false, never>;
68+
}
69+
export declare class MyModule {
70+
static ɵfac: i0.ɵɵFactoryDeclaration<MyModule, never>;
71+
static ɵmod: i0.ɵɵNgModuleDeclaration<MyModule, [typeof MyComponent], never, never>;
72+
static ɵinj: i0.ɵɵInjectorDeclaration<MyModule>;
73+
}
74+
3875
/****************************************************************************************************
3976
* PARTIAL FILE: encapsulation_none.js
4077
****************************************************************************************************/
@@ -109,3 +146,40 @@ export declare class MyModule {
109146
static ɵinj: i0.ɵɵInjectorDeclaration<MyModule>;
110147
}
111148

149+
/****************************************************************************************************
150+
* PARTIAL FILE: external_runtime_files.js
151+
****************************************************************************************************/
152+
import { Component, NgModule, ViewEncapsulation } from '@angular/core';
153+
import * as i0 from "@angular/core";
154+
export class MyComponent {
155+
}
156+
MyComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
157+
MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: MyComponent, selector: "my-component", ngImport: i0, template: '...', isInline: true });
158+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyComponent, decorators: [{
159+
type: Component,
160+
args: [{ selector: 'my-component', encapsulation: ViewEncapsulation.Emulated, template: '...' }]
161+
}] });
162+
export class MyModule {
163+
}
164+
MyModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
165+
MyModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyModule, declarations: [MyComponent] });
166+
MyModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyModule });
167+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyModule, decorators: [{
168+
type: NgModule,
169+
args: [{ declarations: [MyComponent] }]
170+
}] });
171+
172+
/****************************************************************************************************
173+
* PARTIAL FILE: external_runtime_files.d.ts
174+
****************************************************************************************************/
175+
import * as i0 from "@angular/core";
176+
export declare class MyComponent {
177+
static ɵfac: i0.ɵɵFactoryDeclaration<MyComponent, never>;
178+
static ɵcmp: i0.ɵɵComponentDeclaration<MyComponent, "my-component", never, {}, {}, never, never, false, never>;
179+
}
180+
export declare class MyModule {
181+
static ɵfac: i0.ɵɵFactoryDeclaration<MyModule, never>;
182+
static ɵmod: i0.ɵɵNgModuleDeclaration<MyModule, [typeof MyComponent], never, never>;
183+
static ɵinj: i0.ɵɵInjectorDeclaration<MyModule>;
184+
}
185+

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/component_styles/TEST_CASES.json

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@
1515
}
1616
]
1717
},
18+
{
19+
"description": "should pass in the component metadata styles into the component definition and shim them using style encapsulation",
20+
"inputFiles": [
21+
"encapsulation_emulated.ts"
22+
],
23+
"expectations": [
24+
{
25+
"failureMessage": "Incorrect template",
26+
"files": [
27+
"encapsulation_emulated.js"
28+
]
29+
}
30+
]
31+
},
1832
{
1933
"description": "should pass in styles, but skip shimming the styles if the view encapsulation signals not to",
2034
"inputFiles": [
@@ -42,6 +56,26 @@
4256
]
4357
}
4458
]
59+
},
60+
{
61+
"description": "should emit external runtime styles component feature for file-based styles when 'externalRuntimeStyles' option is enabled",
62+
"inputFiles": [
63+
"external_runtime_files.ts"
64+
],
65+
"angularCompilerOptions": {
66+
"externalRuntimeStyles": true
67+
},
68+
"compilationModeFilter": [
69+
"full compile"
70+
],
71+
"expectations": [
72+
{
73+
"failureMessage": "Incorrect template",
74+
"files": [
75+
"external_runtime_files.js"
76+
]
77+
}
78+
]
4579
}
4680
]
47-
}
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["div.bar { color: blue; }\n", "div.baz { color: purple; }\n", "div.foo { color: red; }", ":host p:nth-child(even) { --webkit-transition: 1s linear all; }"]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {Component, NgModule, ViewEncapsulation} from '@angular/core';
2+
3+
@Component({
4+
selector: 'my-component',
5+
encapsulation: ViewEncapsulation.Emulated,
6+
styles: [
7+
'div.foo { color: red; }', ':host p:nth-child(even) { --webkit-transition: 1s linear all; }'
8+
],
9+
styleUrls: ['./style-A.css', './style-B.css'],
10+
template: '...'
11+
})
12+
export class MyComponent {
13+
}
14+
15+
@NgModule({declarations: [MyComponent]})
16+
export class MyModule {
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ɵɵExternalStylesFeature(["/style-A.css", "/style-B.css"])
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {Component, NgModule, ViewEncapsulation} from '@angular/core';
2+
3+
@Component({
4+
selector: 'my-component',
5+
encapsulation: ViewEncapsulation.Emulated,
6+
styleUrls: ['./style-A.css', './style-B.css'],
7+
template: '...'
8+
})
9+
export class MyComponent {
10+
}
11+
12+
@NgModule({declarations: [MyComponent]})
13+
export class MyModule {
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
div.bar { color: blue; }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
div.baz { color: purple; }

0 commit comments

Comments
 (0)