Skip to content

Simplify the process of creating baselines using Kaleido and improve image & other export test systems #5724

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

Merged
merged 59 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
0aced42
generate baselines by new system and using kaleido
archmoj Jun 10, 2021
f166d35
provide googleFonts for image test
archmoj Jun 11, 2021
96b3d5e
provide liberation2 fonts for image test
archmoj Jun 10, 2021
9fb28a3
provide noto font for japanese and gl3d_world-cals baselines
archmoj Jun 10, 2021
71cb928
Revise exports & baseline creation and testing using Kaleido
archmoj Jun 10, 2021
0f9292c
pin down versions in export test similar to image test
archmoj Jun 11, 2021
23ff879
add info on how to draft new baselines
archmoj Jun 14, 2021
ff9b12f
remove image viewer - one could use GitHub os vs-code
archmoj Jun 14, 2021
f23e4cb
move important info on making baselines and remove fat docker readme
archmoj Jun 14, 2021
e8f3d88
remove redundant start-test_dashboard
archmoj Jun 14, 2021
0dc8a41
Merge remote-tracking branch 'origin/master' into switch-to-kaleido
archmoj Jun 15, 2021
ca18710
Update test/image/make_baseline.py
archmoj Jun 15, 2021
fe0502c
Update test/image/make_baseline.py
archmoj Jun 15, 2021
02248d4
Update test/image/make_baseline.py
archmoj Jun 15, 2021
027323e
esp > eps
archmoj Jun 15, 2021
13322c5
test eps export on ci
archmoj Jun 15, 2021
7a44a8e
simplify exclude black lists
archmoj Jun 15, 2021
b1de0bb
reduce pixelmatch threshold to 0 for non-mapbox also fail on mapbox b…
archmoj Jun 17, 2021
4a28781
Merge remote-tracking branch 'origin/master' into switch-to-kaleido
archmoj Jun 18, 2021
82b0ead
update master new baselines using kaleido
archmoj Jun 18, 2021
f0c9e24
adjust bar_show_narrow test
archmoj Jun 18, 2021
4b1b383
Revert "adjust bar_show_narrow test"
archmoj Jun 21, 2021
74853f4
do not keep liberation2 fonts on the repo
archmoj Jun 23, 2021
6522bd5
install liberation2 fonts in docker
archmoj Jun 23, 2021
1786204
do not keep NotoSerifCJK fonts on the repo
archmoj Jun 23, 2021
9f705f7
install NotoSansCJK fonts in docker
archmoj Jun 23, 2021
083f9be
update japanese baseline
archmoj Jun 23, 2021
bb6abea
do not keep Raleway fonts on the repo
archmoj Jun 23, 2021
28077d1
add script to download some google fonts
archmoj Jun 23, 2021
856009e
update baselines using new Raleway fonts
archmoj Jun 23, 2021
f7f4cf1
do not keep Roboto fonts on the repo
archmoj Jun 23, 2021
21e262f
download Roboto fonts
archmoj Jun 23, 2021
9c71d22
update legend_horizontal_autowrap using new Roboto fonts
archmoj Jun 23, 2021
141e40d
do not keep PT_Sans-Narrow fonts on the repo
archmoj Jun 23, 2021
c1341fa
download PT_Sans-Narrow-Web
archmoj Jun 23, 2021
e791887
wip to download OpenSans fonts - could cause big diff
archmoj Jun 23, 2021
0c5d366
do not keep OldStandard fonts on the repo
archmoj Jun 23, 2021
d7548b1
download Old_Standar_dTT
archmoj Jun 24, 2021
09eb8fa
update baselines using new Old_Standard_TT fonts
archmoj Jun 24, 2021
2100fe9
Merge remote-tracking branch 'origin/master' into switch-to-kaleido
archmoj Jun 24, 2021
be8b865
generate baselines using new system
archmoj Jun 24, 2021
1a7461f
do not keep Droid_Sans fonts on the repo
archmoj Jun 24, 2021
1afa2fe
download NotoSans fonts instead of Driod_Sans
archmoj Jun 24, 2021
2a7071f
use NotoSans fonts instead of Driod_Sans
archmoj Jun 24, 2021
ab4b4f9
update baselines using NotoSans instead of Driod_Sans
archmoj Jun 24, 2021
8ad4a68
do not keep Droid_Serif fonts on the repo
archmoj Jun 24, 2021
3bfb395
download NotoSerif fonts instead of Driod_Serif
archmoj Jun 24, 2021
db307f6
use NotoSerif fonts instead of Driod_Serif
archmoj Jun 24, 2021
a4996d0
update baselines using NotoSerif instead of Driod_Serif
archmoj Jun 24, 2021
d1dcafb
do not keep Droid_Sans_Mono font on the repo
archmoj Jun 24, 2021
e98ce87
download NotoSansMono fonts instead of Driod_Sans_Mono
archmoj Jun 24, 2021
d65ee01
use NotoSansMono fonts instead of Driod_Sans_Mono
archmoj Jun 24, 2021
d99dd7f
update baselines using NotoSansMono instead of Driod_Sans_Mono
archmoj Jun 24, 2021
5996af1
do not keep Gravitas_One font on the repo
archmoj Jun 24, 2021
2b8d3ba
download GravitasOne
archmoj Jun 24, 2021
6a15c9e
do not keep Balto fonts on the repo
archmoj Jun 24, 2021
dd1dc35
use Roboto instead of Balto - Roboto used to be in legend_horizontal_…
archmoj Jun 24, 2021
b6a881e
update baselines using Roboto instead of Balto
archmoj Jun 24, 2021
5756afe
update CircleCi task description
archmoj Jun 24, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
105 changes: 83 additions & 22 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,41 +78,96 @@ jobs:
name: Run jasmine tests (part C)
command: ./.circleci/test.sh no-gl-flaky-jasmine

stable-image:
docker:
- image: plotly/testbed:latest
make-baselines:
parallelism: 4
working_directory: /var/www/streambed/image_server/plotly.js/
docker:
- image: circleci/python:3.8.9
working_directory: ~/plotly.js
steps:
- attach_workspace:
at: /var/www/streambed/image_server/
at: ~/
- run:
name: which pip3 version
command: which pip3 && pip3 --version
- run:
name: install kaleido v0.2.1
command: python3 -m pip install kaleido==0.2.1
Comment on lines +93 to +94
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: install kaleido v0.2.1
command: python3 -m pip install kaleido==0.2.1
name: install kaleido
command: pip install kaleido==0.2.1

again, in this env we should only have one pip to worry about... also let's not repeat the version number. (applies several places below too)

- run:
name: Run and setup container
name: install plotly.io v4.14.3
command: python3 -m pip install plotly==4.14.3
- run:
name: install liberation2 fonts
command: sudo apt-get install fonts-liberation2
- run:
name: install NotoSansCJK fonts
command: sudo apt install fonts-noto-cjk
- run:
name: download google fonts e.g. GravitasOne, NotoSansMono, NotoSans, NotoSerif, Old_Standard_TT, PT_Sans_Narrow, Raleway and Roboto
command: python3 ./.circleci/download_google_fonts.py
- run:
name: install OpenSans as well as downloaded google fonts
command: |
supervisord &
npm run docker -- setup
sudo cp -r .circleci/fonts/ /usr/share/
sudo fc-cache -f
- run:
name: create all png files
command: ./.circleci/test.sh make-baselines
- persist_to_workspace:
root: ~/
paths:
- plotly.js

test-baselines:
docker:
- image: circleci/node:12.22.1
working_directory: ~/plotly.js
steps:
- attach_workspace:
at: ~/
- run:
name: Run image tests (part A)
command: ./.circleci/test.sh stable-image || { tar -cvf build/baselines.tar build/test_images/ ; exit 1; } ; find build -maxdepth 1 -type f -delete
name: compare pixels
command: ./.circleci/test.sh test-image ; find build -maxdepth 1 -type f -delete
- store_artifacts:
path: build
destination: /

flaky-image:
make-exports:
docker:
- image: plotly/testbed:latest
working_directory: /var/www/streambed/image_server/plotly.js/
- image: circleci/python:3.8.9
working_directory: ~/plotly.js
steps:
- attach_workspace:
at: /var/www/streambed/image_server/
at: ~/
- run:
name: Run and setup container
command: |
supervisord &
npm run docker -- setup
name: which pip3 version
command: which pip3 && pip3 --version
- run:
name: install kaleido v0.2.1
command: python3 -m pip install kaleido==0.2.1
- run:
name: install plotly.io v4.14.3
command: python3 -m pip install plotly==4.14.3
- run:
name: Run image tests (part B)
command: ./.circleci/test.sh flaky-image ; find build -maxdepth 1 -type f -delete
name: install poppler-utils to have pdftops for exporting eps
command: sudo apt-get install poppler-utils
- run:
name: create svg, jpg, jpeg, webp, pdf and eps files
command: python3 test/image/make_exports.py
- persist_to_workspace:
root: ~/
paths:
- plotly.js

test-exports:
docker:
- image: circleci/node:12.22.1
working_directory: ~/plotly.js
steps:
- attach_workspace:
at: ~/
- run:
name: test export sizes
command: node test/image/export_test.js ; find build -maxdepth 1 -type f -delete
- store_artifacts:
path: build
destination: /
Expand Down Expand Up @@ -237,12 +292,18 @@ workflows:
- no-gl-flaky-jasmine:
requires:
- install-and-cibuild
- stable-image:
- make-baselines:
requires:
- install-and-cibuild
- flaky-image:
- test-baselines:
requires:
- make-baselines
- make-exports:
requires:
- install-and-cibuild
- test-exports:
requires:
- make-exports
- mock-validation:
requires:
- install-and-cibuild
Expand Down
109 changes: 109 additions & 0 deletions .circleci/download_google_fonts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import requests

dirOut = '.circleci/fonts/truetype/googleFonts/'

def download(repo, family, types) :
for t in types :
name = family + t + '.ttf'
url = repo + name + '?raw=true'
print(url)
req = requests.get(url, allow_redirects=True)
open(dirOut + name, 'wb').write(req.content)

download(
'https://github.com/googlefonts/noto-fonts/blob/main/hinted/ttf/NotoSansMono/',
'NotoSansMono',
[
'-Regular',
'-Bold'
]
)

download(
'https://github.com/googlefonts/noto-fonts/blob/main/hinted/ttf/NotoSans/',
'NotoSans',
[
'-Regular',
'-Italic',
'-Bold'
]
)

download(
'https://github.com/googlefonts/noto-fonts/blob/main/hinted/ttf/NotoSerif/',
'NotoSerif',
[
'-Regular',
'-Italic',
'-Bold',
'-BoldItalic',
]
)

download(
'https://github.com/google/fonts/blob/main/ofl/oldstandardtt/',
'OldStandard',
[
'-Regular',
'-Italic',
'-Bold'
]
)

"""
download(
'https://github.com/googlefonts/opensans/blob/main/fonts/ttf/',
'OpenSans',
[
'Bold',
'BoldItalic',
'ExtraBold',
'ExtraBoldItalic',
'Italic',
'Light',
'LightItalic',
'Regular',
'Semibold',
'SemiboldItalic',
]
)
"""

download(
'https://github.com/google/fonts/blob/main/ofl/ptsansnarrow/',
'PT_Sans-Narrow-Web',
[
'-Regular',
'-Bold'
]
)

download(
'https://github.com/impallari/Raleway/blob/master/fonts/v3.000%20Fontlab/TTF/',
'Raleway',
[
'-Regular',
'-Regular-Italic',
'-Bold',
'-Bold-Italic'
]
)

download(
'https://github.com/googlefonts/roboto/blob/main/src/hinted/',
'Roboto',
[
'-Regular',
'-Italic',
'-Bold',
'-BoldItalic'
]
)

download(
'https://github.com/expo/google-fonts/blob/master/font-packages/gravitas-one/',
'GravitasOne',
[
'_400Regular'
]
)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 5 additions & 7 deletions .circleci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,14 @@ case $1 in
exit $EXIT_STATE
;;

stable-image)
SUITE=$(find $ROOT/test/image/mocks/ -type f -printf "%f\n" | circleci tests split)
npm run test-image -- $SUITE --filter --skip-flaky || EXIT_STATE=$?
make-baselines)
SUITE=$(find $ROOT/test/image/mocks/ -type f -printf "%f\n" | sed 's/\.json$//1' | circleci tests split)
python3 test/image/make_baseline.py $SUITE || EXIT_STATE=$?
exit $EXIT_STATE
;;

flaky-image)
MAX_AUTO_RETRY=5
retry npm run test-image -- --just-flaky
npm run test-export || EXIT_STATE=$?
test-image)
node test/image/compare_pixels_test.js || { tar -cvf build/baselines.tar build/test_images/*.png ; exit 1 ; } || EXIT_STATE=$?
exit $EXIT_STATE
;;

Expand Down
48 changes: 30 additions & 18 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Thanks for your interest in contributing to Plotly.js! We are actively looking for
diverse contributors, with diverse background and skills.

This document outlines the general way that changes get made to this library and by whom,
and then provides specific technical information about how to set up a development
This document outlines the general way that changes get made to this library and by whom,
and then provides specific technical information about how to set up a development
environment for doing development and running tests.

## Code of Conduct
Expand All @@ -25,7 +25,7 @@ The basic architecture of Plotly.js is to accept [JSON](https://json.org/) repre
The basic process for adding new features or fixing bugs is as follows. Please note that this is a bit of an idealized outline and that things often don't proceed in a clean/linear fashion and that's ok :)

1. **Discussion** - A community member or maintainer creates an issue to discuss the use-case for the new feature. This usually entails describing the desired graphical output and discussing how close the current system can get to specifying or drawing such a figure. If the issue is perceived to be a bug, the discussion revolves around understanding how the current behaviour is incorrect or problematic, and how existing users of the system would be impacted by a change in this behaviour.
2. **Proposal** - If the current system cannot specify or draw such a figure, or if the way to do it is too onerous, a good next step would be to discuss or propose a specific change to the schema: new attributes to be added or new accepted values to new attributes, along with a prose description of the proposed drawing code. If the issue is determined to be a bug rather than a feature, the same type of proposal is required: a definition of which attributes and values will be impacted by the proposed change. A good proposal includes discussion of whether or not existing attributes can be modified rather than adding new attributes and details about which trace types or subplot types are impacted by the change. Note: sometimes community contributors skip this step and go straight to development & review (below), but going through a proposal can help speed along the review process!
2. **Proposal** - If the current system cannot specify or draw such a figure, or if the way to do it is too onerous, a good next step would be to discuss or propose a specific change to the schema: new attributes to be added or new accepted values to new attributes, along with a prose description of the proposed drawing code. If the issue is determined to be a bug rather than a feature, the same type of proposal is required: a definition of which attributes and values will be impacted by the proposed change. A good proposal includes discussion of whether or not existing attributes can be modified rather than adding new attributes and details about which trace types or subplot types are impacted by the change. Note: sometimes community contributors skip this step and go straight to development & review (below), but going through a proposal can help speed along the review process!
3. **Iteration** - The maintainers of the library or any other interested community member will then give feedback on the proposal, usually focused on consistency with the rest of the schema, and helping define a test plan to further elaborate potential edge cases.
4. **Approval** - After a number of iterations, the maintainers of the library will generally approve a proposal with an informal "this seems like something we would accept a pull request for" comment in the issue.
5. **Development** - A community member or maintainer creates a branch and makes the appropriate modifications to the code and tests and opens a pull request. This can be more or less time-consuming and challenging, depending on the nature of the change.
Expand Down Expand Up @@ -207,23 +207,35 @@ npm run test-jasmine -- --help
npm run test-jasmine -- --info
```

### Image pixel comparison tests

Image pixel comparison tests are run in a docker container. For more
information on how to run them locally, please refer to [image test
README](https://github.com/plotly/plotly.js/blob/master/test/image/README.md).

Running the test locally outputs the generated png images in `build/test_images/` and the png diffs in `build/test_images_diff/` (two git-ignored directories).

To view the image pixel comparison test results, run

### Draft new baseline
Install fonts and tools
```sh
# install required fonts (if missing) on ubuntu
sudo cp -r .circleci/fonts/ /usr/share/ && sudo fc-cache -f
# upgrade pip (if needed)
python3 -m pip install --upgrade pip
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear re: my earlier comments - here the instructions are for local use, so using the longer python3 -m pip syntax is reasonable as a way to indicate to users that it's important to do this with Python 3 if nothing else :)

# install kaleido
python3 -m pip install kaleido
# install plotly
python3 -m pip install plotly
```
npm run start-image_viewer
```

which shows the baseline image, the generated image, the diff and the json mocks of test cases that failed.

To view the results of a run on CircleCI, download the `build/test_images/` and `build/test_images_diff/` artifacts into your local repo and then run `npm run start-image_viewer`.
**IMPORTANT:** the `baseline`, `test-image` and `test-export` scripts do **not** bundle the source files before
running the image tests. We recommend running `npm run watch` or `npm start` in
a separate tab to ensure that the most up-to-date code is used.
Also if you are adding a new mock, you may need to re-run `npm start` or `npm run watch`
to be able to find the new mock in the browser.
To help ensure valid attributes are used in your new mock(s), please run `npm run test-mock`
or `npm run test-mock mock_name(s)` after adding new mocks or implementing any new attributes.

If you added new mocks to test/image/mocks folder, to generate draft baselines run
```sh
python3 test/image/make_baseline.py = mockFilename1 mockFilename2
```
Then commit the new baselines and push.
Please note that image pixel comparison tests run using circleci/python:3.8.9 docker container.
Therefore the final baselines may need updates.
This could simply be done by downloading the `baselines.tar` stored in the `ARTIFACTS` tab of `test-baselines` job (if the test failed).

### Using the developer console in karma to write/debug jasmine tests

Expand Down
12 changes: 0 additions & 12 deletions devtools/image_viewer/index.html

This file was deleted.

Loading