In #41788, logic was added to disambiguate case-insensitively equal docs paths/URLs. This process includes appending a `-\d+` suffix to some paths/URLs (for example, `/.../inject-1`). Unfortunately, some of the Firebase redirects configured in `firebase.json` would match these URLs and redirect them to non-existing paths. Example failures: [stable][1], [next][2] NOTE: This was not picked up in the regular CI tests run for PRs, because the local devserver and the preview server used to test PRs do not support Firebase-like redirects. This commit fixes this by ensuring these disambiguated paths/URLs are not matched by the redirect rules by checking whether the part of the suffix after the `-` contains any numeric digits. While this check is not ideal, it should be good enough for our purpose, since the legacy URLs that we do want to redirect contain suffixes such as `-class`, `-function` and thus no numeric digits. [1]: https://circleci.com/gh/angular/angular/974345 [2]: https://circleci.com/gh/angular/angular/974346 PR Close #41842
53 lines
2.0 KiB
TypeScript
53 lines
2.0 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/foo', '/docs/foo/', '/docs/foo/bar'];
|
|
|
|
navigationUrls.forEach(url => expect(isNavigationUrl(url)).toBeTruthy(url));
|
|
nonNavigationUrls.forEach(url => expect(isNavigationUrl(url)).toBeFalsy(url));
|
|
});
|
|
|
|
it('should treat disambiguated URLs as navigation URLs', () => {
|
|
// Disambiguated URL.
|
|
const url1 = '/api/core/Foo-0';
|
|
expect(isNavigationUrl(url1)).toBeTruthy(url1);
|
|
|
|
// Disambiguated URL.
|
|
const url2 = '/api/core/BAR-1337';
|
|
expect(isNavigationUrl(url2)).toBeTruthy(url2);
|
|
|
|
// Non-disambiguated URL with dash.
|
|
const url3 = '/api/core/baz-class';
|
|
expect(isNavigationUrl(url3)).toBeFalsy(url3);
|
|
});
|
|
});
|