refactor(aio): move deployment config tests and helpers around (#22483)

This commit prepares the ground for adding different types of tests.

PR Close #22483
This commit is contained in:
George Kalpakas 2018-02-28 01:14:28 +02:00 committed by Alex Rickabaugh
parent 8c10df30d7
commit 120673a3ac
5 changed files with 16 additions and 13 deletions

View File

@ -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",

View File

@ -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>([^<]+)<\/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];

View File

@ -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', () => {

View File

@ -1,4 +1,4 @@
import { loadLegacyUrls, loadSitemapUrls, loadSWRoutes } from './helpers';
import { loadLegacyUrls, loadSitemapUrls, loadSWRoutes } from '../shared/helpers';
describe('service-worker routes', () => {