66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9- import { logging } from '@angular-devkit/core' ;
109import { 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' ;
1217
1318/**
1419 * Maximum time in milliseconds for single build/rebuild
@@ -92,47 +97,31 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
9297 } ,
9398 async ( { result, logs } ) => {
9499 expect ( result ?. success ) . toBeFalse ( ) ;
95- expect ( logs ) . toContain (
96- jasmine . objectContaining < logging . LogEntry > ( {
97- message : jasmine . stringMatching ( typeErrorText ) ,
98- } ) ,
99- ) ;
100+ expectLog ( logs , typeErrorText ) ;
100101
101102 // Make an unrelated change to verify error cache was updated
102103 // Should persist error in the next rebuild
103104 await harness . modifyFile ( 'src/main.ts' , ( content ) => content + '\n' ) ;
104105 } ,
105106 async ( { result, logs } ) => {
106107 expect ( result ?. success ) . toBeFalse ( ) ;
107- expect ( logs ) . toContain (
108- jasmine . objectContaining < logging . LogEntry > ( {
109- message : jasmine . stringMatching ( typeErrorText ) ,
110- } ) ,
111- ) ;
108+ expectLog ( logs , typeErrorText ) ;
112109
113110 // Revert the directive change that caused the error
114111 // Should remove the error
115112 await harness . writeFile ( 'src/app/dir.ts' , goodDirectiveContents ) ;
116113 } ,
117114 async ( { result, logs } ) => {
118115 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 ) ;
124117
125118 // Make an unrelated change to verify error cache was updated
126119 // Should continue showing no error
127120 await harness . modifyFile ( 'src/main.ts' , ( content ) => content + '\n' ) ;
128121 } ,
129122 ( { result, logs } ) => {
130123 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 ) ;
136125 } ,
137126 ] ,
138127 { outputLogsOnFailure : false } ,
@@ -152,78 +141,38 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
152141 await harness . appendToFile ( 'src/app/app.component.html' , '@if-one' ) ;
153142 } ,
154143 async ( { logs } ) => {
155- expect ( logs ) . toContain (
156- jasmine . objectContaining < logging . LogEntry > ( {
157- message : jasmine . stringContaining ( '@if-one' ) ,
158- } ) ,
159- ) ;
144+ expectLog ( logs , '@if-one' ) ;
160145
161146 // Make an unrelated change to verify error cache was updated
162147 // Should persist error in the next rebuild
163148 await harness . modifyFile ( 'src/main.ts' , ( content ) => content + '\n' ) ;
164149 } ,
165150 async ( { logs } ) => {
166- expect ( logs ) . toContain (
167- jasmine . objectContaining < logging . LogEntry > ( {
168- message : jasmine . stringContaining ( '@if-one' ) ,
169- } ) ,
170- ) ;
151+ expectLog ( logs , '@if-one' ) ;
171152
172153 // Add more invalid block syntax
173154 await harness . appendToFile ( 'src/app/app.component.html' , '@if-two' ) ;
174155 } ,
175156 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' ) ;
186159
187160 // Add more invalid block syntax
188161 await harness . appendToFile ( 'src/app/app.component.html' , '@if-three' ) ;
189162 } ,
190163 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' ) ;
206167
207168 // Revert the changes that caused the error
208169 // Should remove the error
209170 await harness . writeFile ( 'src/app/app.component.html' , '<p>GOOD</p>' ) ;
210171 } ,
211172 ( { 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' ) ;
227176 } ,
228177 ] ,
229178 { outputLogsOnFailure : false } ,
@@ -243,20 +192,12 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
243192 await harness . writeFile ( 'src/app/app.component.css' , 'invalid-css-content' ) ;
244193 } ,
245194 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' ) ;
251196
252197 await harness . writeFile ( 'src/app/app.component.css' , 'p { color: green }' ) ;
253198 } ,
254199 ( { 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' ) ;
260201
261202 harness
262203 . expectFile ( 'dist/browser/main.js' )
@@ -280,32 +221,20 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
280221 await harness . appendToFile ( 'src/app/app.component.html' , '<div>Hello, world!</div' ) ;
281222 } ,
282223 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"' ) ;
288225
289226 await harness . appendToFile ( 'src/app/app.component.html' , '>' ) ;
290227 } ,
291228 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"' ) ;
297230
298231 harness . expectFile ( 'dist/browser/main.js' ) . content . toContain ( 'Hello, world!' ) ;
299232
300233 // Make an additional valid change to ensure that rebuilds still trigger
301234 await harness . appendToFile ( 'src/app/app.component.html' , '<div>Guten Tag</div>' ) ;
302235 } ,
303236 ( { 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' ) ;
309238
310239 harness . expectFile ( 'dist/browser/main.js' ) . content . toContain ( 'Hello, world!' ) ;
311240 harness . expectFile ( 'dist/browser/main.js' ) . content . toContain ( 'Guten Tag' ) ;
0 commit comments