@@ -10,70 +10,40 @@ import { ng } from '../../utils/process';
10
10
import { updateJsonFile } from '../../utils/project' ;
11
11
import { expectToFail } from '../../utils/utils' ;
12
12
13
- // tslint:disable:max-line-length
14
- export default function ( ) {
15
- const budgetConfigs = [
16
- {
17
- expectation : 'pass' ,
18
- message : 'BIG max for all, should not error' ,
19
- budget : { type : 'allScript' , maximumError : '100mb' } ,
20
- } ,
21
- {
22
- expectation : 'error' ,
23
- message : 'Budget error: all, max error' ,
24
- budget : { type : 'all' , maximumError : '100b' } ,
25
- } ,
26
- {
27
- expectation : 'warning' ,
28
- message : 'Budget warning: all, min warning' ,
29
- budget : { type : 'all' , minimumWarning : '100mb' } ,
30
- } ,
31
- ] ;
13
+ export default async function ( ) {
14
+ // Error
15
+ await updateJsonFile ( 'angular.json' , json => {
16
+ json . projects [ 'test-project' ] . architect . build . options . budgets = [
17
+ { type : 'all' , maximumError : '100b' } ,
18
+ ] ;
19
+ } ) ;
20
+
21
+ const errorMessage = await expectToFail ( ( ) => ng ( 'build' ) ) ;
22
+ if ( ! / E r r o r .+ b u d g e t / . test ( errorMessage ) ) {
23
+ throw new Error ( 'Budget error: all, max error.' ) ;
24
+ }
32
25
33
- const promiseFactories = budgetConfigs . map ( cfg => {
34
- if ( cfg . expectation === 'error' ) {
35
- return ( ) => {
36
- return updateJsonFile ( 'angular.json' , ( json ) => {
37
- json . projects [ 'test-project' ] . architect . build . options . budgets = [ cfg . budget ] ;
38
- } )
39
- . then ( ( ) => expectToFail ( ( ) => ng ( 'build' , '--optimization' ) ) )
40
- . then ( errorMessage => {
41
- if ( ! / E r r o r .+ b u d g e t s / . test ( errorMessage ) ) {
42
- throw new Error ( cfg . message ) ;
43
- }
44
- } ) ;
45
- } ;
46
- } else if ( cfg . expectation === 'warning' ) {
47
- return ( ) => {
48
- return updateJsonFile ( 'angular.json' , ( json ) => {
49
- json . projects [ 'test-project' ] . architect . build . options . budgets = [ cfg . budget ] ;
50
- } )
51
- . then ( ( ) => ng ( 'build' , '--optimization' ) )
52
- . then ( ( { stderr } ) => {
53
- if ( ! / W a r n i n g .+ b u d g e t s / . test ( stderr ) ) {
54
- throw new Error ( cfg . message ) ;
55
- }
56
- } ) ;
57
- } ;
58
- } else { // pass
59
- return ( ) => {
60
- return updateJsonFile ( 'angular.json' , ( json ) => {
61
- json . projects [ 'test-project' ] . architect . build . options . budgets = [ cfg . budget ] ;
62
- } )
63
- . then ( ( ) => ng ( 'build' , '--optimization' ) )
64
- . then ( ( { stderr } ) => {
65
- if ( / ( W a r n i n g | E r r o r ) / . test ( stderr ) ) {
66
- throw new Error ( cfg . message ) ;
67
- }
68
- } ) ;
69
- } ;
70
- }
26
+ // Warning
27
+ await updateJsonFile ( 'angular.json' , json => {
28
+ json . projects [ 'test-project' ] . architect . build . options . budgets = [
29
+ { type : 'all' , minimumWarning : '100mb' } ,
30
+ ] ;
71
31
} ) ;
72
32
73
- let promiseChain = Promise . resolve ( ) ;
74
- for ( let i = 0 ; i < promiseFactories . length ; i ++ ) {
75
- promiseChain = promiseChain . then ( promiseFactories [ i ] ) ;
33
+ const { stderr } = await ng ( 'build' ) ;
34
+ if ( ! / W a r n i n g . + b u d g e t / . test ( stderr ) ) {
35
+ throw new Error ( 'Budget warning: all, min warning' ) ;
76
36
}
77
37
78
- return promiseChain ;
38
+ // Pass
39
+ await updateJsonFile ( 'angular.json' , json => {
40
+ json . projects [ 'test-project' ] . architect . build . options . budgets = [
41
+ { type : 'allScript' , maximumError : '100mb' } ,
42
+ ] ;
43
+ } ) ;
44
+
45
+ const { stderr : stderr2 } = await ng ( 'build' ) ;
46
+ if ( / ( W a r n i n g | E r r o r ) / . test ( stderr2 ) ) {
47
+ throw new Error ( 'BIG max for all, should not error' ) ;
48
+ }
79
49
}
0 commit comments