msramalho / SigTools

📆 Sigarra Tools | An extension that makes the information system of the University of Porto slightly better.
https://chrome.google.com/webstore/detail/sigarra-to-calendar/piefgbacnljenipiifjopkfifeljjkme
Apache License 2.0
37 stars 0 forks source link

CORS breaks existing unit testing approach #93

Closed fabiodrg closed 2 years ago

fabiodrg commented 2 years ago

The current unit test approach relies on loading HTML files dynamically and updating the jQuery context. Loading the HTML file results in a GET request with the file protocol. Well, it seems both Firefox and Chrome's CORS (Cross-Origin Resource Sharing) policies are stricter.

Access to XMLHttpRequest at 'file:///.../SigTools/src/test/pages/datatables/single_row.html' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.

I think the error message is quite clear. The easiest solution, I can think of, is to launch a small server on development mode that serves the test HTML files. However, the server must also add the header Access-Control-Allow-Origin: * to all responses.

I think this is enough!

image

fabiodrg commented 2 years ago

Just lost 15 minutes because the browser was caching the test HTML file... if we implement the web server, I believe there is a header in the response to tell browsers "do not cache this resource"! Might be useful