diff --git a/aio/package.json b/aio/package.json index fa5d9b0ada..e7f1a02e78 100644 --- a/aio/package.json +++ b/aio/package.json @@ -44,7 +44,7 @@ "docs-watch": "node tools/transforms/authors-package/watchr.js", "docs-lint": "eslint --ignore-path=\"tools/transforms/.eslintignore\" tools/transforms", "docs-test": "node tools/transforms/test.js", - "deployment-config-test": "jasmine-ts tests/deployment/*.spec.ts", + "deployment-config-test": "jasmine-ts tests/deployment/**/*.spec.ts", "firebase-utils-test": "jasmine-ts tools/firebase-test-utils/*.spec.ts", "tools-lint": "tslint -c \"tools/tslint.json\" \"tools/firebase-test-utils/**/*.ts\"", "tools-test": "./scripts/deploy-to-firebase.test.sh && yarn docs-test && yarn boilerplate:test && jasmine tools/ng-packages-installer/index.spec.js && yarn firebase-utils-test", diff --git a/aio/tests/deployment/helpers.ts b/aio/tests/deployment/helpers.ts index 6193740e3c..0347597f28 100644 --- a/aio/tests/deployment/helpers.ts +++ b/aio/tests/deployment/helpers.ts @@ -27,3 +27,23 @@ export function loadLegacyUrls() { const urls = readFileSync(pathToLegacyUrls, 'utf8').split('\n').map(line => line.split('\t')); return urls; } + +export function loadSWRoutes() { + const pathToSWManifest = path.resolve(__dirname, '../../ngsw-manifest.json'); + const contents = cjson.load(pathToSWManifest); + const routes = contents.routing.routes; + return Object.keys(routes).map(route => { + const routeConfig = routes[route]; + switch (routeConfig.match) { + case 'exact': + return (url) => url === route; + case 'prefix': + return (url) => url.startsWith(route); + case 'regex': + const regex = new RegExp(route); + return (url) => regex.test(url); + default: + throw new Error(`unknown route config: ${route} - ${routeConfig.match}`); + } + }); +} diff --git a/aio/tests/deployment/testServiceWorkerRoutes.spec.ts b/aio/tests/deployment/testServiceWorkerRoutes.spec.ts new file mode 100644 index 0000000000..db119ffecb --- /dev/null +++ b/aio/tests/deployment/testServiceWorkerRoutes.spec.ts @@ -0,0 +1,33 @@ +import { loadLegacyUrls, loadSitemapUrls, loadSWRoutes } from './helpers'; + +describe('service-worker routes', () => { + + loadSitemapUrls().forEach(url => { + it('should process URLs in the Sitemap', () => { + const routes = loadSWRoutes(); + expect(routes.some(test => test(url))).toBeTruthy(url); + }); + }); + + loadLegacyUrls().forEach(urlPair => { + const url = urlPair[0]; + it('should ignore legacy URLs that will be redirected', () => { + const routes = loadSWRoutes(); + expect(routes.some(test => test(url))).toBeFalsy(url); + }); + }); + + it('should ignore stackblitz URLs', () => { + const routes = loadSWRoutes(); + expect(routes.some(test => test('/generated/live-examples/toh-pt6/stackblitz.html'))).toBeFalsy(); + expect(routes.some(test => test('/generated/live-examples/toh-pt6/stackblitz'))).toBeFalsy(); + }); + + it('should ignore URLs to files with extensions', () => { + const routes = loadSWRoutes(); + expect(routes.some(test => test('/generated/zips/animations/animations.zip'))).toBeFalsy(); + expect(routes.some(test => test('/generated/images/guide/animations/animation_auto.gif'))).toBeFalsy(); + expect(routes.some(test => test('/generated/ie-polyfills.min.js'))).toBeFalsy(); + expect(routes.some(test => test('/generated/docs/guide/animations.json'))).toBeFalsy(); + }); +});