angular-cn/aio/tests/deployment/unit/testServiceWorkerRoutes.spec.ts
George Kalpakas 982521f284 build(docs-infra): align navigationUrls in ngsw-config.json with Firebase redirects (#42452)
The ServiceWorker `navigationUrls` globs defined in `ngsw-config.json`
are supposed to exclude any URLs that are redirected on the server (as
configured in `firebase.json`). However, the list of redirected
URLs/globs in `firebase.json` and `ngsw-config.json` have gotten out of
sync.

This commit updates the globs in `ngsw-config.json` to match the ones in
`firebase.json`.

This is in preparation of automatically generating the ServiceWorker
`navigationUrls` based on `firebase.json`.

PR Close #42452
2021-06-18 17:32:58 +00:00

45 lines
1.7 KiB
TypeScript

import { getSwNavigationUrlChecker, loadLegacyUrls, loadLocalSitemapUrls } from '../shared/helpers';
describe('ServiceWorker navigation URLs', () => {
const isNavigationUrl = getSwNavigationUrlChecker();
loadLocalSitemapUrls().forEach(url => {
it('should treat URLs in the Sitemap as navigation URLs', () => {
expect(isNavigationUrl(url)).toBeTruthy(url);
});
});
loadLegacyUrls().forEach(urlPair => {
const url = urlPair[0];
it('should treat legacy URLs that will be redirected as non-navigation URLs', () => {
expect(isNavigationUrl(url)).toBeFalsy(url);
});
});
it('should treat StackBlitz URLs as non-navigation URLs', () => {
expect(isNavigationUrl('/generated/live-examples/toh-pt6/stackblitz.html')).toBeFalsy();
expect(isNavigationUrl('/generated/live-examples/toh-pt6/stackblitz')).toBeFalsy();
});
it('should treat URLs to files with extensions as non-navigation URLs', () => {
expect(isNavigationUrl('/generated/zips/animations/animations.zip')).toBeFalsy();
expect(isNavigationUrl('/generated/images/guide/animations/animation_auto.gif')).toBeFalsy();
expect(isNavigationUrl('/generated/ngsw-worker.js')).toBeFalsy();
expect(isNavigationUrl('/generated/docs/guide/animations.json')).toBeFalsy();
});
it('should treat `/docs/*` URLs correctly', () => {
const navigationUrls = ['/docs', '/docs/'];
const nonNavigationUrls = [
'/docs/js/latest',
'/docs/ts/latest/foo',
'/docs/latest/foo/bar',
'/docs/styleguide',
'/docs/styleguide/',
];
navigationUrls.forEach(url => expect(isNavigationUrl(url)).toBeTruthy(url));
nonNavigationUrls.forEach(url => expect(isNavigationUrl(url)).toBeFalsy(url));
});
});