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

CORS breaks existing unit testing approach #93

Closed
3 tasks done
fabiodrg opened this issue Oct 29, 2021 · 1 comment · Fixed by #94
Closed
3 tasks done

CORS breaks existing unit testing approach #93

fabiodrg opened this issue Oct 29, 2021 · 1 comment · Fixed by #94
Assignees
Labels
bug Something isn't working test Unit test

Comments

@fabiodrg
Copy link
Collaborator

fabiodrg commented Oct 29, 2021

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.

  • Launch a local web server on /src/test, with a fixed port (customizable env environment is a bonus). Since with already have node, perhaps is the easiest way to create the said server
  • Ensure the web server attaches Access-Control-Allow-Origin: * on all responses
  • Add a prefix with the address for the local web server on all requested HTML files. Update it here:
    function updatejQueryContext(url) {
    ,

I think this is enough!

image

@fabiodrg fabiodrg added bug Something isn't working test Unit test labels Oct 29, 2021
@fabiodrg fabiodrg self-assigned this Oct 29, 2021
@fabiodrg
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working test Unit test
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant