We have a node.js app that displays content on partner websites. Our partners include some javascript code in their HTML templates, pointing to our server, and we then use the URL of the page which loads our code to figure out what content to show. Being a third-party script, we mostly rely on document.referrer to get the URL of the including page, but sometimes we are included in an iframe, which complicates things. We are looking to make this code more robust by writing a comprehensive test suite.
Is there a good way to test this type of functionality on the server? We’d need to emulate a browser with javascript support, and it would need to report the referrer like a normal browser would. We’d also need to be able to test cross-origin issues on the server, by simulating domain names, ports etc.
It would be preferable to use node.js for this, but that’s not a requirement.