Skip to content

Commit f9df5dd

Browse files
authored
Merge pull request #5724 from plotly/switch-to-kaleido
Simplify the process of creating baselines using Kaleido and improve image & other export test systems
2 parents 4f54bcd + 5756afe commit f9df5dd

File tree

1,151 files changed

+625
-1086
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,151 files changed

+625
-1086
lines changed

.circleci/config.yml

+83-22
Original file line numberDiff line numberDiff line change
@@ -78,41 +78,96 @@ jobs:
7878
name: Run jasmine tests (part C)
7979
command: ./.circleci/test.sh no-gl-flaky-jasmine
8080

81-
stable-image:
82-
docker:
83-
- image: plotly/testbed:latest
81+
make-baselines:
8482
parallelism: 4
85-
working_directory: /var/www/streambed/image_server/plotly.js/
83+
docker:
84+
- image: circleci/python:3.8.9
85+
working_directory: ~/plotly.js
8686
steps:
8787
- attach_workspace:
88-
at: /var/www/streambed/image_server/
88+
at: ~/
89+
- run:
90+
name: which pip3 version
91+
command: which pip3 && pip3 --version
92+
- run:
93+
name: install kaleido v0.2.1
94+
command: python3 -m pip install kaleido==0.2.1
8995
- run:
90-
name: Run and setup container
96+
name: install plotly.io v4.14.3
97+
command: python3 -m pip install plotly==4.14.3
98+
- run:
99+
name: install liberation2 fonts
100+
command: sudo apt-get install fonts-liberation2
101+
- run:
102+
name: install NotoSansCJK fonts
103+
command: sudo apt install fonts-noto-cjk
104+
- run:
105+
name: download google fonts e.g. GravitasOne, NotoSansMono, NotoSans, NotoSerif, Old_Standard_TT, PT_Sans_Narrow, Raleway and Roboto
106+
command: python3 ./.circleci/download_google_fonts.py
107+
- run:
108+
name: install OpenSans as well as downloaded google fonts
91109
command: |
92-
supervisord &
93-
npm run docker -- setup
110+
sudo cp -r .circleci/fonts/ /usr/share/
111+
sudo fc-cache -f
112+
- run:
113+
name: create all png files
114+
command: ./.circleci/test.sh make-baselines
115+
- persist_to_workspace:
116+
root: ~/
117+
paths:
118+
- plotly.js
119+
120+
test-baselines:
121+
docker:
122+
- image: circleci/node:12.22.1
123+
working_directory: ~/plotly.js
124+
steps:
125+
- attach_workspace:
126+
at: ~/
94127
- run:
95-
name: Run image tests (part A)
96-
command: ./.circleci/test.sh stable-image || { tar -cvf build/baselines.tar build/test_images/ ; exit 1; } ; find build -maxdepth 1 -type f -delete
128+
name: compare pixels
129+
command: ./.circleci/test.sh test-image ; find build -maxdepth 1 -type f -delete
97130
- store_artifacts:
98131
path: build
99132
destination: /
100133

101-
flaky-image:
134+
make-exports:
102135
docker:
103-
- image: plotly/testbed:latest
104-
working_directory: /var/www/streambed/image_server/plotly.js/
136+
- image: circleci/python:3.8.9
137+
working_directory: ~/plotly.js
105138
steps:
106139
- attach_workspace:
107-
at: /var/www/streambed/image_server/
140+
at: ~/
108141
- run:
109-
name: Run and setup container
110-
command: |
111-
supervisord &
112-
npm run docker -- setup
142+
name: which pip3 version
143+
command: which pip3 && pip3 --version
144+
- run:
145+
name: install kaleido v0.2.1
146+
command: python3 -m pip install kaleido==0.2.1
147+
- run:
148+
name: install plotly.io v4.14.3
149+
command: python3 -m pip install plotly==4.14.3
113150
- run:
114-
name: Run image tests (part B)
115-
command: ./.circleci/test.sh flaky-image ; find build -maxdepth 1 -type f -delete
151+
name: install poppler-utils to have pdftops for exporting eps
152+
command: sudo apt-get install poppler-utils
153+
- run:
154+
name: create svg, jpg, jpeg, webp, pdf and eps files
155+
command: python3 test/image/make_exports.py
156+
- persist_to_workspace:
157+
root: ~/
158+
paths:
159+
- plotly.js
160+
161+
test-exports:
162+
docker:
163+
- image: circleci/node:12.22.1
164+
working_directory: ~/plotly.js
165+
steps:
166+
- attach_workspace:
167+
at: ~/
168+
- run:
169+
name: test export sizes
170+
command: node test/image/export_test.js ; find build -maxdepth 1 -type f -delete
116171
- store_artifacts:
117172
path: build
118173
destination: /
@@ -237,12 +292,18 @@ workflows:
237292
- no-gl-flaky-jasmine:
238293
requires:
239294
- install-and-cibuild
240-
- stable-image:
295+
- make-baselines:
241296
requires:
242297
- install-and-cibuild
243-
- flaky-image:
298+
- test-baselines:
299+
requires:
300+
- make-baselines
301+
- make-exports:
244302
requires:
245303
- install-and-cibuild
304+
- test-exports:
305+
requires:
306+
- make-exports
246307
- mock-validation:
247308
requires:
248309
- install-and-cibuild

.circleci/download_google_fonts.py

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import requests
2+
3+
dirOut = '.circleci/fonts/truetype/googleFonts/'
4+
5+
def download(repo, family, types) :
6+
for t in types :
7+
name = family + t + '.ttf'
8+
url = repo + name + '?raw=true'
9+
print(url)
10+
req = requests.get(url, allow_redirects=True)
11+
open(dirOut + name, 'wb').write(req.content)
12+
13+
download(
14+
'https://github.com/googlefonts/noto-fonts/blob/main/hinted/ttf/NotoSansMono/',
15+
'NotoSansMono',
16+
[
17+
'-Regular',
18+
'-Bold'
19+
]
20+
)
21+
22+
download(
23+
'https://github.com/googlefonts/noto-fonts/blob/main/hinted/ttf/NotoSans/',
24+
'NotoSans',
25+
[
26+
'-Regular',
27+
'-Italic',
28+
'-Bold'
29+
]
30+
)
31+
32+
download(
33+
'https://github.com/googlefonts/noto-fonts/blob/main/hinted/ttf/NotoSerif/',
34+
'NotoSerif',
35+
[
36+
'-Regular',
37+
'-Italic',
38+
'-Bold',
39+
'-BoldItalic',
40+
]
41+
)
42+
43+
download(
44+
'https://github.com/google/fonts/blob/main/ofl/oldstandardtt/',
45+
'OldStandard',
46+
[
47+
'-Regular',
48+
'-Italic',
49+
'-Bold'
50+
]
51+
)
52+
53+
"""
54+
download(
55+
'https://github.com/googlefonts/opensans/blob/main/fonts/ttf/',
56+
'OpenSans',
57+
[
58+
'Bold',
59+
'BoldItalic',
60+
'ExtraBold',
61+
'ExtraBoldItalic',
62+
'Italic',
63+
'Light',
64+
'LightItalic',
65+
'Regular',
66+
'Semibold',
67+
'SemiboldItalic',
68+
]
69+
)
70+
"""
71+
72+
download(
73+
'https://github.com/google/fonts/blob/main/ofl/ptsansnarrow/',
74+
'PT_Sans-Narrow-Web',
75+
[
76+
'-Regular',
77+
'-Bold'
78+
]
79+
)
80+
81+
download(
82+
'https://github.com/impallari/Raleway/blob/master/fonts/v3.000%20Fontlab/TTF/',
83+
'Raleway',
84+
[
85+
'-Regular',
86+
'-Regular-Italic',
87+
'-Bold',
88+
'-Bold-Italic'
89+
]
90+
)
91+
92+
download(
93+
'https://github.com/googlefonts/roboto/blob/main/src/hinted/',
94+
'Roboto',
95+
[
96+
'-Regular',
97+
'-Italic',
98+
'-Bold',
99+
'-BoldItalic'
100+
]
101+
)
102+
103+
download(
104+
'https://github.com/expo/google-fonts/blob/master/font-packages/gravitas-one/',
105+
'GravitasOne',
106+
[
107+
'_400Regular'
108+
]
109+
)
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.

.circleci/test.sh

+5-7
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,14 @@ case $1 in
7676
exit $EXIT_STATE
7777
;;
7878

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

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

CONTRIBUTING.md

+30-18
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
Thanks for your interest in contributing to Plotly.js! We are actively looking for
44
diverse contributors, with diverse background and skills.
55

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

1010
## Code of Conduct
@@ -25,7 +25,7 @@ The basic architecture of Plotly.js is to accept [JSON](https://json.org/) repre
2525
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 :)
2626

2727
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.
28-
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!
28+
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!
2929
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.
3030
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.
3131
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.
@@ -207,23 +207,35 @@ npm run test-jasmine -- --help
207207
npm run test-jasmine -- --info
208208
```
209209

210-
### Image pixel comparison tests
211-
212-
Image pixel comparison tests are run in a docker container. For more
213-
information on how to run them locally, please refer to [image test
214-
README](https://github.com/plotly/plotly.js/blob/master/test/image/README.md).
215-
216-
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).
217-
218-
To view the image pixel comparison test results, run
219-
210+
### Draft new baseline
211+
Install fonts and tools
212+
```sh
213+
# install required fonts (if missing) on ubuntu
214+
sudo cp -r .circleci/fonts/ /usr/share/ && sudo fc-cache -f
215+
# upgrade pip (if needed)
216+
python3 -m pip install --upgrade pip
217+
# install kaleido
218+
python3 -m pip install kaleido
219+
# install plotly
220+
python3 -m pip install plotly
220221
```
221-
npm run start-image_viewer
222-
```
223-
224-
which shows the baseline image, the generated image, the diff and the json mocks of test cases that failed.
225222

226-
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`.
223+
**IMPORTANT:** the `baseline`, `test-image` and `test-export` scripts do **not** bundle the source files before
224+
running the image tests. We recommend running `npm run watch` or `npm start` in
225+
a separate tab to ensure that the most up-to-date code is used.
226+
Also if you are adding a new mock, you may need to re-run `npm start` or `npm run watch`
227+
to be able to find the new mock in the browser.
228+
To help ensure valid attributes are used in your new mock(s), please run `npm run test-mock`
229+
or `npm run test-mock mock_name(s)` after adding new mocks or implementing any new attributes.
230+
231+
If you added new mocks to test/image/mocks folder, to generate draft baselines run
232+
```sh
233+
python3 test/image/make_baseline.py = mockFilename1 mockFilename2
234+
```
235+
Then commit the new baselines and push.
236+
Please note that image pixel comparison tests run using circleci/python:3.8.9 docker container.
237+
Therefore the final baselines may need updates.
238+
This could simply be done by downloading the `baselines.tar` stored in the `ARTIFACTS` tab of `test-baselines` job (if the test failed).
227239

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

devtools/image_viewer/index.html

-12
This file was deleted.

0 commit comments

Comments
 (0)