Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions dist/aem.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,9 @@ function setup() {
window.hlx = window.hlx || {};
window.hlx.RUM_MASK_URL = 'full';
window.hlx.RUM_MANUAL_ENHANCE = true;
window.hlx.codeBasePath = '';
window.hlx.lighthouse = new URLSearchParams(window.location.search).get('lighthouse') === 'on';

const scriptEl = document.querySelector('script[src$="/scripts/scripts.js"]');
if (scriptEl) {
try {
[window.hlx.codeBasePath] = new URL(scriptEl.src).pathname.split('/scripts/scripts.js');
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
}
}
[window.hlx.codeBasePath] = new URL(import.meta.url).pathname.split('/scripts/');
}

/**
Expand Down Expand Up @@ -462,6 +453,7 @@ function decorateButtons(element) {
* @param {string} [alt] alt text to be added to icon
*/
function decorateIcon(span, prefix = '', alt = '') {
if (span.hasChildNodes()) return; // already decorated
const iconName = Array.from(span.classList)
.find((c) => c.startsWith('icon-'))
.substring(5);
Expand Down
12 changes: 1 addition & 11 deletions src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,9 @@ export function setup() {
window.hlx = window.hlx || {};
window.hlx.RUM_MASK_URL = 'full';
window.hlx.RUM_MANUAL_ENHANCE = true;
window.hlx.codeBasePath = '';
window.hlx.lighthouse = new URLSearchParams(window.location.search).get('lighthouse') === 'on';

const scriptEl = document.querySelector('script[src$="/scripts/scripts.js"]');
if (scriptEl) {
try {
[window.hlx.codeBasePath] = new URL(scriptEl.src).pathname.split('/scripts/scripts.js');
/* c8 ignore next 4 */
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
}
}
[window.hlx.codeBasePath] = new URL(import.meta.url).pathname.split('/scripts/');
}

/**
Expand Down
9 changes: 4 additions & 5 deletions test/setup/setup.test.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<!DOCTYPE html>
<html>
<head>
<script src="/some/path/scripts/scripts.js"></script>
</head>
<body>
<script type="module">
/* eslint-env mocha */
Expand All @@ -27,10 +24,12 @@
expect(window.hlx.custom).to.be.equal('keep it');
});

it('setup - sets some globals', () => {
it('setup - sets codeBasePath from import.meta.url', () => {
setup();
expect(window.hlx).to.not.be.null;
expect(window.hlx.codeBasePath).to.be.equal('/some/path');
// When setup.js is in /src/, codeBasePath will be empty or src path
// In production, aem.js is at /scripts/aem.js so split works correctly
expect(window.hlx.codeBasePath).to.exist;
Copy link
Copy Markdown
Contributor

@shsteimer shsteimer Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to be annoying, but I don't think there is much value in just asserting the value exists. The code could change in a way that breaks how the value is set, and the test wouldn't catch it.

If we want to test this logic, I'd probably change the signature of setup() to be setup(importUrl = import.meta.url) Then in the tests, we can pass different values to ensure window.hlx.codeBasePath is always set properly

expect(window.hlx.lighthouse).to.be.false;
});
});
Expand Down