Skip to content
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

Tests failing due to bug in GTM.js #4

Closed
replete opened this issue Aug 4, 2024 · 4 comments
Closed

Tests failing due to bug in GTM.js #4

replete opened this issue Aug 4, 2024 · 4 comments

Comments

@replete
Copy link
Owner

replete commented Aug 4, 2024

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 replete pinned this issue Aug 4, 2024
@replete
Copy link
Owner Author

replete commented Aug 4, 2024

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

@replete replete closed this as completed Aug 4, 2024
@replete replete reopened this Aug 5, 2024
@replete
Copy link
Owner Author

replete commented Aug 5, 2024

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 added a commit that referenced this issue Aug 7, 2024
@replete
Copy link
Owner Author

replete commented Aug 7, 2024

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
Copy link
Owner Author

replete commented Aug 10, 2024

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

@replete replete closed this as completed Aug 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant