Open jamesdigid opened 2 years ago
I am also facing this issue in latest version.
I created a project with min. configuration to reproduce this. I believe this is an issue with jest not supporting the webpack "auto" configuration https://github.com/Zaid-Safadi/wado-loader-unit-test/tree/master
@swederik , this started happening after setting the publicPath to auto in this commit #399 , is this needed for production to make the library work?
I believe it was necessary when I was getting the dynamic imports working for the codecs inside the web workers. Previously we had an empty string, then there was a commit which set it to '/' (https://github.com/cornerstonejs/cornerstoneWADOImageLoader/commit/f88b236dc9017db3956611309398c6b9609112c2) and then 'auto', which also looks like it is the default for the option itself: https://webpack.js.org/configuration/output/#outputpublicpath
If you don't want it to be set to auto, what do you want it to be set to? "/" ? Won't that break when someone tries to use a consuming application (e.g. OHIF) at a subdirectory (e.g. mywebsite.com/ohif/)? It will try to fetch the codecs from mywebsite.com/ and fail. Open to ideas!
I think setting the value in the library to "auto" is the right thing to allow the consuming app to configure this based on the hosting url. It just doesn't seem to be supported with jest and causing any unit test that reference the library to fail.
Cypress seems to have a similar issue but there are some workarounds here: https://github.com/cypress-io/cypress/issues/18435
Trying to see if there is a similar solution or workaround for jest otherwise no unit tests can run with the library
@swederik
cornerstoneWebImageLoader
doesn't set it to auto:
https://github.com/cornerstonejs/cornerstoneWebImageLoader/blob/master/config/webpack/webpack-base.js
cornerstoneTools
doesn't set it too:
https://github.com/cornerstonejs/cornerstoneTools/blob/master/config/webpack/webpack-base.js
It's currently failing for me with Jest, Cypress and Vitest.
I don't think this is something caused by an update to cornerstoneWADOImageLoader but more to the updated versions of the webpack/jest...
The way I solved this is by using the library https://github.com/jsdom/jsdom as a dev dependency to provide the required DOM objects
What you will need is on startup/init of your unit-test library (e.g. jest)
@Zaid-Safadi
Thank you, I was able to do that in "vitest" in "jsdom" environment with the following:
const script = global.document.createElement("script");
script.setAttribute("src", "/");
Object.defineProperty(global.document, "currentScript", {
value: script
});
update: same for the Cypress
For me, I'm using SvelteKit + this library. I found that webpack was looking for document.currentScript (as stated above), but whatever reason that doesn't exist when using SvelteKit. In the webpack code, if that fails it looks for the last <script>
tag on the page, and looks for its src
attribute. In the instance of SvelteKit, that also doesn't exist, so it throws the error in the OP.
If you used vite to scaffold your project, your app.html should look something like this.
The workaround I've found is to simply change app.html to have a script tag at the end of the file like this:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- head stuff -->
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
<!-- workaround to let webpack scripts work properly -->
<script type="text/javascript" src=""></script>
</html>
Hope this helps someone else. I spent a good week looking into this, and finally figured out the cause.
I don't think this is something caused by an update to cornerstoneWADOImageLoader but more to the updated versions of the webpack/jest...
We're getting this in Storybook after adding cornerstone-wado-image-loader. Removing this dependency makes the error go away.
I'm getting the follow issues during our pipeline build after doing an upgrade.
Here is my webpack config:
Any suggestions or advice would be appreciated. Thanks