replete / biscuitman

Biscuitman is a super lightweight open-source privacy consent manager for your website
MIT License
5 stars 0 forks source link

Tests failing due to bug in GTM.js #4

Closed replete closed 1 month ago

replete commented 1 month ago

v0.3.18 CI tests fail due to:

   a fresh load of biscuitman.withcss.min.mjs
    ✓ should load without consents (20 ms)
    ✓ should display a UI (23 ms)
    ✓ should have loaded CSS correctly (24 ms)
    ✓ should open settings modal after clicking settings (37 ms)
    ✓ should close settings modal after clicking close (63 ms)
    ✓ should hide UI and save consents correctly after clicking accept (69 ms)
    ✓ should hide UI and save consents correctly after clicking reject (99 ms)
    ✕ should hide UI and save consents correctly after selecting some sections (166 ms)
    ✓ should remove consent preferences when "bmInvalidate" is called (101 ms)
    ✓ should update consent preferences when "bmUpdate" is called (27 ms)

  ● a fresh load of biscuitman.withcss.min.mjs › should hide UI and save consents correctly after selecting some sections

    TypeError: Failed to execute 'getValue' on 'CookieDeprecationLabel': Illegal invocation

      at nl (https:/www.googletagmanager.com/gtag/js?id=G-TEST:243:331)
      at c (https:/www.googletagmanager.com/gtag/js?id=G-TEST:559:130)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 79 passed, 80 total
Snapshots:   0 total
Time:        4.808 s
Ran all test suites.
Error: Process completed with exit code 1.

This is a bug in Google Tag Manager's gtm.js: https://support.google.com/tagmanager/thread/288419928/error-failed-to-execute-getvalue-on-cookiedeprecationlabel?hl=en

Will remove once builds sort themselves out when they presumably push out a fix as it only started happening a few days ago. GTM.js is only used in the sandbox, but we use the sandbox for integration tests.

replete commented 1 month ago

Fixed by adding check to jest.setup.js for GTM error

replete commented 1 month ago

I wanted to fix the build process by preventing errors not raised by locally hosted scripts from propogating, but this wasn't so straightforward so for now I'm leaving it as-is and will come back to it in the future.

The tests pass locally

replete commented 1 month ago

Not quite sure how to fix this, seems jest-puppeteer related.

I've opened a question on SO: https://stackoverflow.com/questions/78844702/jest-puppeteer-how-can-i-prevent-javascript-errors-from-third-party-scripts-fro

EDIT: Deleted it as it spent more time being pointlessly edited by internet point chasers

replete commented 1 month ago

It's passing now, presumably GTM.js has been updated by Google, but to prevent this in the future we'll need to somehow ignore page errors except for self-hosted ones. I've attempted this with a few methods and not got anywhere, javascript errors are baked in as test failures so it's hard to avoid this, even with replacing window.onerror.

gov UK design system repo uses request interception to mock response to avoid these kind of issues, which might be what we need to do: https://github.com/alphagov/govuk-design-system/blob/main/__tests__/helpers/google-tag-manager.js