dailymotion / vast-client-js

VAST (up to 6) parsing library for JavaScript
https://iabtechlab.com/wp-content/uploads/2022/09/VAST_4.3.pdf
MIT License
367 stars 215 forks source link

[QUESTION] How to write automated tests for vast tracking #427

Closed chamino closed 2 years ago

chamino commented 2 years ago

Hi, I'm trying to write integration tests to test that events are sent properly. However, intercept/spy doesn't work in cypress, probably because it's not XHR . Do you have a recommended way to write integration tests?

ZacharieTFR commented 2 years ago

Hello @chamino, Indeed it's not really a XHR request as trackers (or pixels) by definition will be requested through the source of an image tag. https://github.com/dailymotion/vast-client-js/blob/d13ba9a566af10555673ac04b9c1aa4f164a9a44/src/util/util.js#L9 But on my side I'm able to intercept it with cy.intercept and wait like below.

  cy.intercept('GET', 'https://foo.bar/my-first-quartile-tracker-url').as('trackerFirstQuartile')
  cy.wait('@trackerFirstQuartile')

If the tracker url is not requested the wait command will fail with following error No request ever occurred.

Tell me if that works for you, if not can you provide more details ?

chamino commented 2 years ago

Hi, thank you for the tip it works! I was trying to get the callCount which didn't work, but at the end we created an object on window and pushed events there during integration tests so we can verify how many times it's been called. (Like how GTM works).

ZacharieTFR commented 2 years ago

You're welcome ! 👍 I will close this issue then, please feel free to open another one if needed.