Skip to content

Commit 17aa816

Browse files
committed
fixup! fix(@angular-devkit/build-angular): correctly generate ServiceWorker config on Windows
1 parent cd4260f commit 17aa816

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

tests/legacy-cli/e2e/tests/commands/add/add-pwa.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,39 @@ export default async function () {
99
await expectFileToExist(join(process.cwd(), 'src/manifest.webmanifest'));
1010

1111
// 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+
);
1518
if (hasPWADep) {
1619
throw new Error(`Expected 'package.json' not to contain a dependency on '@angular/pwa'.`);
1720
}
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+
}
1847
}

0 commit comments

Comments
 (0)