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
4 changes: 3 additions & 1 deletion src/Rokt-Kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var constructor = function () {
self.testHelpers = null;
self.placementEventMappingLookup = {};
self.eventQueue = [];
self.integrationName = null;

/**
* Generates the Rokt launcher script URL with optional domain override and extensions
Expand Down Expand Up @@ -113,9 +114,10 @@ var constructor = function () {
{},
window.mParticle.Rokt.launcherOptions || {}
);
launcherOptions.integrationName = generateIntegrationName(
self.integrationName = generateIntegrationName(
launcherOptions.integrationName
);
launcherOptions.integrationName = self.integrationName;

if (testMode) {
self.testHelpers = {
Expand Down
87 changes: 87 additions & 0 deletions test/src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,93 @@ describe('Rokt Forwarder', () => {
);
});

it('should set integrationName on kit instance after attaching', async () => {
window.Rokt = new MockRoktForwarder();
window.mParticle.Rokt = window.Rokt;
window.mParticle.Rokt.attachKitCalled = false;

window.mParticle.Rokt.attachKit = async (kit) => {
window.mParticle.Rokt.attachKitCalled = true;
window.mParticle.Rokt.kit = kit;
return Promise.resolve();
};

await mParticle.forwarder.init(
{
accountId: '123456',
},
reportService.cb,
true
);

// Wait for initialization to complete
await waitForCondition(() => window.mParticle.Rokt.isInitialized);

window.mParticle.Rokt.kit.integrationName.should.equal(
`${sdkVersion}_${kitVersion}`
);
Comment on lines +339 to +344
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

These assertions rely on waitForCondition(() => window.mParticle.Rokt.isInitialized), but MockRoktForwarder.createLauncher sets isInitialized = true before the kit is actually attached. This can make the test race/flaky if attachKit runs later. Consider waiting on window.mParticle.Rokt.attachKitCalled (or window.mParticle.forwarder.isInitialized, or window.mParticle.Rokt.kit being set) instead so the kit is guaranteed available before asserting kit.integrationName.

Copilot uses AI. Check for mistakes.
});

it('should set integrationName on kit instance with custom name when provided', async () => {
const customName = 'myCustomName';

window.Rokt = new MockRoktForwarder();
window.mParticle.Rokt = window.Rokt;
window.mParticle.Rokt.attachKitCalled = false;

window.mParticle.Rokt.attachKit = async (kit) => {
window.mParticle.Rokt.attachKitCalled = true;
window.mParticle.Rokt.kit = kit;
return Promise.resolve();
};

window.mParticle.Rokt.launcherOptions = {
integrationName: customName,
};

await mParticle.forwarder.init(
{
accountId: '123456',
},
reportService.cb,
true
);

// Wait for initialization to complete
await waitForCondition(() => window.mParticle.Rokt.isInitialized);

window.mParticle.Rokt.kit.integrationName.should.equal(
`${sdkVersion}_${kitVersion}_${customName}`
);
Comment on lines +372 to +377
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

This test also waits on window.mParticle.Rokt.isInitialized, which is toggled inside the mock before attachKit necessarily completes. To avoid intermittent failures (e.g., window.mParticle.Rokt.kit still undefined), wait on attachKitCalled / forwarder.isInitialized / kit being assigned before asserting kit.integrationName.

Copilot uses AI. Check for mistakes.
});

it('should have integrationName available on kit after initialization', async () => {
window.Rokt = new MockRoktForwarder();
window.mParticle.Rokt = window.Rokt;
window.mParticle.Rokt.attachKitCalled = false;

window.mParticle.Rokt.attachKit = async (kit) => {
window.mParticle.Rokt.attachKitCalled = true;
window.mParticle.Rokt.kit = kit;
return Promise.resolve();
};

await mParticle.forwarder.init(
{
accountId: '123456',
},
reportService.cb,
true
);

// Wait for initialization to complete
await waitForCondition(() => window.mParticle.Rokt.isInitialized);

window.mParticle.Rokt.attachKitCalled.should.equal(true);
window.mParticle.Rokt.kit.integrationName.should.be.a.String();
window.mParticle.Rokt.kit.integrationName.should.not.be.empty();
});
Comment on lines +399 to +405
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

Even though the test later asserts attachKitCalled, the wait condition is still window.mParticle.Rokt.isInitialized (set early by the mock). Waiting directly for attachKitCalled (or kit assignment) would better guarantee the kit has been attached before reading kit.integrationName.

Copilot uses AI. Check for mistakes.

it('should not mutate the global launcherOptions object during initialization', async () => {
const originalIntegrationName = 'globalIntegrationName';

Expand Down
Loading