diff --git a/src/setup.js b/src/setup.js index 04177a3..d963825 100644 --- a/src/setup.js +++ b/src/setup.js @@ -37,9 +37,8 @@ export function setup() { /** * Auto initialization. */ -/* c8 ignore next 18 */ export function init() { setup(); - sampleRUM.collectBaseURL = window.origin; + sampleRUM.collectBaseURL = new URL(`${window.hlx.codeBasePath}/`, window.origin); sampleRUM(); } diff --git a/test/setup/setup.test.html b/test/setup/setup.test.html index 586a720..cf88291 100644 --- a/test/setup/setup.test.html +++ b/test/setup/setup.test.html @@ -8,7 +8,8 @@ /* eslint-env mocha */ import { runTests } from '@web/test-runner-mocha'; import { expect } from '@esm-bundle/chai'; - import { setup } from '../../src/setup.js'; + import { sampleRUM } from '@adobe/helix-rum-js'; + import { setup, init } from '../../src/setup.js'; runTests(() => { it('setup - defines window.hlx', () => { @@ -33,6 +34,11 @@ expect(window.hlx.codeBasePath).to.be.equal('/some/path'); expect(window.hlx.lighthouse).to.be.false; }); + + it('init - sets sampleRUM.collectBaseURL to include the codeBasePath', () => { + init(); + expect(sampleRUM.collectBaseURL.href).to.be.equal(`${window.origin}/some/path/`); + }); });