@@ -11,6 +11,7 @@ import { createArchitect, host } from '../utils';
11
11
12
12
13
13
describe ( 'Browser Builder bundle budgets' , ( ) => {
14
+ const cssExtensions = [ 'css' , 'scss' , 'less' , 'styl' ] ;
14
15
const targetSpec = { project : 'app' , target : 'build' } ;
15
16
let architect : Architect ;
16
17
@@ -64,66 +65,84 @@ describe('Browser Builder bundle budgets', () => {
64
65
await run . stop ( ) ;
65
66
} ) ;
66
67
67
- it ( `shows warnings for large component css when using 'anyComponentStyle' when AOT` , async ( ) => {
68
- const overrides = {
69
- aot : true ,
70
- optimization : true ,
71
- budgets : [ { type : 'anyComponentStyle' , maximumWarning : '1b' } ] ,
72
- } ;
73
-
74
- const cssContent = `
75
- .foo { color: white; padding: 1px; }
76
- .buz { color: white; padding: 2px; }
77
- .bar { color: white; padding: 3px; }
78
- ` ;
68
+ cssExtensions . forEach ( ext => {
69
+ it ( `shows warnings for large component ${ ext } when using 'anyComponentStyle' when AOT` , async ( ) => {
70
+ const overrides = {
71
+ aot : true ,
72
+ optimization : true ,
73
+ budgets : [ { type : 'anyComponentStyle' , maximumWarning : '1b' } ] ,
74
+ styles : [ `src/styles.${ ext } ` ] ,
75
+ } ;
79
76
80
- host . writeMultipleFiles ( {
81
- 'src/app/app.component.css' : cssContent ,
82
- 'src/assets/foo.css' : cssContent ,
83
- 'src/styles.css' : cssContent ,
77
+ const cssContent = `
78
+ .foo { color: white; padding: 1px; }
79
+ .buz { color: white; padding: 2px; }
80
+ .bar { color: white; padding: 3px; }
81
+ ` ;
82
+
83
+ host . writeMultipleFiles ( {
84
+ [ `src/app/app.component.${ ext } ` ] : cssContent ,
85
+ [ `src/assets/foo.${ ext } ` ] : cssContent ,
86
+ [ `src/styles.${ ext } ` ] : cssContent ,
87
+ } ) ;
88
+
89
+ host . replaceInFile (
90
+ 'src/app/app.component.ts' ,
91
+ './app.component.css' ,
92
+ `./app.component.${ ext } ` ,
93
+ ) ;
94
+
95
+ const logger = new logging . Logger ( '' ) ;
96
+ const logs : string [ ] = [ ] ;
97
+ logger . subscribe ( e => logs . push ( e . message ) ) ;
98
+
99
+ const run = await architect . scheduleTarget ( targetSpec , overrides , { logger } ) ;
100
+ const output = await run . result ;
101
+ expect ( output . success ) . toBe ( true ) ;
102
+ expect ( logs . length ) . toBe ( 2 ) ;
103
+ expect ( logs . join ( ) ) . toMatch ( `WARNING.+app\.component\.${ ext } ` ) ;
104
+ await run . stop ( ) ;
84
105
} ) ;
85
-
86
- const logger = new logging . Logger ( '' ) ;
87
- const logs : string [ ] = [ ] ;
88
- logger . subscribe ( e => logs . push ( e . message ) ) ;
89
-
90
- const run = await architect . scheduleTarget ( targetSpec , overrides , { logger } ) ;
91
- const output = await run . result ;
92
- expect ( output . success ) . toBe ( true ) ;
93
- expect ( logs . length ) . toBe ( 2 ) ;
94
- expect ( logs . join ( ) ) . toMatch ( / W A R N I N G .+ a p p \. c o m p o n e n t \. c s s / ) ;
95
- await run . stop ( ) ;
96
106
} ) ;
97
107
98
- it ( `shows error for large component css when using 'anyComponentStyle' when AOT` , async ( ) => {
99
- const overrides = {
100
- aot : true ,
101
- optimization : true ,
102
- budgets : [ { type : 'anyComponentStyle' , maximumError : '1b' } ] ,
103
- } ;
104
-
105
- const cssContent = `
106
- .foo { color: white; padding: 1px; }
107
- .buz { color: white; padding: 2px; }
108
- .bar { color: white; padding: 3px; }
109
- ` ;
108
+ cssExtensions . forEach ( ext => {
109
+ it ( `shows error for large component ${ ext } when using 'anyComponentStyle' when AOT` , async ( ) => {
110
+ const overrides = {
111
+ aot : true ,
112
+ optimization : true ,
113
+ budgets : [ { type : 'anyComponentStyle' , maximumError : '1b' } ] ,
114
+ styles : [ `src/styles.${ ext } ` ] ,
115
+ } ;
110
116
111
- host . writeMultipleFiles ( {
112
- 'src/app/app.component.css' : cssContent ,
113
- 'src/assets/foo.css' : cssContent ,
114
- 'src/styles.css' : cssContent ,
117
+ const cssContent = `
118
+ .foo { color: white; padding: 1px; }
119
+ .buz { color: white; padding: 2px; }
120
+ .bar { color: white; padding: 3px; }
121
+ ` ;
122
+
123
+ host . writeMultipleFiles ( {
124
+ [ `src/app/app.component.${ ext } ` ] : cssContent ,
125
+ [ `src/assets/foo.${ ext } ` ] : cssContent ,
126
+ [ `src/styles.${ ext } ` ] : cssContent ,
127
+ } ) ;
128
+
129
+ host . replaceInFile (
130
+ 'src/app/app.component.ts' ,
131
+ './app.component.css' ,
132
+ `./app.component.${ ext } ` ,
133
+ ) ;
134
+
135
+ const logger = new logging . Logger ( '' ) ;
136
+ const logs : string [ ] = [ ] ;
137
+ logger . subscribe ( e => logs . push ( e . message ) ) ;
138
+
139
+ const run = await architect . scheduleTarget ( targetSpec , overrides , { logger } ) ;
140
+ const output = await run . result ;
141
+ expect ( output . success ) . toBe ( false ) ;
142
+ expect ( logs . length ) . toBe ( 2 ) ;
143
+ expect ( logs . join ( ) ) . toMatch ( `ERROR.+app\.component\.${ ext } ` ) ;
144
+ await run . stop ( ) ;
115
145
} ) ;
116
-
117
- const logger = new logging . Logger ( '' ) ;
118
- const logs : string [ ] = [ ] ;
119
- logger . subscribe ( e => logs . push ( e . message ) ) ;
120
-
121
- const run = await architect . scheduleTarget ( targetSpec , overrides , { logger } ) ;
122
- const output = await run . result ;
123
- expect ( output . success ) . toBe ( false ) ;
124
- expect ( logs . length ) . toBe ( 2 ) ;
125
- expect ( logs . join ( ) ) . toMatch ( / E R R O R .+ a p p \. c o m p o n e n t \. c s s / ) ;
126
- await run . stop ( ) ;
127
146
} ) ;
128
147
129
148
describe ( `should ignore '.map' files` , ( ) => {
0 commit comments