diff --git a/aio/package.json b/aio/package.json index 28449ffa01..612a5bb892 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-config/unit/**/*.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/URLS_TO_REDIRECT.txt b/aio/tests/deployment-config/shared/URLS_TO_REDIRECT.txt similarity index 100% rename from aio/tests/deployment/URLS_TO_REDIRECT.txt rename to aio/tests/deployment-config/shared/URLS_TO_REDIRECT.txt diff --git a/aio/tests/deployment/helpers.ts b/aio/tests/deployment-config/shared/helpers.ts similarity index 66% rename from aio/tests/deployment/helpers.ts rename to aio/tests/deployment-config/shared/helpers.ts index 0347597f28..e4a28d3074 100644 --- a/aio/tests/deployment/helpers.ts +++ b/aio/tests/deployment-config/shared/helpers.ts @@ -1,21 +1,24 @@ -const { readFileSync } = require('fs'); -const path = require('canonical-path'); -const cjson = require('cjson'); +import { resolve } from 'canonical-path'; +import { load as loadJson } from 'cjson'; +import { readFileSync } from 'fs'; -import { FirebaseRedirector, FirebaseRedirectConfig } from '../../tools/firebase-test-utils/FirebaseRedirector'; +import { FirebaseRedirector, FirebaseRedirectConfig } from '../../../tools/firebase-test-utils/FirebaseRedirector'; + + +const AIO_DIR = resolve(__dirname, '../../..'); export function getRedirector() { return new FirebaseRedirector(loadRedirects()); } export function loadRedirects(): FirebaseRedirectConfig[] { - const pathToFirebaseJSON = path.resolve(__dirname, '../../firebase.json'); - const contents = cjson.load(pathToFirebaseJSON); + const pathToFirebaseJSON = `${AIO_DIR}/firebase.json`; + const contents = loadJson(pathToFirebaseJSON); return contents.hosting.redirects; } export function loadSitemapUrls() { - const pathToSiteMap = path.resolve(__dirname, '../../src/generated/sitemap.xml'); + const pathToSiteMap = `${AIO_DIR}/src/generated/sitemap.xml`; const xml = readFileSync(pathToSiteMap, 'utf8'); const urls: string[] = []; xml.replace(/([^<]+)<\/loc>/g, (_, loc) => urls.push(loc.replace('%%DEPLOYMENT_HOST%%', ''))); @@ -23,14 +26,14 @@ export function loadSitemapUrls() { } export function loadLegacyUrls() { - const pathToLegacyUrls = path.resolve(__dirname, 'URLS_TO_REDIRECT.txt'); + const pathToLegacyUrls = `${__dirname}/URLS_TO_REDIRECT.txt`; 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 pathToSWManifest = `${AIO_DIR}/ngsw-manifest.json`; + const contents = loadJson(pathToSWManifest); const routes = contents.routing.routes; return Object.keys(routes).map(route => { const routeConfig = routes[route]; diff --git a/aio/tests/deployment/testFirebaseRedirection.spec.ts b/aio/tests/deployment-config/unit/testFirebaseRedirection.spec.ts similarity index 96% rename from aio/tests/deployment/testFirebaseRedirection.spec.ts rename to aio/tests/deployment-config/unit/testFirebaseRedirection.spec.ts index 19b687456d..b9a018dfea 100644 --- a/aio/tests/deployment/testFirebaseRedirection.spec.ts +++ b/aio/tests/deployment-config/unit/testFirebaseRedirection.spec.ts @@ -1,4 +1,4 @@ -import { getRedirector, loadLegacyUrls, loadRedirects, loadSitemapUrls } from './helpers'; +import { getRedirector, loadLegacyUrls, loadRedirects, loadSitemapUrls } from '../shared/helpers'; describe('firebase.json redirect config', () => { describe('with sitemap urls', () => { diff --git a/aio/tests/deployment/testServiceWorkerRoutes.spec.ts b/aio/tests/deployment-config/unit/testServiceWorkerRoutes.spec.ts similarity index 98% rename from aio/tests/deployment/testServiceWorkerRoutes.spec.ts rename to aio/tests/deployment-config/unit/testServiceWorkerRoutes.spec.ts index db119ffecb..ad115b1fd2 100644 --- a/aio/tests/deployment/testServiceWorkerRoutes.spec.ts +++ b/aio/tests/deployment-config/unit/testServiceWorkerRoutes.spec.ts @@ -1,4 +1,4 @@ -import { loadLegacyUrls, loadSitemapUrls, loadSWRoutes } from './helpers'; +import { loadLegacyUrls, loadSitemapUrls, loadSWRoutes } from '../shared/helpers'; describe('service-worker routes', () => {