@@ -9,10 +9,39 @@ export default async function () {
9
9
await expectFileToExist ( join ( process . cwd ( ) , 'src/manifest.webmanifest' ) ) ;
10
10
11
11
// Angular PWA doesn't install as a dependency
12
- const { dependencies, devDependencies } = JSON . parse ( await readFile ( join ( process . cwd ( ) , 'package.json' ) ) ) ;
13
- const hasPWADep = Object . keys ( { ...dependencies , ...devDependencies } )
14
- . some ( d => d === '@angular/pwa' ) ;
12
+ const { dependencies, devDependencies } = JSON . parse (
13
+ await readFile ( join ( process . cwd ( ) , 'package.json' ) ) ,
14
+ ) ;
15
+ const hasPWADep = Object . keys ( { ...dependencies , ...devDependencies } ) . some (
16
+ ( d ) => d === '@angular/pwa' ,
17
+ ) ;
15
18
if ( hasPWADep ) {
16
19
throw new Error ( `Expected 'package.json' not to contain a dependency on '@angular/pwa'.` ) ;
17
20
}
21
+
22
+ // It should generate a SW configuration file (`ngsw.json`).
23
+ const workspaceJson = JSON . parse ( await readFile ( 'angular.json' ) ) ;
24
+ const outputPath = workspaceJson . projects [ 'test-project' ] . architect . build . options . outputPath ;
25
+ const ngswPath = join ( process . cwd ( ) , outputPath , 'ngsw.json' ) ;
26
+
27
+ await ng ( 'build' ) ;
28
+ await expectFileToExist ( ngswPath ) ;
29
+
30
+ // It should correctly generate assetGroups and include at least one URL in each group.
31
+ const ngswJson = JSON . parse ( await readFile ( ngswPath ) ) ;
32
+ const assetGroups = ngswJson . assetGroups . map ( ( { name, urls } ) => ( {
33
+ name,
34
+ urlCount : urls . length ,
35
+ } ) ) ;
36
+ const emptyAssetGroups = assetGroups . filter ( ( { urlCount } ) => urlCount === 0 ) ;
37
+
38
+ if ( assetGroups . length === 0 ) {
39
+ throw new Error ( "Expected 'ngsw.json' to contain at least one asset-group." ) ;
40
+ }
41
+ if ( emptyAssetGroups . length > 0 ) {
42
+ throw new Error (
43
+ 'Expected all asset-groups to contain at least one URL, but the following groups are empty: ' +
44
+ emptyAssetGroups . map ( ( { name } ) => name ) . join ( ', ' ) ,
45
+ ) ;
46
+ }
18
47
}
0 commit comments