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

give getSrc a better role in this class (tests fix) #3189

Merged
merged 1 commit into from
Aug 22, 2016

Conversation

kherock
Copy link
Contributor

@kherock kherock commented Aug 22, 2016

Working off of #3173.
I'm seeing if I can get this to pass those couple tests. Also, the conditional for checking if the element existed was preventing using this.src as a fallback.

@kherock kherock force-pushed the toSVG branch 3 times, most recently from 2015e3e to 7cfb2de Compare August 22, 2016 02:43
@kherock
Copy link
Contributor Author

kherock commented Aug 22, 2016

Ok. I have a pretty good idea of what needs to be done to have this passing, but I have an important question: What is the expected behavior of getSrc in a Node.js environment? The Image element created by node-canvas uses the src property as a setter taking a Buffer or base64 encoded string, and it gives back a Buffer.

For general use and for testing, wouldn't it make more sense if the tests worked with a base64 data URL? The test that the image source is undefined in a Node environment isn't really proving anything.

@asturur
Copy link
Member

asturur commented Aug 22, 2016

i did not looked in tests yet.
the point of getSrc is that i noticed that when subclassing you may need to have your own src property. you may have a custom class that work on cropped images based on canvas elements that lack .src support and you do not want to use dataUrl as a source.

@kherock
Copy link
Contributor Author

kherock commented Aug 22, 2016

Ok, it turns out those tests were really hacked together to get Node.js stuff to pass. It seems like the author of those wasn't aware of how node-canvas's src property worked.

In the Node.js fabric.util.loadImage override, you can see where the _src property is set to preserve the original url passed in. That property should always be the one returned by getSrc (since it's how toObject serializes the image) since it's what was used to create the image!

The tests aren't leveraging the fabric.util.loadImage (should they? it can handle fs paths), and it looks like the author forgot to also set img._src in the test boilerplate. Setting that and adjusting getSrc to check fabric.isLikelyNode seems to make everything behave as intended.

@asturur
Copy link
Member

asturur commented Aug 22, 2016

Thanks for looking at tests.
I have still to add some tests to see that getSrc returns what expected.
I will merge this for now.

@asturur asturur merged commit 181cdec into fabricjs:master Aug 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants