I've spent a significant amount of time trying to implement tests for the canvas operations in the WindArrow class. As I found out testing canvas operations is challenging and not really needed in this case:
The main difficulty lies in the fact that canvas operations involve rendering graphics, which isn't straightforward to test programmatically. While there are libraries like node-canvas that provide a canvas implementation for Node.js, using them to create a canvas, draw on it in tests, and then check the resulting image data can be quite complex.
I believe that in our case, it's not strictly necessary to test the actual drawing on the canvas. The critical parts of the wind_direction.py code are the calculations that determine what should be drawn on the canvas, not the drawing operations themselves.
In this pull request, I've focused on testing these calculations. I've written tests for the constructor, createCanvas, appendCanvasToContainer, and calculateComponents methods of the WindArrow class. These tests check that the methods are correctly setting properties or returning values, and they don't depend on the canvas because they don't actually draw anything on it.
While this does mean that our code coverage for this suffers the actual logic and resulting canvas image seen on the server produce expected results.
Note: Committing package.json and package-lock.json to ensure consistent installation of the same versions of dependencies across different environments, which helps in maintaining the stability of the project. I looked it up and it is recommended to still commit package-lock.json
I've spent a significant amount of time trying to implement tests for the canvas operations in the
WindArrow
class. As I found out testing canvas operations is challenging and not really needed in this case:The main difficulty lies in the fact that canvas operations involve rendering graphics, which isn't straightforward to test programmatically. While there are libraries like
node-canvas
that provide a canvas implementation for Node.js, using them to create a canvas, draw on it in tests, and then check the resulting image data can be quite complex.I believe that in our case, it's not strictly necessary to test the actual drawing on the canvas. The critical parts of the
wind_direction.py
code are the calculations that determine what should be drawn on the canvas, not the drawing operations themselves.In this pull request, I've focused on testing these calculations. I've written tests for the
constructor
,createCanvas
,appendCanvasToContainer
, andcalculateComponents
methods of theWindArrow
class. These tests check that the methods are correctly setting properties or returning values, and they don't depend on the canvas because they don't actually draw anything on it.While this does mean that our code coverage for this suffers the actual logic and resulting canvas image seen on the server produce expected results.
Note: Committing
package.json
andpackage-lock.json
to ensure consistent installation of the same versions of dependencies across different environments, which helps in maintaining the stability of the project. I looked it up and it is recommended to still commitpackage-lock.json
closes #141 closes #149