6
6
* found in the LICENSE file at https://angular.dev/license
7
7
*/
8
8
9
- import { logging } from '@angular-devkit/core' ;
10
9
import { buildApplication } from '../../index' ;
11
- import { APPLICATION_BUILDER_INFO , BASE_OPTIONS , describeBuilder } from '../setup' ;
10
+ import {
11
+ APPLICATION_BUILDER_INFO ,
12
+ BASE_OPTIONS ,
13
+ describeBuilder ,
14
+ expectLog ,
15
+ expectNoLog ,
16
+ } from '../setup' ;
12
17
13
18
/**
14
19
* Maximum time in milliseconds for single build/rebuild
@@ -92,47 +97,31 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
92
97
} ,
93
98
async ( { result, logs } ) => {
94
99
expect ( result ?. success ) . toBeFalse ( ) ;
95
- expect ( logs ) . toContain (
96
- jasmine . objectContaining < logging . LogEntry > ( {
97
- message : jasmine . stringMatching ( typeErrorText ) ,
98
- } ) ,
99
- ) ;
100
+ expectLog ( logs , typeErrorText ) ;
100
101
101
102
// Make an unrelated change to verify error cache was updated
102
103
// Should persist error in the next rebuild
103
104
await harness . modifyFile ( 'src/main.ts' , ( content ) => content + '\n' ) ;
104
105
} ,
105
106
async ( { result, logs } ) => {
106
107
expect ( result ?. success ) . toBeFalse ( ) ;
107
- expect ( logs ) . toContain (
108
- jasmine . objectContaining < logging . LogEntry > ( {
109
- message : jasmine . stringMatching ( typeErrorText ) ,
110
- } ) ,
111
- ) ;
108
+ expectLog ( logs , typeErrorText ) ;
112
109
113
110
// Revert the directive change that caused the error
114
111
// Should remove the error
115
112
await harness . writeFile ( 'src/app/dir.ts' , goodDirectiveContents ) ;
116
113
} ,
117
114
async ( { result, logs } ) => {
118
115
expect ( result ?. success ) . toBeTrue ( ) ;
119
- expect ( logs ) . not . toContain (
120
- jasmine . objectContaining < logging . LogEntry > ( {
121
- message : jasmine . stringMatching ( typeErrorText ) ,
122
- } ) ,
123
- ) ;
116
+ expectNoLog ( logs , typeErrorText ) ;
124
117
125
118
// Make an unrelated change to verify error cache was updated
126
119
// Should continue showing no error
127
120
await harness . modifyFile ( 'src/main.ts' , ( content ) => content + '\n' ) ;
128
121
} ,
129
122
( { result, logs } ) => {
130
123
expect ( result ?. success ) . toBeTrue ( ) ;
131
- expect ( logs ) . not . toContain (
132
- jasmine . objectContaining < logging . LogEntry > ( {
133
- message : jasmine . stringMatching ( typeErrorText ) ,
134
- } ) ,
135
- ) ;
124
+ expectNoLog ( logs , typeErrorText ) ;
136
125
} ,
137
126
] ,
138
127
{ outputLogsOnFailure : false } ,
@@ -152,78 +141,38 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
152
141
await harness . appendToFile ( 'src/app/app.component.html' , '@if-one' ) ;
153
142
} ,
154
143
async ( { logs } ) => {
155
- expect ( logs ) . toContain (
156
- jasmine . objectContaining < logging . LogEntry > ( {
157
- message : jasmine . stringContaining ( '@if-one' ) ,
158
- } ) ,
159
- ) ;
144
+ expectLog ( logs , '@if-one' ) ;
160
145
161
146
// Make an unrelated change to verify error cache was updated
162
147
// Should persist error in the next rebuild
163
148
await harness . modifyFile ( 'src/main.ts' , ( content ) => content + '\n' ) ;
164
149
} ,
165
150
async ( { logs } ) => {
166
- expect ( logs ) . toContain (
167
- jasmine . objectContaining < logging . LogEntry > ( {
168
- message : jasmine . stringContaining ( '@if-one' ) ,
169
- } ) ,
170
- ) ;
151
+ expectLog ( logs , '@if-one' ) ;
171
152
172
153
// Add more invalid block syntax
173
154
await harness . appendToFile ( 'src/app/app.component.html' , '@if-two' ) ;
174
155
} ,
175
156
async ( { logs } ) => {
176
- expect ( logs ) . toContain (
177
- jasmine . objectContaining < logging . LogEntry > ( {
178
- message : jasmine . stringContaining ( '@if-one' ) ,
179
- } ) ,
180
- ) ;
181
- expect ( logs ) . toContain (
182
- jasmine . objectContaining < logging . LogEntry > ( {
183
- message : jasmine . stringContaining ( '@if-two' ) ,
184
- } ) ,
185
- ) ;
157
+ expectLog ( logs , '@if-one' ) ;
158
+ expectLog ( logs , '@if-two' ) ;
186
159
187
160
// Add more invalid block syntax
188
161
await harness . appendToFile ( 'src/app/app.component.html' , '@if-three' ) ;
189
162
} ,
190
163
async ( { logs } ) => {
191
- expect ( logs ) . toContain (
192
- jasmine . objectContaining < logging . LogEntry > ( {
193
- message : jasmine . stringContaining ( '@if-one' ) ,
194
- } ) ,
195
- ) ;
196
- expect ( logs ) . toContain (
197
- jasmine . objectContaining < logging . LogEntry > ( {
198
- message : jasmine . stringContaining ( '@if-two' ) ,
199
- } ) ,
200
- ) ;
201
- expect ( logs ) . toContain (
202
- jasmine . objectContaining < logging . LogEntry > ( {
203
- message : jasmine . stringContaining ( '@if-three' ) ,
204
- } ) ,
205
- ) ;
164
+ expectLog ( logs , '@if-one' ) ;
165
+ expectLog ( logs , '@if-two' ) ;
166
+ expectLog ( logs , '@if-three' ) ;
206
167
207
168
// Revert the changes that caused the error
208
169
// Should remove the error
209
170
await harness . writeFile ( 'src/app/app.component.html' , '<p>GOOD</p>' ) ;
210
171
} ,
211
172
( { logs } ) => {
212
- expect ( logs ) . not . toContain (
213
- jasmine . objectContaining < logging . LogEntry > ( {
214
- message : jasmine . stringContaining ( '@if-one' ) ,
215
- } ) ,
216
- ) ;
217
- expect ( logs ) . not . toContain (
218
- jasmine . objectContaining < logging . LogEntry > ( {
219
- message : jasmine . stringContaining ( '@if-two' ) ,
220
- } ) ,
221
- ) ;
222
- expect ( logs ) . not . toContain (
223
- jasmine . objectContaining < logging . LogEntry > ( {
224
- message : jasmine . stringContaining ( '@if-three' ) ,
225
- } ) ,
226
- ) ;
173
+ expectNoLog ( logs , '@if-one' ) ;
174
+ expectNoLog ( logs , '@if-two' ) ;
175
+ expectNoLog ( logs , '@if-three' ) ;
227
176
} ,
228
177
] ,
229
178
{ outputLogsOnFailure : false } ,
@@ -243,20 +192,12 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
243
192
await harness . writeFile ( 'src/app/app.component.css' , 'invalid-css-content' ) ;
244
193
} ,
245
194
async ( { logs } ) => {
246
- expect ( logs ) . toContain (
247
- jasmine . objectContaining < logging . LogEntry > ( {
248
- message : jasmine . stringMatching ( 'invalid-css-content' ) ,
249
- } ) ,
250
- ) ;
195
+ expectLog ( logs , 'invalid-css-content' ) ;
251
196
252
197
await harness . writeFile ( 'src/app/app.component.css' , 'p { color: green }' ) ;
253
198
} ,
254
199
( { logs } ) => {
255
- expect ( logs ) . not . toContain (
256
- jasmine . objectContaining < logging . LogEntry > ( {
257
- message : jasmine . stringMatching ( 'invalid-css-content' ) ,
258
- } ) ,
259
- ) ;
200
+ expectNoLog ( logs , 'invalid-css-content' ) ;
260
201
261
202
harness
262
203
. expectFile ( 'dist/browser/main.js' )
@@ -280,32 +221,20 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
280
221
await harness . appendToFile ( 'src/app/app.component.html' , '<div>Hello, world!</div' ) ;
281
222
} ,
282
223
async ( { logs } ) => {
283
- expect ( logs ) . toContain (
284
- jasmine . objectContaining < logging . LogEntry > ( {
285
- message : jasmine . stringMatching ( 'Unexpected character "EOF"' ) ,
286
- } ) ,
287
- ) ;
224
+ expectLog ( logs , 'Unexpected character "EOF"' ) ;
288
225
289
226
await harness . appendToFile ( 'src/app/app.component.html' , '>' ) ;
290
227
} ,
291
228
async ( { logs } ) => {
292
- expect ( logs ) . not . toContain (
293
- jasmine . objectContaining < logging . LogEntry > ( {
294
- message : jasmine . stringMatching ( 'Unexpected character "EOF"' ) ,
295
- } ) ,
296
- ) ;
229
+ expectNoLog ( logs , 'Unexpected character "EOF"' ) ;
297
230
298
231
harness . expectFile ( 'dist/browser/main.js' ) . content . toContain ( 'Hello, world!' ) ;
299
232
300
233
// Make an additional valid change to ensure that rebuilds still trigger
301
234
await harness . appendToFile ( 'src/app/app.component.html' , '<div>Guten Tag</div>' ) ;
302
235
} ,
303
236
( { logs } ) => {
304
- expect ( logs ) . not . toContain (
305
- jasmine . objectContaining < logging . LogEntry > ( {
306
- message : jasmine . stringMatching ( 'invalid-css-content' ) ,
307
- } ) ,
308
- ) ;
237
+ expectNoLog ( logs , 'invalid-css-content' ) ;
309
238
310
239
harness . expectFile ( 'dist/browser/main.js' ) . content . toContain ( 'Hello, world!' ) ;
311
240
harness . expectFile ( 'dist/browser/main.js' ) . content . toContain ( 'Guten Tag' ) ;
0 commit comments