- Issue created by @Grevil
- π©πͺGermany Grevil
Maybe 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!
- Merge request !30Issue #3509331: Fix posthog cookies js aggregation test β (Open) created by Grevil
- π©πͺGermany lrwebks Porta Westfalica
The 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?
- π©πͺGermany Anybody Porta Westfalica
We 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...
- π©πͺGermany Grevil
We should also consider the option that the test is correct and with aggregation enabled posthog isn't currently handled correctly
On a real site, everything works as expected. Only the test fails.
- π©πͺGermany Anybody Porta Westfalica
Ok then the test is wrong and also @lrwebks's assumption is correct, regarding the (exprected) aggregation.
- π©πͺGermany Grevil
Ok, 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:
Drupal\Tests\posthog_cookies\FunctionalJavascript\PosthogCookiesFunctionalJavascriptTest::testPosthogCorrectlyKnockedWithJsAggregation
TypeError: Cannot read properties of undefined (reading 'init_config_json')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.
- π©πͺGermany Anybody Porta Westfalica
Yeah 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_js
is 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.