-
Notifications
You must be signed in to change notification settings - Fork 57
test: evaluate resetForTests function #1100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: evaluate resetForTests function #1100
Conversation
d600e65 to
0d87d77
Compare
src/mp-instance.ts
Outdated
| }; | ||
|
|
||
| this._resetForTests = function(config, keepPersistence, instance) { | ||
| if (typeof window !== 'undefined') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this additional resetForTests functionality into the config/setup in the test folder to avoid increasing the size of the SDK for test purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since I realize we use ._resetForTests all over the place, I'd expect it to be something like:
const originalRFT = mParticle._resetForTests;
mParticle._resetForTests = function() {
// all this code here
originalRFT();
}
This way all the future instances of ._resetForTests will run the code + the original _resetForTests function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added additional code in setup.ts to keep everything together. I believe we're already resetting flags there and calling _resetForTests, so the additional code can be added here. Let me know thoughts
src/mp-instance.ts
Outdated
| const forwardingStatsTimer = mParticleSDK?._forwardingStatsTimer; | ||
| if (typeof forwardingStatsTimer === 'number' && mParticleSDK) { | ||
| clearInterval(forwardingStatsTimer); | ||
| mParticleSDK._forwardingStatsTimer = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason this is null but line 230 is 0? I think we should set both to 0
test/src/config/setup.ts
Outdated
| }; | ||
|
|
||
|
|
||
| window.onbeforeunload = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the reason for setting this to null? seems like we should be setting it/mocking it for specific tests that require onbeforeunload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, individual tests like tests-beaconUpload.ts also set it to null before dispatching events, but having it in the global setup acts as a safeguard that ensures clean test isolation for both current and future tests.
When I started working on this I was exploring potential causes of flakiness, so this is just defensive approach even if a someone forgets to clear onbeforeunload in a specific test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I think we should have it only in the test file it's being used. There's a chance an integration test depends on onbeforeunload in the future, and I'd rather be explicit about when it should be null and when it shouldn't. This can probably be part of a cleanup task.
… into test/SDKE-302-evaluate-resetForTests-for-flakey-tests
|
302dd47
into
test/SDKE-300-convert-all-then-to-async-await-in-tests


Background
What Has Changed
resetForTestsfunction for:isTestEnv):eventBatchingIntervalMillis,astBackgroundEvents,offlineStorage(and cleared window.onbeforeunload).window.mParticle.forwardingStatsTimer.Screenshots/Video
Checklist
Additional Notes
resetForTestsfunction.Reference Issue (For employees only. Ignore if you are an outside contributor)