forked from ampproject/amphtml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Cache SW manual test infrastructure (ampproject#6532)
* Extract extensions-location from extensions-impl For some god awful reason, all of our polyfills were being pulled into the SW code because of the dependency chains. * Create calculateEntryPointScriptUrl * Ensure SW installs max code when asked * Update pathname rewriting in SW The old code prevented a base directory from being used, like if we were serving from `http://localhost/dist` * Add Cache SW manual test infrastructure * Remove unused export * Add tests * Fix tests
- Loading branch information
1 parent
6b08e63
commit 029186b
Showing
10 changed files
with
357 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* Copyright 2016 The AMP HTML Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import {urls} from '../config'; | ||
import {getMode} from '../mode'; | ||
|
||
/** | ||
* Calculate the base url for any scripts. | ||
* @param {!Location} location The window's location | ||
* @param {boolean=} isLocalDev | ||
* @param {boolean=} isTest | ||
* @return {string} | ||
*/ | ||
function calculateScriptBaseUrl(location, isLocalDev, isTest) { | ||
if (isLocalDev) { | ||
if (isTest || isMax(location) || isMin(location)) { | ||
return `${location.protocol}//${location.host}/dist`; | ||
} | ||
} | ||
return urls.cdn; | ||
} | ||
|
||
/** | ||
* Calculate script url for an extension. | ||
* @param {!Location} location The window's location | ||
* @param {string} extensionId | ||
* @param {boolean=} isLocalDev | ||
* @param {boolean=} isTest | ||
* @param {boolean=} isUsingCompiledJs | ||
* @return {string} | ||
*/ | ||
export function calculateExtensionScriptUrl(location, extensionId, isLocalDev, | ||
isTest, isUsingCompiledJs) { | ||
const base = calculateScriptBaseUrl(location, isLocalDev, isTest); | ||
if (isLocalDev) { | ||
if ((isTest && !isUsingCompiledJs) || isMax(location)) { | ||
return `${base}/v0/${extensionId}-0.1.max.js`; | ||
} | ||
return `${base}/v0/${extensionId}-0.1.js`; | ||
} | ||
return `${base}/rtv/${getMode().rtvVersion}/v0/${extensionId}-0.1.js`; | ||
} | ||
|
||
/** | ||
* Calculate script url for an entry point. | ||
* @param {!Location} location The window's location | ||
* @param {string} entryPoint | ||
* @param {boolean=} isLocalDev | ||
* @param {boolean=} isTest | ||
* @return {string} | ||
*/ | ||
export function calculateEntryPointScriptUrl(location, entryPoint, isLocalDev, | ||
isTest) { | ||
const base = calculateScriptBaseUrl(location, isLocalDev, isTest); | ||
const serveMax = isLocalDev && isMax(location); | ||
return `${base}/${entryPoint}${serveMax ? '.max' : ''}.js`; | ||
} | ||
|
||
/** | ||
* Is this path to a max (unminified) version? | ||
* @param {!Location} location | ||
* @return {boolean} | ||
*/ | ||
function isMax(location) { | ||
const path = location.pathname; | ||
return path.indexOf('.max') >= 0 || path.substr(0, 5) == '/max/'; | ||
} | ||
|
||
/** | ||
* Is this path to a minified version? | ||
* @param {!Location} location | ||
* @return {boolean} | ||
*/ | ||
function isMin(location) { | ||
const path = location.pathname; | ||
return path.indexOf('.min') >= 0 || path.substr(0, 5) == '/min/'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.