-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Introduce unit test based on image comparison #3988
Conversation
Attempt to make easier the creation of unit tests that check the drawing output. Until now, this was done by checking calls on a 'fake' context, which is hard to maintain (need to update pixel values by hands) and also not reliable when optimizing code (i.e. different calls sequence but same result). As of now, it's possible to define 'auto' tests based on JSON/PNG fixtures: chart is generated from the JSON file and compared to the associated PNG image. The image diff is done using `pixelmatch`. As an example (and in preparation of the `filler` plugin), add auto tests for the line element `fill` options.
Spectacular!! |
I am trying to create new test. But the canvas seems to be destroyed when running tests so i can not create png file. I assume "debug": true should be put inside test/fixtures/{spec.name}/{feature-name}.json. But I have try putting it everywhere there without success. json: scale-suggestedMin-suggestedMax-no-values.txt is located in test\fixtures\scale.linear test\specs\scale.linear.tests: scale.linear.tests.txt |
Attempt to make easier the creation of unit tests that check the drawing output. Until now, this was done by checking calls on a 'fake' context, which is hard to maintain (need to update pixel values by hands) and also not reliable when optimizing code (i.e. different calls sequence but same result). As of now, it's possible to define 'auto' tests based on JSON/PNG fixtures: chart is generated from the JSON file and compared to the associated PNG image. The image diff is done using `pixelmatch`. As an example (and in preparation of the `filler` plugin), add auto tests for the line element `fill` options.
Attempt to make easier the creation of unit tests that check the drawing output. Until now, this was done by checking calls on a 'fake' context, which is hard to maintain (need to update pixel values by hands) and also not reliable when optimizing code (i.e. different calls sequence but same result). As of now, it's possible to define 'auto' tests based on JSON/PNG fixtures: chart is generated from the JSON file and compared to the associated PNG image. The image diff is done using `pixelmatch`. As an example (and in preparation of the `filler` plugin), add auto tests for the line element `fill` options.
Attempt to make easier the creation of unit tests that check the drawing output. Until now, this was done by checking calls on a 'fake' context, which is hard to maintain (need to update pixel values by hands) and also not reliable when optimizing code (i.e. different calls sequence but same result).
As of now, it's possible to define 'auto' tests based on JSON/PNG fixtures: chart is generated from the JSON file and compared to the associated PNG image. The image diff is done using
pixelmatch
. As an example (and in preparation of thefiller
plugin), add auto tests for the line elementfill
options.Creating image based unit tests
test/fixtures/{spec.name}/{feature-name}.json
.specs/{spec.name}.js
."debug": true
in the JSON file to prevent the canvas destruction when running tests.gulp unittest --watch --inputs=test/specs/{spec.name}.js
.test/fixtures/{spec.name}/{feature-name}.png
.CTRL+R
): test should now pass2.debug: true
from the JSON file.1 Important: generated charts should be as minimal as possible and focus only on tested features to prevent failure if another feature breaks (e.g. disable the title and legend when testing scales).
2 Tests should pass in both browsers, if not,
tolerance
and orthreshold
need to be adjusted at the beginning of the JSON file and kept as low as possible.