Closed (fixed)
Project:
Posthog Analytics integration
Version:
1.x-dev
Component:
Code (posthog_cookies)
Priority:
Minor
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
27 Feb 2025 at 09:03 UTC
Updated:
2 Dec 2025 at 11:14 UTC
Jump to comment: Most recent
Comments
Comment #2
grevil commentedMaybe you find a way to fix the test. I couldn't.
Btw, we actually set the settings via the config object here, so @anybody's assumption, that the config object exists in another Drupal session than the one we control via UI inside the tests is incorrect!
Comment #4
lrwebks commentedThe problem might be caused by the JS aggregation itself, since all JS is merged into a single file then, which can of course be the reason for the missing library files. However, @grevil told me that the code for these cookie tests was mostly taken from the “COOKiES” module, so we might need to have a look regarding the correctness there too?
Comment #5
lrwebks commentedComment #6
anybodyWe should also consider the option that the test is correct and with aggregation enabled posthog isn't currently handled correctly, because we need to explicitly disable aggregation, if that's needed for the knockout!
Like we do for other libraries:
https://git.drupalcode.org/project/cookies/-/blob/2.x/modules/cookies_gt...
I don't have the time currently to dig deeper, but either the test has wrong assumptions or the posthog_cookies implementation is wrong.
To find that out, we should manually tests the expected behaviour first, with aggregation enabled and see if it's right or wrong.
Can you follow my thoughts @grevil? We had similar cases with other libraries before...
Comment #7
grevil commentedOn a real site, everything works as expected. Only the test fails.
Comment #8
anybodyOk then the test is wrong and also @lrwebks's assumption is correct, regarding the (exprected) aggregation.
Comment #9
grevil commentedOk, the js preprocessing (aggregation behavior) was overridden in our local dev environments "settings.local.php", meaning I have never seen any js / css aggregation in Drupal ever.
I adjusted the tests slightly, so that they should run theoretically now, but they don't.
As @lrwebks correctly mentioned, we can't check for any files directly if they are aggregated. This Test works in other cookies submodules, because there we manually disable any js aggregation, so we can morph the "data-src" attribute, but we don't need to do that here (see @anybody's example code here).
I disabled the file check, so now a different error appears:
Sounds like a racing condition to me? Maybe also something different. But I just tested it with ACTUAL js aggregation in my test site and the module works fine with js_aggregation enabled. So its a test error.
Comment #10
anybodyYeah I agree this looks like a race-condition or external sources (Posthog) are not loaded in tests (e.g. for security reasons that would make some sense to me).
drupalSettings.posthog_jsis undefined in posthog_cookies.jsLet's come back here later, if we have an idea for the root cause. Good to know it actually works in real-life.
Comment #11
grevil commentedFixed through #3558457: Overhaul Cookies integration using new Posthog best practices .
Comment #13
grevil commented