mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
Eliminate pre-module code from resolveUrl tests
This commit is contained in:
@@ -14,10 +14,9 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
<script src="../../node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js"></script>
|
||||
<script src="wct-browser-config.js"></script>
|
||||
<script src="../../node_modules/wct-browser-legacy/browser.js"></script>
|
||||
<script>
|
||||
Polymer = {
|
||||
rootPath: 'earlyRootPath/'
|
||||
};
|
||||
<script type="module">
|
||||
import { setRootPath } from '../../lib/utils/settings.js';
|
||||
setRootPath('earlyRootPath/');
|
||||
</script>
|
||||
<script type="module" src="../../polymer-legacy.js"></script>
|
||||
<script type="module" src="./sub/resolveurl-elements.js"></script>
|
||||
@@ -56,10 +55,10 @@ import { PolymerElement } from '../../polymer-element.js';
|
||||
import { setRootPath } from '../../lib/utils/settings.js';
|
||||
suite('ResolveUrl', function() {
|
||||
|
||||
const testStylesAndAttributes = (elementName, folder) => () => {
|
||||
const testStylesAndAttributes = (elementName) => () => {
|
||||
var el = document.createElement(elementName);
|
||||
document.body.appendChild(el);
|
||||
var resolvedUrl = new RegExp(`${folder}/foo\\.z`);
|
||||
var resolvedUrl = /sub\/foo\.z/;
|
||||
var styleHashUrl = /url\('#bar'\)/;
|
||||
var styleAbsUrl = /url\('\/zot'\)/;
|
||||
var style = el.shadowRoot.querySelector('style') || document.querySelector(`style[scope=${elementName}]`);
|
||||
@@ -84,11 +83,9 @@ suite('ResolveUrl', function() {
|
||||
document.body.removeChild(el);
|
||||
};
|
||||
|
||||
test('Urls in styles and attributes', testStylesAndAttributes('p-r', 'sub'));
|
||||
test('Urls in styles and attributes', testStylesAndAttributes('p-r'));
|
||||
|
||||
test('Urls in styles and attributes (importMeta)', testStylesAndAttributes('p-r-im', 'http://class.com/mymodule'));
|
||||
|
||||
test('Urls in styles and attributes (importMeta, hybrid)', testStylesAndAttributes('p-r-hybrid', 'http://hybrid.com/mymodule'));
|
||||
test('Urls in styles and attributes (hybrid)', testStylesAndAttributes('p-r-hybrid'));
|
||||
|
||||
test('url changes via setting importPath/rootPath on element instance', function() {
|
||||
var el = document.createElement('p-r');
|
||||
|
||||
@@ -12,12 +12,14 @@ import { html } from '../../../lib/utils/html-tag.js';
|
||||
import { PolymerElement } from '../../../polymer-element.js';
|
||||
import { DomModule } from '../../../lib/elements/dom-module.js';
|
||||
import { Polymer } from '../../../lib/legacy/polymer-fn.js';
|
||||
import { pathFromUrl } from '../utils/resolve-url.js';
|
||||
import { pathFromUrl } from '../../../lib/utils/resolve-url.js';
|
||||
|
||||
const $_documentContainer = document.createElement('div');
|
||||
$_documentContainer.setAttribute('style', 'display: none;');
|
||||
const baseAssetPath = pathFromUrl(import.meta.url);
|
||||
$_documentContainer.innerHTML = `<dom-module id="p-r-ap" assetpath="${baseAssetPath}../../assets/"></dom-module>`;
|
||||
document.head.appendChild($_documentContainer);
|
||||
|
||||
class PR extends PolymerElement {
|
||||
static get template() {
|
||||
return html`
|
||||
@@ -44,29 +46,17 @@ class PR extends PolymerElement {
|
||||
<a id="protocol" href="data:foo.z">Foo</a>
|
||||
`;
|
||||
}
|
||||
|
||||
static get is() { return 'p-r'; }
|
||||
static get importMeta() {
|
||||
return import.meta;
|
||||
}
|
||||
}
|
||||
customElements.define(PR.is, PR);
|
||||
|
||||
class PRImportMeta extends PolymerElement {
|
||||
static get template() {
|
||||
return PR.template;
|
||||
}
|
||||
static get importMeta() {
|
||||
// Idiomatically, this would be `return import.meta`, but for purposes
|
||||
// of stubbing the test without actual modules, it's shimmed
|
||||
return { url: 'http://class.com/mymodule/index.js' };
|
||||
}
|
||||
}
|
||||
customElements.define('p-r-im', PRImportMeta);
|
||||
|
||||
const PRHybrid = Polymer({
|
||||
is: 'p-r-hybrid',
|
||||
_template: PR.template,
|
||||
// Idiomatically, this would be `return import.meta`, but for purposes
|
||||
// of stubbing the test without actual modules, it's shimmed
|
||||
importMeta: { url: 'http://hybrid.com/mymodule/index.js' }
|
||||
importMeta: import.meta
|
||||
});
|
||||
|
||||
class PRAp extends PolymerElement {
|
||||
|
||||
Reference in New Issue
Block a user