Introduce unit test based on image comparison#3988
Merged
tannerlinsley merged 1 commit intochartjs:masterfrom Mar 5, 2017
Merged
Introduce unit test based on image comparison#3988tannerlinsley merged 1 commit intochartjs:masterfrom
tannerlinsley merged 1 commit intochartjs:masterfrom
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.
Member
Author
Contributor
|
Spectacular!! |
Contributor
|
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 |
roicos
pushed a commit
to roicos/Chart.js
that referenced
this pull request
Aug 21, 2017
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.
exwm
pushed a commit
to exwm/Chart.js
that referenced
this pull request
Apr 30, 2021
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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 thefillerplugin), add auto tests for the line elementfilloptions.Creating image based unit tests
test/fixtures/{spec.name}/{feature-name}.json.specs/{spec.name}.js."debug": truein 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: truefrom 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,
toleranceand orthresholdneed to be adjusted at the beginning of the JSON file and kept as low as possible.