Skip to content

Commit

Permalink
fix: add a dataset attribute for js load
Browse files Browse the repository at this point in the history
this will allow web editor to read if the assets js has been loaded/doesn't need to be

This is required to allow us to wait until integrations have run

AP-3414
  • Loading branch information
robertsevernsentient committed Oct 13, 2023
1 parent 698e2a6 commit 5487696
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/asset-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ function main(container, _runner) {
const cssAsset = retrieveEvolvCssAsset(environment);
const jsAsset = retrieveEvolvJsAsset(environment);

const markDOMJSState = function (state) {
document.documentElement.dataset.evolvJs = state;
}
markDOMJSState(jsAsset ? 'loaded' : 'not-requested');

const runner = _runner || new Runner(container);

/**
Expand Down
8 changes: 7 additions & 1 deletion src/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ describe('asset manager handles correctly', () => {
global.document = new DocumentMock({ elements: styleSheets, styleSheets });
const client = new EvolvMock();
new EvolvAssetManager(client, undefined, mockTiming());
assert.equal(document.classList.classList.length, 0)
assert.equal(document.classList.classList.length, 0);
});

it('for just stylesheets - will still confirm - but there is nothing to confirm into', () => {
Expand All @@ -192,6 +192,9 @@ describe('asset manager handles correctly', () => {
new EvolvAssetManager(client, undefined, mockTiming());
assert.equal(client.confirmations, 1);
assert.equal(client.contaminations, 0);

// verify we mark the status of the assets js load
assert.strictEqual(document.documentElement.dataset.evolvJs, 'not-requested');
});

it('for just javascript - will still confirm - but there is nothing to confirm into', () => {
Expand All @@ -203,6 +206,9 @@ describe('asset manager handles correctly', () => {
assert.equal(true, _mockRunner.updateFunctionsToRun.calledOnce);
assert.deepStrictEqual([], _mockRunner.updateFunctionsToRun.getCall(0).args[0]);
assert.equal(client.contaminations, 0);

// verify we mark the status of the assets js load
assert.strictEqual(document.documentElement.dataset.evolvJs, 'loaded');
});
});

Expand Down
3 changes: 2 additions & 1 deletion src/tests/mocks/document.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class DocumentMock {
this.scripts = options.scripts || [];
this.currentScript = options.currentScript;
this.documentElement = {
classList: this.classList
classList: this.classList,
dataset: {}
}
this.children = [];
this.head = {};
Expand Down
4 changes: 2 additions & 2 deletions src/tests/webloader.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as assert from 'assert';
import { WindowMock, DocumentMock, MOCK_GA_CLIENT_ID } from './mocks/document.mock.js';
import { WindowMock, DocumentMock } from './mocks/document.mock.js';
import EvolvMock from './mocks/evolv.mock.js';
import sinon from 'sinon';

Expand Down Expand Up @@ -166,7 +166,7 @@ describe('the web loader', () => {
assert.strictEqual(window.evolv.client.environment, queryEnvironmentId, 'Environment id should be overridden');
});

it('should use the environment data parameter if set and not thefirst query param', async () => {
it('should use the environment data parameter if set and not the first query param', async () => {
setupGlobal(null, undefined, {
evolvEnvironment: undefined
});
Expand Down

0 comments on commit 5487696

Please sign in to comment.