@@ -14,7 +14,14 @@ import * as transpile from './transpile';
14
14
describe ( 'build' , ( ) => {
15
15
beforeEach ( ( ) => {
16
16
spyOn ( clean , 'clean' ) ;
17
- spyOn ( helpers , 'readFileAsync' ) . and . returnValue ( Promise . resolve ( ) ) ;
17
+ spyOn ( helpers , 'readFileAsync' ) . and . callFake ( ( ) => {
18
+ return Promise . resolve ( `{
19
+ "compilerOptions": {
20
+ "sourceMap": true
21
+ }
22
+ }
23
+ ` ) ;
24
+ } ) ;
18
25
spyOn ( copy , 'copy' ) . and . returnValue ( Promise . resolve ( ) ) ;
19
26
spyOn ( ngc , 'ngc' ) . and . returnValue ( Promise . resolve ( ) ) ;
20
27
spyOn ( bundle , 'bundle' ) . and . returnValue ( Promise . resolve ( ) ) ;
@@ -26,56 +33,150 @@ describe('build', () => {
26
33
} ) ;
27
34
28
35
it ( 'should do a prod build' , ( ) => {
29
- let context : BuildContext = {
30
- isProd : true ,
31
- optimizeJs : true ,
32
- runMinifyJs : true ,
33
- runMinifyCss : true ,
34
- runAot : true
35
- } ;
36
-
37
- return build . build ( context ) . then ( ( ) => {
38
- expect ( helpers . readFileAsync ) . toHaveBeenCalled ( ) ;
39
- expect ( copy . copy ) . toHaveBeenCalled ( ) ;
40
- expect ( ngc . ngc ) . toHaveBeenCalled ( ) ;
41
- expect ( bundle . bundle ) . toHaveBeenCalled ( ) ;
42
- expect ( minify . minifyJs ) . toHaveBeenCalled ( ) ;
43
- expect ( sass . sass ) . toHaveBeenCalled ( ) ;
44
- expect ( minify . minifyCss ) . toHaveBeenCalled ( ) ;
45
- expect ( lint . lint ) . toHaveBeenCalled ( ) ;
46
-
47
- expect ( transpile . transpile ) . not . toHaveBeenCalled ( ) ;
48
- } ) . catch ( err => {
49
- console . log ( `err.message: ` , err . message ) ;
50
- expect ( true ) . toEqual ( false ) ;
51
- } ) ;
36
+ let context : BuildContext = {
37
+ isProd : true ,
38
+ optimizeJs : true ,
39
+ runMinifyJs : true ,
40
+ runMinifyCss : true ,
41
+ runAot : true
42
+ } ;
43
+
44
+ return build . build ( context ) . then ( ( ) => {
45
+ expect ( helpers . readFileAsync ) . toHaveBeenCalled ( ) ;
46
+ expect ( copy . copy ) . toHaveBeenCalled ( ) ;
47
+ expect ( ngc . ngc ) . toHaveBeenCalled ( ) ;
48
+ expect ( bundle . bundle ) . toHaveBeenCalled ( ) ;
49
+ expect ( minify . minifyJs ) . toHaveBeenCalled ( ) ;
50
+ expect ( sass . sass ) . toHaveBeenCalled ( ) ;
51
+ expect ( minify . minifyCss ) . toHaveBeenCalled ( ) ;
52
+ expect ( lint . lint ) . toHaveBeenCalled ( ) ;
53
+
54
+ expect ( transpile . transpile ) . not . toHaveBeenCalled ( ) ;
55
+ } ) . catch ( err => {
56
+ console . log ( `err.message: ` , err . message ) ;
57
+ expect ( true ) . toEqual ( false ) ;
58
+ } ) ;
59
+ } ) ;
60
+
61
+ it ( 'should do a dev build' , ( ) => {
62
+ let context : BuildContext = {
63
+ isProd : false ,
64
+ optimizeJs : false ,
65
+ runMinifyJs : false ,
66
+ runMinifyCss : false ,
67
+ runAot : false
68
+ } ;
69
+
70
+ return build . build ( context ) . then ( ( ) => {
71
+ expect ( helpers . readFileAsync ) . toHaveBeenCalled ( ) ;
72
+ expect ( copy . copy ) . toHaveBeenCalled ( ) ;
73
+ expect ( transpile . transpile ) . toHaveBeenCalled ( ) ;
74
+ expect ( bundle . bundle ) . toHaveBeenCalled ( ) ;
75
+ expect ( sass . sass ) . toHaveBeenCalled ( ) ;
76
+ expect ( lint . lint ) . toHaveBeenCalled ( ) ;
77
+
78
+ expect ( ngc . ngc ) . not . toHaveBeenCalled ( ) ;
79
+ expect ( minify . minifyJs ) . not . toHaveBeenCalled ( ) ;
80
+ expect ( minify . minifyCss ) . not . toHaveBeenCalled ( ) ;
81
+ } ) . catch ( err => {
82
+ console . log ( `err.message: ` , err . message ) ;
83
+ expect ( true ) . toEqual ( false ) ;
84
+ } ) ;
85
+ } ) ;
86
+ } ) ;
87
+
88
+ describe ( 'test project requirements before building' , ( ) => {
89
+ it ( 'should fail if APP_ENTRY_POINT file does not exist' , ( ) => {
90
+ process . env . IONIC_APP_ENTRY_POINT = 'src/app/main.ts' ;
91
+ process . env . IONIC_TS_CONFIG = 'tsConfig.js' ;
92
+ const error = new Error ( 'App entry point was not found' ) ;
93
+
94
+ spyOn ( helpers , 'readFileAsync' ) . and . returnValue ( Promise . reject ( error ) ) ;
95
+
96
+ return build . build ( { } ) . catch ( ( e ) => {
97
+ expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 2 ) ;
98
+ expect ( e ) . toEqual ( error ) ;
52
99
} ) ;
100
+ } ) ;
101
+
102
+ it ( 'should fail if IONIC_TS_CONFIG file does not exist' , ( ) => {
103
+ process . env . IONIC_APP_ENTRY_POINT = 'src/app/main.ts' ;
104
+ process . env . IONIC_TS_CONFIG = 'tsConfig.js' ;
105
+ const error = new Error ( 'App entry point was not found' ) ;
53
106
54
- it ( 'should do a dev build' , ( done : Function ) => {
55
- let context : BuildContext = {
56
- isProd : false ,
57
- optimizeJs : false ,
58
- runMinifyJs : false ,
59
- runMinifyCss : false ,
60
- runAot : false
61
- } ;
62
-
63
- build . build ( context ) . then ( ( ) => {
64
- expect ( helpers . readFileAsync ) . toHaveBeenCalled ( ) ;
65
- expect ( copy . copy ) . toHaveBeenCalled ( ) ;
66
- expect ( transpile . transpile ) . toHaveBeenCalled ( ) ;
67
- expect ( bundle . bundle ) . toHaveBeenCalled ( ) ;
68
- expect ( sass . sass ) . toHaveBeenCalled ( ) ;
69
- expect ( lint . lint ) . toHaveBeenCalled ( ) ;
70
-
71
- expect ( ngc . ngc ) . not . toHaveBeenCalled ( ) ;
72
- expect ( minify . minifyJs ) . not . toHaveBeenCalled ( ) ;
73
- expect ( minify . minifyCss ) . not . toHaveBeenCalled ( ) ;
74
- done ( ) ;
75
- } ) . catch ( err => {
76
- console . log ( `err.message: ` , err . message ) ;
77
- expect ( true ) . toEqual ( false ) ;
78
- } ) ;
107
+ spyOn ( helpers , 'readFileAsync' ) . and . callFake ( ( filePath : string ) => {
108
+ if ( filePath === 'src/app/main.ts' ) {
109
+ return Promise . resolve ( 'allgood' ) ;
110
+ }
111
+ return Promise . reject ( error ) ;
79
112
} ) ;
80
113
114
+ return build . build ( { } ) . catch ( ( e ) => {
115
+ expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 2 ) ;
116
+ expect ( e ) . toEqual ( error ) ;
117
+ } ) ;
118
+ } ) ;
119
+
120
+ it ( 'should fail fataly if IONIC_TS_CONFIG file does not contain valid JSON' , ( ) => {
121
+ process . env . IONIC_APP_ENTRY_POINT = 'src/app/main.ts' ;
122
+ process . env . IONIC_TS_CONFIG = 'tsConfig.js' ;
123
+ spyOn ( helpers , 'readFileAsync' ) . and . callFake ( ( ) => {
124
+ return Promise . resolve ( `{
125
+ "compilerOptions" {
126
+ "sourceMap": false
127
+ }
128
+ }
129
+ ` ) ;
130
+ } ) ;
131
+
132
+ return build . build ( { } ) . catch ( ( e ) => {
133
+ expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 2 ) ;
134
+ expect ( e . isFatal ) . toBeTruthy ( ) ;
135
+ } ) ;
136
+ } ) ;
137
+
138
+ it ( 'should fail fataly if IONIC_TS_CONFIG file does not contain compilerOptions.sourceMap === true' , ( ) => {
139
+ process . env . IONIC_APP_ENTRY_POINT = 'src/app/main.ts' ;
140
+ process . env . IONIC_TS_CONFIG = 'tsConfig.js' ;
141
+ spyOn ( helpers , 'readFileAsync' ) . and . callFake ( ( ) => {
142
+ return Promise . resolve ( `{
143
+ "compilerOptions": {
144
+ "sourceMap": false
145
+ }
146
+ }
147
+ ` ) ;
148
+ } ) ;
149
+
150
+ return build . build ( { } ) . catch ( ( e ) => {
151
+ expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 2 ) ;
152
+ expect ( e . isFatal ) . toBeTruthy ( ) ;
153
+ } ) ;
154
+ } ) ;
155
+
156
+ it ( 'should succeed if IONIC_TS_CONFIG file contains compilerOptions.sourceMap === true' , ( ) => {
157
+ process . env . IONIC_APP_ENTRY_POINT = 'src/app/main.ts' ;
158
+ process . env . IONIC_TS_CONFIG = 'tsConfig.js' ;
159
+
160
+ spyOn ( clean , 'clean' ) ;
161
+ spyOn ( copy , 'copy' ) . and . returnValue ( Promise . resolve ( ) ) ;
162
+ spyOn ( ngc , 'ngc' ) . and . returnValue ( Promise . resolve ( ) ) ;
163
+ spyOn ( bundle , 'bundle' ) . and . returnValue ( Promise . resolve ( ) ) ;
164
+ spyOn ( minify , 'minifyJs' ) . and . returnValue ( Promise . resolve ( ) ) ;
165
+ spyOn ( sass , 'sass' ) . and . returnValue ( Promise . resolve ( ) ) ;
166
+ spyOn ( minify , 'minifyCss' ) . and . returnValue ( Promise . resolve ( ) ) ;
167
+ spyOn ( lint , 'lint' ) . and . returnValue ( Promise . resolve ( ) ) ;
168
+ spyOn ( transpile , 'transpile' ) . and . returnValue ( Promise . resolve ( ) ) ;
169
+ spyOn ( helpers , 'readFileAsync' ) . and . callFake ( ( ) => {
170
+ return Promise . resolve ( `{
171
+ "compilerOptions": {
172
+ "sourceMap": true
173
+ }
174
+ }
175
+ ` ) ;
176
+ } ) ;
177
+
178
+ return build . build ( { } ) . then ( ( ) => {
179
+ expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 2 ) ;
180
+ } ) ;
181
+ } ) ;
81
182
} ) ;
0 commit comments