@@ -145,6 +145,44 @@ describe(`Migration to use the application builder`, () => {
145145 expect ( app . architect [ 'build' ] . configurations . production . serviceWorker ) . toBe (
146146 'src/ngsw-config.json' ,
147147 ) ;
148+ expect ( app . architect [ 'build' ] . options . serviceWorker ) . toBeUndefined ( ) ;
149+ } ) ;
150+
151+ it ( `should not enable the service worker when 'serviceWorker' is false` , async ( ) => {
152+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
153+ const workspaceContent = tree . readJson ( '/angular.json' ) as Record < string , any > ;
154+ const build = workspaceContent [ 'projects' ] [ 'app' ] [ 'architect' ] [ 'build' ] ;
155+ build [ 'options' ] [ 'serviceWorker' ] = false ;
156+ build [ 'options' ] [ 'ngswConfigPath' ] = 'src/ngsw-config.json' ;
157+ tree . overwrite ( '/angular.json' , JSON . stringify ( workspaceContent ) ) ;
158+
159+ const newTree = await schematicRunner . runSchematic ( schematicName , { } , tree ) ;
160+ const {
161+ projects : { app } ,
162+ } = JSON . parse ( newTree . readContent ( '/angular.json' ) ) ;
163+
164+ const { serviceWorker, ngswConfigPath } = app . architect [ 'build' ] . options ;
165+ expect ( serviceWorker ) . toBeFalse ( ) ;
166+ expect ( ngswConfigPath ) . toBeUndefined ( ) ;
167+ } ) ;
168+
169+ it ( `should use a configuration 'ngswConfigPath' when the base options enable the service worker` , async ( ) => {
170+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
171+ const workspaceContent = tree . readJson ( '/angular.json' ) as Record < string , any > ;
172+ const build = workspaceContent [ 'projects' ] [ 'app' ] [ 'architect' ] [ 'build' ] ;
173+ build [ 'options' ] [ 'serviceWorker' ] = true ;
174+ build [ 'configurations' ] = { production : { ngswConfigPath : 'src/ngsw-config.prod.json' } } ;
175+ tree . overwrite ( '/angular.json' , JSON . stringify ( workspaceContent ) ) ;
176+
177+ const newTree = await schematicRunner . runSchematic ( schematicName , { } , tree ) ;
178+ const {
179+ projects : { app } ,
180+ } = JSON . parse ( newTree . readContent ( '/angular.json' ) ) ;
181+
182+ expect ( app . architect [ 'build' ] . options . serviceWorker ) . toBe ( '/project/app/ngsw-config.json' ) ;
183+ expect ( app . architect [ 'build' ] . configurations . production . serviceWorker ) . toBe (
184+ 'src/ngsw-config.prod.json' ,
185+ ) ;
148186 } ) ;
149187
150188 it ( `should remove 'builderMode' from karma options` , async ( ) => {
0 commit comments