Files
angular__angular/aio/tests/deployment/unit/testServiceWorkerRoutes.spec.ts
Joey Perrott 418a35f3fb fix(docs-infra): fix failing tests related to redirects (#55994)
Correct failing tests created by redirect changes

PR Close #55994
2024-05-22 15:58:33 +00:00

52 lines
2.0 KiB
TypeScript

import {getSwNavigationUrlChecker, loadLegacyUrls, loadLocalSitemapUrls} from '../shared/helpers';
describe('ServiceWorker navigation URLs', () => {
const isNavigationUrl = getSwNavigationUrlChecker();
loadLocalSitemapUrls().forEach(url => {
// Skip check for `/` because it is not handled by the service worker because the redirect
// sending all trafic away from the site anyway on firebase. We are okay with it being handled
// locally by the service worker during fallback.
if (url === '/') {
return;
}
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));
});
});