-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Cannot run jsdom unit tests for files that import Plotly due to missing browser functions #3239
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
Comments
First of all, thank you @Camru for your interest in Plotly.js! As of right now, Plotly.js is designed to run in a real browser. For example, some traces type leverage WebGL which isn't supported by |
Yeah, this has come up a lot before. Getting plotly.js to work in jsdom would be nice, but it's not something plotly.js team member will dedicate time to. That said, we'll potentially accept a community PR that finds a viable solution to this problem. |
@Camru in order to simply run plotly.js in jsdom, looks like you only need to mock two things: // mock a few things that JSDOM doesn't support out-of-the-box
w.HTMLCanvasElement.prototype.getContext = function() { return null; };
w.URL.createObjectURL = function() { return null; }; See full example -> https://gist.github.com/etpinard/58a9e054b9ca7c0ca4c39976fc8bbf8a |
@etpinard your solution works great! Failed to make it export anything other then SVG... But this will do. |
We use Plotly with its React component .
So I'm not sure how your solution applies here. If you can please give an example. Any way, If you'll please give me some guidance on where to start, I can work on that issue. We really need to be able to test our app :) |
I can't even run plotly in a node script using |
I get the same error @mhkeller |
Same error as well, following the instructions at https://github.com/plotly/plotly.js#load-as-a-node-module. |
In case this is useful to folks, I put together this little node library that opens up a window with the plotly chart rendered: https://github.com/mhkeller/plot |
I'm trying to get my QUnit tests running in a Node.js module I've created, but like others above I'm getting |
We are using Plotly in our react application and are currently experiencing issues while unit testing components that import the Plotly library either directly, or further down the component tree.
Currently we are using the latest versions of jsdom and mocha to run our unit tests.
It appears the issue is in the Plotly node module, because our unit test suite breaks due to undefined functions in
node_modules/plotly.js/dist/plotly.js
For example we get:
We have attempted to stub that function (as mentioned in the closed issue #1675), but more undefined functions arise and it becomes a bit of a rabbit hole trying to stub all of the missing functions.
The text was updated successfully, but these errors were encountered: