elm / core

Elm's core libraries
http://package.elm-lang.org/packages/elm/core/latest
BSD 3-Clause "New" or "Revised" License
2.8k stars 359 forks source link

Tests for Collage module #162

Closed jazmit closed 8 years ago

jazmit commented 9 years ago

I was pondering how to add tests for Collage, and came up with the idea of using node-canvas to render a data-url and comparing it to a known url.

This would add another test dependency to core, but would add some comfort in making changes to the Native modules.

Perhaps in future it could be combined with a tool to compare the expected DOM output using js-dom or similar and become a general purpose regression testing tool for Elm.

Is this desirable or should we avoid adding extra dependencies to Core?

TheSeamau5 commented 9 years ago

I was wondering, and this is a bit out there as an idea, but, Collage reminds me a lot of Processing.

For example, these two should be equivalent:

Elm:

move (200,200) <|
  filled red <|
    circle 20

Processingjs:

noStroke();
fill(255,0,0);
ellipse(200,200,20,20);

In theory we could have unit tests (or properties) where we fabricate equivalent calls and send them to two different canvases (of equal dimensions of course). We then compare the pixels. If we assume that processing is super stable and not buggy (which it probably is after all the time it's been around), then any inconsistencies we get must come from the collage API (assuming the tests are correct).

Since this is visual, we can always see the output of the two as an image (and optionally a diff of the two outputs) and see if the output from the tests make sense.

(I think in processing the origin is at the top-left and +y is down, so obviously we would have to correct for that)

evancz commented 8 years ago

Sorry this did not get attention til now! The Graphics.* modules now live in evancz/elm-graphics so I am trying to get stuff migrated over there.

Not sure if this makes sense. I expect to be focusing on <canvas> for professional users and "friendly graphics" for learning as separate use cases. Progress will be made when those start happening.