@@ -7,6 +7,13 @@ proxyquire.noCallThru();
77
88class EmptyClass { } ;
99
10+ let angularCompilerOptions : any ;
11+ class AngularCompilerStub {
12+ constructor ( options ) {
13+ angularCompilerOptions = options ;
14+ }
15+ } ;
16+
1017const nativeScriptDevWebpack = {
1118 GenerateBundleStarterPlugin : EmptyClass ,
1219 WatchStateLoggerPlugin : EmptyClass ,
@@ -18,15 +25,18 @@ const nativeScriptDevWebpack = {
1825} ;
1926
2027const emptyObject = { } ;
21-
28+ const FakeAotTransformerFlag = "aot" ;
29+ const FakeHmrTransformerFlag = "hmr" ;
30+ const FakeLazyTransformerFlag = "lazy" ;
2231const webpackConfigAngular = proxyquire ( './webpack.angular' , {
2332 'nativescript-dev-webpack' : nativeScriptDevWebpack ,
2433 'nativescript-dev-webpack/nativescript-target' : emptyObject ,
25- 'nativescript-dev-webpack/transformers/ns-replace-bootstrap' : emptyObject ,
26- 'nativescript-dev-webpack/transformers/ns-replace-lazy-loader' : emptyObject ,
27- 'nativescript-dev-webpack/utils/ast-utils' : emptyObject ,
34+ 'nativescript-dev-webpack/transformers/ns-replace-bootstrap' : { nsReplaceBootstrap : ( ) => { return FakeAotTransformerFlag } } ,
35+ 'nativescript-dev-webpack/transformers/ns-replace-lazy-loader' : { nsReplaceLazyLoader : ( ) => { return FakeLazyTransformerFlag } } ,
36+ 'nativescript-dev-webpack/transformers/ns-support-hmr-ng' : { nsSupportHmrNg : ( ) => { return FakeHmrTransformerFlag } } ,
37+ 'nativescript-dev-webpack/utils/ast-utils' : { getMainModulePath : ( ) => { return "fakePath" ; } } ,
2838 '@ngtools/webpack' : {
29- AngularCompilerPlugin : EmptyClass
39+ AngularCompilerPlugin : AngularCompilerStub
3040 }
3141} ) ;
3242
@@ -48,6 +58,12 @@ const webpackConfigVue = proxyquire('./webpack.vue', {
4858} ) ;
4959
5060describe ( 'webpack.config.js' , ( ) => {
61+ const getInput = ( options : { platform : string , aot ?: boolean , hmr ?: boolean , externals ?: string [ ] } ) => {
62+ const input : any = { aot : options . aot , hmr : options . hmr , externals : options . externals } ;
63+ input [ options . platform ] = true ;
64+ return input ;
65+ } ;
66+
5167 [
5268 { type : 'javascript' , webpackConfig : webpackConfigJavaScript } ,
5369 { type : 'typescript' , webpackConfig : webpackConfigTypeScript } ,
@@ -57,12 +73,6 @@ describe('webpack.config.js', () => {
5773 const { type, webpackConfig } = element ;
5874
5975 describe ( `verify externals for webpack.${ type } .js` , ( ) => {
60- const getInput = ( platform : string , externals : string [ ] ) => {
61- const input : any = { externals } ;
62- input [ platform ] = true ;
63- return input ;
64- } ;
65-
6676 [
6777 'android' ,
6878 'ios'
@@ -73,7 +83,7 @@ describe('webpack.config.js', () => {
7383 } ) ;
7484
7585 it ( 'returns empty array when externals are not passed' , ( ) => {
76- const config = webpackConfig ( getInput ( platform , null ) ) ;
86+ const config = webpackConfig ( getInput ( { platform } ) ) ;
7787 expect ( config . externals ) . toEqual ( [ ] ) ;
7888 } ) ;
7989
@@ -84,7 +94,7 @@ describe('webpack.config.js', () => {
8494 return [ ] ;
8595 } ;
8696
87- const input = getInput ( platform , [ 'nativescript-vue' ] ) ;
97+ const input = getInput ( { platform, externals : [ 'nativescript-vue' ] } ) ;
8898 webpackConfig ( input ) ;
8999 expect ( isCalled ) . toBe ( true , 'Webpack.config.js must use the getConvertedExternals method' ) ;
90100 } ) ;
@@ -99,7 +109,7 @@ describe('webpack.config.js', () => {
99109 expectedOutput : [ / ^ n a t i v e s c r i p t - v u e ( ( \/ .* ) | $ ) / , / ^ n a t i v e s c r i p t - a n g u l a r ( ( \/ .* ) | $ ) / ]
100110 } ,
101111 ] . forEach ( testCase => {
102- const input = getInput ( platform , testCase . input ) ;
112+ const input = getInput ( { platform, externals : testCase . input } ) ;
103113
104114 it ( `are correct regular expressions, for input ${ testCase . input } ` , ( ) => {
105115 const config = webpackConfig ( input ) ;
@@ -110,4 +120,133 @@ describe('webpack.config.js', () => {
110120 } ) ;
111121 } ) ;
112122 } ) ;
123+
124+ [
125+ 'android' ,
126+ 'ios'
127+ ] . forEach ( platform => {
128+ describe ( `angular transformers (${ platform } )` , ( ) => {
129+
130+ beforeEach ( ( ) => {
131+ angularCompilerOptions = null ;
132+ } ) ;
133+
134+ it ( "should be empty by default" , ( ) => {
135+ const input = getInput ( { platform } ) ;
136+
137+ webpackConfigAngular ( input ) ;
138+
139+ expect ( angularCompilerOptions ) . toBeDefined ( ) ;
140+ expect ( angularCompilerOptions . platformTransformers ) . toBeDefined ( ) ;
141+ expect ( angularCompilerOptions . platformTransformers . length ) . toEqual ( 0 ) ;
142+ } ) ;
143+
144+ it ( "should contain the AOT transformer when the AOT flag is passed" , ( ) => {
145+ const input = getInput ( { platform, aot : true } ) ;
146+
147+ webpackConfigAngular ( input ) ;
148+
149+ expect ( angularCompilerOptions ) . toBeDefined ( ) ;
150+ expect ( angularCompilerOptions . platformTransformers ) . toBeDefined ( ) ;
151+ expect ( angularCompilerOptions . platformTransformers . length ) . toEqual ( 1 ) ;
152+ expect ( angularCompilerOptions . platformTransformers [ 0 ] ) . toEqual ( FakeAotTransformerFlag ) ;
153+ } ) ;
154+
155+ it ( "should contain the HMR transformer when the HMR flag is passed" , ( ) => {
156+ const input = getInput ( { platform, hmr : true } ) ;
157+
158+ webpackConfigAngular ( input ) ;
159+
160+ expect ( angularCompilerOptions ) . toBeDefined ( ) ;
161+ expect ( angularCompilerOptions . platformTransformers ) . toBeDefined ( ) ;
162+ expect ( angularCompilerOptions . platformTransformers . length ) . toEqual ( 1 ) ;
163+ expect ( angularCompilerOptions . platformTransformers [ 0 ] ) . toEqual ( FakeHmrTransformerFlag ) ;
164+ } ) ;
165+
166+ it ( "should contain the Lazy transformer when the @angular/core is an external module" , ( ) => {
167+ const input = getInput ( { platform, externals : [ "@angular/core" ] } ) ;
168+
169+ webpackConfigAngular ( input ) ;
170+
171+ expect ( angularCompilerOptions ) . toBeDefined ( ) ;
172+ expect ( angularCompilerOptions . platformTransformers ) . toBeDefined ( ) ;
173+ expect ( angularCompilerOptions . platformTransformers . length ) . toEqual ( 1 ) ;
174+ expect ( angularCompilerOptions . platformTransformers [ 0 ] ) . toEqual ( FakeLazyTransformerFlag ) ;
175+ } ) ;
176+
177+ it ( "should contain the AOT + HMR transformers when the AOT and HMR flags are passed" , ( ) => {
178+ const input = getInput ( { platform, aot : true , hmr : true } ) ;
179+
180+ webpackConfigAngular ( input ) ;
181+
182+ expect ( angularCompilerOptions ) . toBeDefined ( ) ;
183+ expect ( angularCompilerOptions . platformTransformers ) . toBeDefined ( ) ;
184+ expect ( angularCompilerOptions . platformTransformers . length ) . toEqual ( 2 ) ;
185+ expect ( angularCompilerOptions . platformTransformers ) . toContain ( FakeAotTransformerFlag ) ;
186+ expect ( angularCompilerOptions . platformTransformers ) . toContain ( FakeHmrTransformerFlag ) ;
187+ } ) ;
188+
189+ it ( "should set the AOT transformer before the HMR one when the AOT and HMR flags are passed" , ( ) => {
190+ const input = getInput ( { platform, aot : true , hmr : true } ) ;
191+
192+ webpackConfigAngular ( input ) ;
193+
194+ expect ( angularCompilerOptions ) . toBeDefined ( ) ;
195+ expect ( angularCompilerOptions . platformTransformers ) . toBeDefined ( ) ;
196+ expect ( angularCompilerOptions . platformTransformers . length ) . toEqual ( 2 ) ;
197+ expect ( angularCompilerOptions . platformTransformers [ 0 ] ) . toEqual ( FakeAotTransformerFlag ) ;
198+ expect ( angularCompilerOptions . platformTransformers [ 1 ] ) . toEqual ( FakeHmrTransformerFlag ) ;
199+ } ) ;
200+
201+ it ( "should contain the AOT + Lazy transformers when the AOT flag is passed and @angular/core is an external module" , ( ) => {
202+ const input = getInput ( { platform, aot : true , externals : [ "@angular/core" ] } ) ;
203+
204+ webpackConfigAngular ( input ) ;
205+
206+ expect ( angularCompilerOptions ) . toBeDefined ( ) ;
207+ expect ( angularCompilerOptions . platformTransformers ) . toBeDefined ( ) ;
208+ expect ( angularCompilerOptions . platformTransformers . length ) . toEqual ( 2 ) ;
209+ expect ( angularCompilerOptions . platformTransformers ) . toContain ( FakeAotTransformerFlag ) ;
210+ expect ( angularCompilerOptions . platformTransformers ) . toContain ( FakeLazyTransformerFlag ) ;
211+ } ) ;
212+
213+ it ( "should contain the HMR + Lazy transformers when the HMR flag is passed and @angular/core is an external module" , ( ) => {
214+ const input = getInput ( { platform, hmr : true , externals : [ "@angular/core" ] } ) ;
215+
216+ webpackConfigAngular ( input ) ;
217+
218+ expect ( angularCompilerOptions ) . toBeDefined ( ) ;
219+ expect ( angularCompilerOptions . platformTransformers ) . toBeDefined ( ) ;
220+ expect ( angularCompilerOptions . platformTransformers . length ) . toEqual ( 2 ) ;
221+ expect ( angularCompilerOptions . platformTransformers ) . toContain ( FakeHmrTransformerFlag ) ;
222+ expect ( angularCompilerOptions . platformTransformers ) . toContain ( FakeLazyTransformerFlag ) ;
223+ } ) ;
224+
225+ it ( "should contain the AOT + HMR + Lazy transformers when the AOT and HMR flags are passed and @angular/core is an external module" , ( ) => {
226+ const input = getInput ( { platform, aot : true , hmr : true , externals : [ "@angular/core" ] } ) ;
227+
228+ webpackConfigAngular ( input ) ;
229+
230+ expect ( angularCompilerOptions ) . toBeDefined ( ) ;
231+ expect ( angularCompilerOptions . platformTransformers ) . toBeDefined ( ) ;
232+ expect ( angularCompilerOptions . platformTransformers . length ) . toEqual ( 3 ) ;
233+ expect ( angularCompilerOptions . platformTransformers ) . toContain ( FakeAotTransformerFlag ) ;
234+ expect ( angularCompilerOptions . platformTransformers ) . toContain ( FakeHmrTransformerFlag ) ;
235+ expect ( angularCompilerOptions . platformTransformers ) . toContain ( FakeLazyTransformerFlag ) ;
236+ } ) ;
237+
238+ it ( "should contain the AOT + HMR + Lazy transformers in the proper order when the AOT and HMR flags are passed and @angular/core is an external module" , ( ) => {
239+ const input = getInput ( { platform, aot : true , hmr : true , externals : [ "@angular/core" ] } ) ;
240+
241+ webpackConfigAngular ( input ) ;
242+
243+ expect ( angularCompilerOptions ) . toBeDefined ( ) ;
244+ expect ( angularCompilerOptions . platformTransformers ) . toBeDefined ( ) ;
245+ expect ( angularCompilerOptions . platformTransformers . length ) . toEqual ( 3 ) ;
246+ expect ( angularCompilerOptions . platformTransformers [ 0 ] ) . toEqual ( FakeAotTransformerFlag ) ;
247+ expect ( angularCompilerOptions . platformTransformers [ 1 ] ) . toEqual ( FakeHmrTransformerFlag ) ;
248+ expect ( angularCompilerOptions . platformTransformers [ 2 ] ) . toEqual ( FakeLazyTransformerFlag ) ;
249+ } ) ;
250+ } ) ;
251+ } ) ;
113252} ) ;
0 commit comments