Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
0b41099
test: updated setup for identity tests
jaissica12 Oct 20, 2025
600d90a
test: added .only to test files for targeted testing
jaissica12 Oct 22, 2025
46d2c3b
test: updated identity test for failing test
jaissica12 Oct 23, 2025
c0fb30e
test: updated identity test to handle identity calls
jaissica12 Oct 23, 2025
6e80ee6
test: document Firefox timing issues in identity tests
jaissica12 Oct 23, 2025
a4c5c44
test: updated karma timeout config
jaissica12 Oct 23, 2025
f691539
test: updated identity tests to resolve flaky tests
jaissica12 Oct 24, 2025
b245b05
test: updated identity test when mpid is zero
jaissica12 Oct 24, 2025
1eb173b
test: updated identity tests when mpid is invalid
jaissica12 Oct 24, 2025
4e4de0b
test: updated karma config for timeout issues
jaissica12 Oct 24, 2025
b2ab345
test: increase timeout for flaky identity tests for Firefox
jaissica12 Oct 24, 2025
71302f9
test: reduce browserNoActivityTimeout to 20000 for Firefox browser
jaissica12 Oct 24, 2025
301d5f9
test: increase browserNoActivityTimeout to 60000 for Firefox browser
jaissica12 Oct 24, 2025
f537ab7
test: increase mocha timeout to 10 seconds
jaissica12 Oct 24, 2025
00fad32
test: updated timeout for identity test
jaissica12 Oct 24, 2025
c738b43
test: reverted timeout changes from individual tests
jaissica12 Oct 24, 2025
01a78d8
test: updated waitForCondition for identity login
jaissica12 Oct 24, 2025
62aef29
test: cleanup identity tests
jaissica12 Oct 27, 2025
45b9892
test: use logger spy for robust identity test SDKE-420
jaissica12 Oct 27, 2025
2b49b0a
Merge branch 'test/SDKE-303-evaluate-each-integration-test-setup' int…
jaissica12 Oct 27, 2025
cf63920
test: updated failing identities attributes test
jaissica12 Oct 27, 2025
ea95636
test: use logger spy for identity response in identity attributes tests
jaissica12 Oct 27, 2025
e0032c7
test: fix logger spy scope in identity attributes test
jaissica12 Oct 27, 2025
565cec7
test: update logger spy in identity tests
jaissica12 Oct 28, 2025
32e35f3
test: updated identity callback test to handle timeout error
jaissica12 Oct 28, 2025
1dec717
test: rollback karma config timeout to 5 sec
jaissica12 Oct 28, 2025
1dc590e
test: update failing identity tests to with logger spy
jaissica12 Oct 28, 2025
fa332dd
test: update identity test waitForCondition for modify function
jaissica12 Oct 28, 2025
2c02bcd
test: rollback karma config and remove SDKE-420 ticket comment
jaissica12 Oct 28, 2025
9c90192
test: removed extra spaces and waitForCondition calls from identity t…
jaissica12 Oct 28, 2025
705e462
test: added ticket SDKE-420 comment for flakey test
jaissica12 Oct 28, 2025
7eb53bc
test: clean up identity tests and add SDKE-420 comment to flaky tests
jaissica12 Oct 28, 2025
088aa6c
test: updated test message content
jaissica12 Oct 28, 2025
6dea100
fix test for queue events when MPID is 0
rmi22186 Oct 28, 2025
acfaa82
test: updated identity localStorage flaky test
jaissica12 Oct 28, 2025
e4ee4e5
fix additional tests by adding waitForCondition and resetForTests at …
rmi22186 Oct 30, 2025
11bf973
remove jira ticket
rmi22186 Oct 30, 2025
9952a4d
fix consent change test by adding waitForCondition and resetForTests
jaissica12 Oct 30, 2025
c6fdceb
revert karma config changes
jaissica12 Oct 30, 2025
3ad0a46
added browserConsoleLogOptions to karma config
jaissica12 Oct 30, 2025
13c3454
remove comment and jira ticket for consent rules test
jaissica12 Oct 30, 2025
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
7 changes: 6 additions & 1 deletion test/karma.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,21 @@ module.exports = function(config) {
debug: true,
logLevel: config.LOG_INFO,
browserConsoleLogOptions,
browserDisconnectTimeout: 10000,
browserDisconnectTolerance: 1,
captureTimeout: 120000,
processKillTimeout: 100000,
client: {
captureConsole,
mocha: {
timeout: 5000 // 5 seconds. Increase from default 2 seconds.
timeout: 10000 // 10 seconds. Increase from default 2 seconds.
Copy link
Member

Choose a reason for hiding this comment

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

Strange, still seeing a 2000 ms issue here for firefox

Image

Copy link
Member

Choose a reason for hiding this comment

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

nevermind, may be the comment i left above actually in the utils.js file for waitForCondition instead

}
},
customLaunchers: {
FirefoxHeadless: {
base: 'Firefox',
flags: ['-headless'],
browserNoActivityTimeout: 60000,
},
},
junitReporter: {
Expand Down
2 changes: 1 addition & 1 deletion test/src/config/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ var pluses = /\+/g,
},
waitForCondition = function async(
conditionFn,
timeout = 200,
timeout = 2000,
Copy link
Member

Choose a reason for hiding this comment

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

i realize i commented below seeing that there was still a 2000ms timeout for firefox, but i realize maybe that's here instead

Image

interval = 10
) {
return new Promise((resolve, reject) => {
Expand Down
60 changes: 21 additions & 39 deletions test/src/tests-identities-attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ const BAD_USER_ATTRIBUTE_KEY_AS_ARRAY = ([

const BAD_USER_ATTRIBUTE_LIST_VALUE = (1234 as unknown) as UserAttributesValue[];

describe('identities and attributes', function() {
describe.only('identities and attributes', function() {
let beforeEachCallbackCalled = false;
let hasBeforeEachCallbackReturned;

beforeEach(function() {
mParticle._resetForTests(MPConfig);
fetchMock.config.overwriteRoutes = true;

fetchMockSuccess(urls.identify, {
mpid: testMPID, is_logged_in: false
});
Expand All @@ -82,7 +85,6 @@ describe('identities and attributes', function() {
});

it('should set user attribute', async () => {
mParticle._resetForTests(MPConfig);
const mockForwarder = new MockForwarder();

mockForwarder.register(window.mParticle.config);
Expand All @@ -104,7 +106,6 @@ describe('identities and attributes', function() {
});

it('should set user attribute be case insensitive', async () => {
mParticle._resetForTests(MPConfig);
const mockForwarder = new MockForwarder();

mockForwarder.register(window.mParticle.config);
Expand Down Expand Up @@ -140,7 +141,6 @@ describe('identities and attributes', function() {
});

it('should set multiple user attributes with setUserAttributes', async () => {
mParticle._resetForTests(MPConfig);
const mockForwarder = new MockForwarder();

mockForwarder.register(window.mParticle.config);
Expand All @@ -165,7 +165,6 @@ describe('identities and attributes', function() {
});

it('should remove user attribute', async () => {
mParticle._resetForTests(MPConfig);
const mockForwarder = new MockForwarder();

mockForwarder.register(window.mParticle.config);
Expand All @@ -183,7 +182,6 @@ describe('identities and attributes', function() {
});

it('should remove user attribute case insensitive', async () => {
mParticle._resetForTests(MPConfig);
const mockForwarder = new MockForwarder();

mockForwarder.register(window.mParticle.config);
Expand Down Expand Up @@ -383,8 +381,6 @@ describe('identities and attributes', function() {
});

it('should set user attribute list', async () => {
mParticle._resetForTests(MPConfig);

mParticle.init(apiKey, window.mParticle.config);
await waitForCondition(hasIdentifyReturned);
mParticle.Identity.getCurrentUser().setUserAttributeList('numbers', [
Expand All @@ -409,8 +405,6 @@ describe('identities and attributes', function() {
});

it('should set user attribute list case insensitive', async () => {
mParticle._resetForTests(MPConfig);

mParticle.init(apiKey, window.mParticle.config);
await waitForCondition(hasIdentifyReturned);
mParticle.Identity.getCurrentUser().setUserAttributeList('numbers', [
Expand Down Expand Up @@ -463,8 +457,6 @@ describe('identities and attributes', function() {
it('should make a copy of user attribute list', async () => {
const list = [1, 2, 3, 4, 5];

mParticle._resetForTests(MPConfig);

mParticle.init(apiKey, window.mParticle.config);

await waitForCondition(hasIdentifyReturned);
Expand All @@ -489,8 +481,6 @@ describe('identities and attributes', function() {
});

it('should remove all user attributes', async () => {
mParticle._resetForTests(MPConfig);

mParticle.init(apiKey, window.mParticle.config);
await waitForCondition(hasIdentifyReturned);
mParticle.Identity.getCurrentUser().setUserAttributeList('numbers', [
Expand All @@ -513,7 +503,6 @@ describe('identities and attributes', function() {
});

it('should get user attribute lists', async () => {
mParticle._resetForTests(MPConfig);

mParticle.init(apiKey, window.mParticle.config);

Expand All @@ -535,7 +524,6 @@ describe('identities and attributes', function() {
});

it('should copy when calling get user attribute lists', async () => {
mParticle._resetForTests(MPConfig);
mParticle.init(apiKey, window.mParticle.config);

await waitForCondition(hasIdentifyReturned);
Expand All @@ -557,7 +545,6 @@ describe('identities and attributes', function() {
});

it('should copy when calling get user attributes', async () => {
mParticle._resetForTests(MPConfig);
mParticle.init(apiKey, window.mParticle.config);
await waitForCondition(hasIdentifyReturned);
mParticle.Identity.getCurrentUser().setUserAttribute('gender', 'male');
Expand All @@ -581,8 +568,6 @@ describe('identities and attributes', function() {
});

it('should get all user attributes', async () => {
mParticle._resetForTests(MPConfig);

mParticle.init(apiKey, window.mParticle.config);
await waitForCondition(hasIdentifyReturned);
mParticle.Identity.getCurrentUser().setUserAttribute('test', '123');
Expand All @@ -598,7 +583,6 @@ describe('identities and attributes', function() {
});

it('should not set user attribute list if value is not array', async () => {
mParticle._resetForTests(MPConfig);
mParticle.init(apiKey, window.mParticle.config);
await waitForCondition(hasIdentifyReturned);
mParticle.Identity.getCurrentUser().setUserAttributeList(
Expand Down Expand Up @@ -709,8 +693,6 @@ describe('identities and attributes', function() {
});

it('should send user attribute change requests when setting new attributes', async () => {
mParticle._resetForTests(MPConfig);

mParticle.init(apiKey, window.mParticle.config);
await waitForCondition(hasIdentifyReturned);
// set a new attribute, age
Expand Down Expand Up @@ -823,8 +805,6 @@ describe('identities and attributes', function() {
});

it('should send user attribute change requests for the MPID it is being set on', async () => {
mParticle._resetForTests(MPConfig);

mParticle.init(apiKey, window.mParticle.config);
await waitForCondition(hasIdentifyReturned);

Expand Down Expand Up @@ -917,9 +897,8 @@ describe('identities and attributes', function() {
delete window.mParticle.config.flags;
});

// https://go/j-SDKE-420 - Intermittently fails in Firefox due to timing
it('should send user identity change requests when setting new identities on new users', async () => {
mParticle._resetForTests(MPConfig);

fetchMock.resetHistory();

window.mParticle.config.identifyRequest = {
Expand Down Expand Up @@ -1004,11 +983,11 @@ describe('identities and attributes', function() {
});

mParticle.Identity.modify(modifyUser);
await waitForCondition(() => {
return (
mParticle.getInstance()._Store.identityCallInFlight === false
);
});
await waitForCondition(() => {
return (
mParticle.getInstance()._Store.identityCallInFlight === false
);
});
const body2 = JSON.parse(`${fetchMock.lastOptions().body}`);
expect(body2.mpid).to.equal('anotherMPID');
expect(body2.user_identities).to.have.property(
Expand Down Expand Up @@ -1074,6 +1053,7 @@ describe('identities and attributes', function() {
});

mParticle.Identity.logout(logoutUser);
await waitForCondition(hasIdentityCallInflightReturned);
await waitForCondition(() => {
Copy link
Member

Choose a reason for hiding this comment

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

this should be either the await you added OR the await that's already here. there isn't really a reason to have both. I'd test again using just the bottom one, because the fetchMock on line 1051 i the reason the current waitForConfition should be working. if the one you added is more reliable though, that's fine

return (
mParticle.Identity.getCurrentUser()?.getMPID() === 'mpid2'
Expand Down Expand Up @@ -1169,7 +1149,6 @@ describe('identities and attributes', function() {
});

it('should order user identity change events before logging any events that are in the ready queue', async () => {

mParticle._resetForTests(MPConfig);
fetchMock.resetHistory();

Expand Down Expand Up @@ -1235,8 +1214,6 @@ describe('identities and attributes', function() {
});

it('should send historical UIs on batches when MPID changes', async () => {
mParticle._resetForTests(MPConfig);

window.mParticle.config.identifyRequest = {
userIdentities: {
email: 'initial@gmail.com',
Expand Down Expand Up @@ -1268,6 +1245,15 @@ describe('identities and attributes', function() {
mParticle.getInstance()._Store.identityCallInFlight === false
);
});

await waitForCondition(() => {
const currentUser = mParticle.Identity.getCurrentUser();
const userIdentities = currentUser?.getUserIdentities()?.userIdentities;
return userIdentities &&
userIdentities.customerid === 'customerid1' &&
userIdentities.email === 'initial@gmail.com';
});
Copy link
Member

Choose a reason for hiding this comment

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

I think I see why the waitForCondition for identityCallInFlight === false may not be reliable. because it is set to false BEFORE parsing the identityResponse, which is where a lot of the additional logic about making a new current user, happens. So we can probably remove the waitForCondition and leave yours.

Copy link
Member

Choose a reason for hiding this comment

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

This can be a future cleanup ticket once we merge everything in, but at the bottom of the parseIdentityResponse, we do log Successfully parsed Identity Response. I wonder if we should be mocking the logger and waiting for this to be called and then this will basically allow us to know that an identity has been fully returned AND completely parsed.


let batch = JSON.parse(`${fetchMock.lastOptions().body}`);
expect(batch.mpid).to.equal(testMPID);
expect(batch.user_identities).to.have.property(
Expand All @@ -1290,6 +1276,7 @@ describe('identities and attributes', function() {
});

mParticle.Identity.logout(logoutUser);
await waitForCondition(hasIdentityCallInflightReturned);

await waitForCondition(() => {
return (
Expand All @@ -1316,7 +1303,6 @@ describe('identities and attributes', function() {
mParticle.getInstance()._Store.identityCallInFlight === false
);
});
// switching back to logged in user should not result in any UIC events
Copy link
Member

Choose a reason for hiding this comment

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

let's keep this comment

expect(fetchMock.calls().length).to.equal(1);

const data = getIdentityEvent(fetchMock.calls(), 'login');
Expand All @@ -1336,8 +1322,6 @@ describe('identities and attributes', function() {
);
});
it('should not send user attribute change requests when user attribute already set with same value with false values', async () => {
mParticle._resetForTests(MPConfig);

window.mParticle.config.flags = {
EventBatchingIntervalMillis: 0,
};
Expand Down Expand Up @@ -1433,8 +1417,6 @@ describe('identities and attributes', function() {
});

it('should send user attribute change event when setting different falsey values', async () => {
mParticle._resetForTests(MPConfig);

window.mParticle.config.flags = {
EventBatchingIntervalMillis: 0,
};
Expand Down
Loading
Loading