Skip to content

Commit 7a2dc05

Browse files
committed
Merge branch 'master' into heatmap-multi-trace
2 parents 897cb6f + d16393b commit 7a2dc05

12 files changed

+425
-222
lines changed

tasks/baseline.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ CMD=(
1414
"cp -f test/image/index.html ../server_app/index.html &&"
1515
"supervisorctl restart nw1 &&"
1616
"wget --server-response --spider --tries=10 --retry-connrefused http://localhost:9010/ping &&"
17-
"node test/image/make_baseline.js $1"
17+
"node test/image/make_baseline.js $@"
1818
)
1919

2020
docker exec -i $CONTAINER_NAME /bin/bash -c "${CMD[*]}"

tasks/pretest.js

+8
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,11 @@ var setPlotConfig = [
3636
fs.writeFile(constants.pathToSetPlotConfig, setPlotConfig, function(err) {
3737
if(err) throw err;
3838
});
39+
40+
// make artifact folders for image tests
41+
if(!fs.existsSync(constants.pathToTestImagesDiff)) {
42+
fs.mkdirSync(constants.pathToTestImagesDiff);
43+
}
44+
if(!fs.existsSync(constants.pathToTestImages)) {
45+
fs.mkdirSync(constants.pathToTestImages);
46+
}

tasks/test_export.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ CMD=(
1414
"cp -f test/image/index.html ../server_app/index.html &&"
1515
"supervisorctl restart nw1 && "
1616
"wget --server-response --spider --tries=10 --retry-connrefused http://localhost:9010/ping &&"
17-
"node test/image/export_test.js $1"
17+
"node test/image/export_test.js $@"
1818
)
1919

2020
docker exec -i $CONTAINER_NAME /bin/bash -c "${CMD[*]}"

tasks/test_image.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ CMD=(
1414
"cp -f test/image/index.html ../server_app/index.html &&"
1515
"supervisorctl restart nw1 && "
1616
"wget --server-response --spider --tries=10 --retry-connrefused http://localhost:9010/ping &&"
17-
"node test/image/compare_pixels_test.js $1"
17+
"node test/image/compare_pixels_test.js $@"
1818
)
1919

2020
docker exec -i $CONTAINER_NAME /bin/bash -c "${CMD[*]}"

tasks/util/get_image_request_options.js

-16
This file was deleted.

test/image/README.md

+73-9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ the above evaluates the output of `docker-machine env default`.
2626

2727
### Step 1: Run the testing container
2828

29-
Plotly.js uses `docker-compose` to ease the creation/stopping/deletion of the testing docker container.
29+
We use `docker-compose` to ease the creation/stopping/deletion of the testing docker container.
3030

3131
Inside your `plotly.js` directory, run
3232

@@ -40,25 +40,86 @@ as listed on [hub.docker.com](https://hub.docker.com/r/plotly/testbed/tags/) and
4040

4141
### Step 2: Run the image tests
4242

43-
Inside your `plotly.js` directory, run
43+
The image testing docker container allows plotly.js developers to ([A](#a-run-image-comparison-tests) run image
44+
comparison tests, ([B](#b-run-image-export-tests) run image export tests and ([C](#c-generate-or-update-existing-baseline-image)) generate baseline
45+
images.
46+
47+
**IMPORTANT:** the image tests scripts do **not** bundle the source files before
48+
running the image tests. We recommend running `npm run watch` or `npm start` in
49+
a separate tab to ensure that the most up-to-date code is used.
50+
51+
##### A: Run image comparison tests
52+
53+
Image comparison tests take in plotly.js mock json files (found in
54+
[`test/image/mocks`][mocks]), generate test png images (saved in
55+
`build/test_images/` - which is git-ignored) and compare them pixel-by-pixel to
56+
their corresponding baseline images (found in
57+
[`test/image/baselines`][baselines]) using
58+
[`GraphicsMagick`](https://github.com/aheckmann/gm).
59+
60+
To run the image comparison tests, in your `plotly.js` directory:
4461

4562
```bash
4663
npm run test-image
4764
```
4865

49-
if some tests fail, compare their outputs using `npm run start-image_viewer`.
66+
which runs all image comparison tests in batch. If some tests fail, compare their outputs
67+
by booting up the test image viewer using `npm run start-image_viewer`.
5068

51-
**IMPORTANT:** `npm run test-image` does **not** bundle the source files before running the image tests. We recommend runnnig `npm run watch` or `npm run start-test_dashboard` in a separate tab to ensure that the most up-to-date code is tested.
69+
As an alternative to running all image comparison tests at once, you can provide
70+
a [glob](https://github.com/isaacs/node-glob) as argument to target one or multiple test mocks found in
71+
[`test/image/mocks`][mocks].
72+
For example,
5273

53-
### Step 2b: Make a new or update an existing baseline image
74+
```bash
75+
# Run one test (e.g. the 'contour_nolines' test):
76+
$ npm run test-image -- contour_nolines
5477

55-
Inside your `plotly.js` directory, run
78+
# Run all gl3d image test in batch:
79+
$ npm run test-image -- gl3d_*
80+
```
81+
82+
Developers on weak hardware might encounter batch timeout issue. These are most
83+
common when generated WebGL-based graphs. In this case, running the image
84+
comparison tests in queue (i.e. with no concurrency) is recommended:
5685

5786
```bash
58-
npm run baseline -- mock.json
87+
# Run all gl3d image test in queue:
88+
$ npm run test-image -- gl3d_* --queue
89+
```
90+
91+
##### B: Run image export tests
92+
93+
Image export tests check that image export works for formats other than png.
94+
95+
To run the image export tests, in your `plotly.js` directory:
96+
97+
```bash
98+
npm run test-export
99+
100+
# or
101+
npm run test-export -- <glob>
102+
```
103+
104+
##### C: Generate or update existing baseline image
105+
106+
To generate a new baseline image, add a new mock file in
107+
[`test/image/mocks`][mocks]. Note that mock file needs to be a valid JSON and
108+
have both a "data" and a `"layout"` field. Then, in your plotly.js directory,
109+
run:
110+
111+
```bash
112+
npm run baseline -- <name-of-mock>
113+
```
114+
115+
which generates a baseline png image in [`test/image/baselines`][baselines].
116+
117+
To update existing baseline image(s), run
118+
119+
```bash
120+
npm run basline -- <glob-of-mocks-to-update>
59121
```
60122

61-
where `mock.json` is the name of a `{"data": [], "layout": {}}` json file found in [`test/image/mocks/`](https://github.com/plotly/plotly.js/tree/master/test/image/mocks). The `"data"` and `"layout"` field are passed to `Plotly.plot` to produce an image saved in [`test/image/baslines`](https://github.com/plotly/plotly.js/tree/master/test/image/baselines).
62123

63124
### Step 3: Stop your testing container
64125

@@ -74,7 +135,7 @@ Mac and Windows user should also kill their docker-machine (named `default`) onc
74135
docker-machine kill default
75136
```
76137

77-
### Docker tricks
138+
### Docker tricks
78139

79140
##### Get into docker container
80141

@@ -119,3 +180,6 @@ docker-machine kill default
119180
```
120181

121182
For more comprehensive information about docker, please refer to the [docker docs](http://docs.docker.com/).
183+
184+
[mocks]: https://github.com/plotly/plotly.js/tree/master/test/image/mocks
185+
[baselines]: https://github.com/plotly/plotly.js/tree/master/test/image/baselines

test/image/assets/get_image_paths.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var path = require('path');
2+
var constants = require('../../../tasks/util/constants');
3+
4+
var DEFAULT_FORMAT = 'png';
5+
6+
7+
/**
8+
* Return paths to baseline, test-image and diff images for a given mock name.
9+
*
10+
* @param {string} mockName
11+
* @param {string} format
12+
* @return {object}
13+
* baseline
14+
* test
15+
* diff
16+
*/
17+
module.exports = function getImagePaths(mockName, format) {
18+
format = format || DEFAULT_FORMAT;
19+
20+
return {
21+
baseline: join(constants.pathToTestImageBaselines, mockName, format),
22+
test: join(constants.pathToTestImages, mockName, format),
23+
diff: join(constants.pathToTestImagesDiff, mockName, format)
24+
};
25+
};
26+
27+
function join(basePath, mockName, format) {
28+
return path.join(basePath, mockName) + '.' + format;
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var path = require('path');
2+
var constants = require('../../../tasks/util/constants');
3+
4+
var DEFAULT_URL = 'http://localhost:9010/';
5+
var DEFAULT_FORMAT = 'png';
6+
var DEFAULT_SCALE = 1;
7+
8+
/**
9+
* Return the image server request options for a given mock (and specs)
10+
*
11+
* @param {object} specs
12+
* mockName : name of json mock to plot
13+
* format (optional): format of generated image
14+
* scale (optional): scale of generated image
15+
* url (optional): URL of image server
16+
*/
17+
module.exports = function getRequestOpts(specs) {
18+
var pathToMock = path.join(constants.pathToTestImageMocks, specs.mockName) + '.json';
19+
var figure = require(pathToMock);
20+
21+
var body = {
22+
figure: figure,
23+
format: specs.format || DEFAULT_FORMAT,
24+
scale: specs.scale || DEFAULT_SCALE
25+
};
26+
27+
return {
28+
method: 'POST',
29+
url: specs.url || DEFAULT_URL,
30+
body: JSON.stringify(body)
31+
};
32+
};

test/image/assets/get_mock_list.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var path = require('path');
2+
var glob = require('glob');
3+
4+
var constants = require('../../../tasks/util/constants');
5+
6+
7+
/**
8+
* Return array of mock name corresponding to input glob pattern
9+
*
10+
* @param {string} pattern
11+
* @return {array}
12+
*/
13+
module.exports = function getMocks(pattern) {
14+
// defaults to 'all'
15+
pattern = pattern || '*';
16+
17+
// defaults to '.json' ext is none is provided
18+
if(path.extname(pattern) === '') pattern += '.json';
19+
20+
var patternFull = constants.pathToTestImageMocks + '/' + pattern;
21+
var matches = glob.sync(patternFull);
22+
23+
// return only the mock name (not a full path, no ext)
24+
var mockNames = matches.map(function(match) {
25+
return path.basename(match).split('.')[0];
26+
});
27+
28+
return mockNames;
29+
};

0 commit comments

Comments
 (0)