Skip to content

Commit

Permalink
Eliminate pre-module code from resolveUrl tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Apr 24, 2018
1 parent d6821e4 commit a93f81f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
17 changes: 7 additions & 10 deletions test/unit/resolveurl.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
<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>
Expand Down Expand Up @@ -56,10 +55,10 @@
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}]`);
Expand All @@ -84,11 +83,9 @@
document.body.removeChild(el);
};

test('Urls in styles and attributes', testStylesAndAttributes('p-r', 'sub'));

test('Urls in styles and attributes (importMeta)', testStylesAndAttributes('p-r-im', 'http://class.com/mymodule'));
test('Urls in styles and attributes', testStylesAndAttributes('p-r'));

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');
Expand Down
22 changes: 6 additions & 16 deletions test/unit/sub/resolveurl-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -44,29 +46,17 @@ class PR extends PolymerElement {
<a id="protocol" href="data:foo.z">Foo</a>
`;
}

static get is() { return 'p-r'; }
}
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' };
return import.meta;
}
}
customElements.define('p-r-im', PRImportMeta);
customElements.define(PR.is, PR);

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 {
Expand Down

0 comments on commit a93f81f

Please sign in to comment.