Skip to content

Commit b6df8ab

Browse files
committed
Merge pull request #61 from plotly/karma-plot-tests
karma/jamsine plot interaction tests
2 parents 10dff2c + 7deeec7 commit b6df8ab

File tree

10 files changed

+249
-55
lines changed

10 files changed

+249
-55
lines changed

circle.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
general:
22
artifacts:
3-
- "build/test_images/" # relative to the build directory
4-
- "build/test_images_diff/" # relative to the build directory
3+
- "build/test_images/"
4+
- "build/test_images_diff/"
55

66
machine:
77
node:
8-
version: 4.2.1
8+
version: 4.2.1
99
services:
1010
- docker
11-
11+
1212

1313
dependencies:
14-
pre:
14+
pre:
1515
- docker pull plotly/imageserver:latest
1616
post:
1717
- npm run cibuild

tasks/baseline.sh

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,12 @@
22
#
33
# TODO adapt this for Windows
44
#
5-
# TODO add package.json config arguments to configure:
6-
# - container name,
7-
# - ports and
8-
# - imageserver version
9-
#
105
# ===============================================================================
116

12-
CONTAINER_NAME="imagetest"
13-
IMAGE_NAME="registry.plot.ly:5000/imageserver"
14-
IMAGE_VERSION="1.3.0"
7+
CONTAINER_NAME="imagetest" # same as in docker-compose.yml
158

16-
# Run docker container:
17-
#
18-
# docker run -d --name $CONTAINER_NAME \
19-
# -v $PWD/plotly.js:/var/www/streambed/image_server/plotly.js \
20-
# -p 9010:9010 -p 2022:22 \
21-
# $IMAGE_NAME:[$IMAGE_VERSION]
9+
# create/run/start docker container with:
10+
# $ docker-compose up -d
2211

2312
CMD=(
2413
"cd /var/www/streambed/image_server/plotly.js &&"

tasks/test_image.sh

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,12 @@
22
#
33
# TODO adapt this for Windows
44
#
5-
# TODO add package.json config arguments to configure:
6-
# - container name,
7-
# - ports and
8-
# - imageserver version
9-
#
105
# ===============================================================================
116

12-
CONTAINER_NAME="imagetest"
13-
IMAGE_NAME="registry.plot.ly:5000/imageserver"
14-
IMAGE_VERSION="1.3.0"
7+
CONTAINER_NAME="imagetest" # same as in docker-compose.yml
158

16-
# Run docker container:
17-
#
18-
# docker run -d --name $CONTAINER_NAME \
19-
# -v $PWD/plotly.js:/var/www/streambed/image_server/plotly.js \
20-
# -p 9010:9010 -p 2022:22 \
21-
# $IMAGE_NAME:[$IMAGE_VERSION]
9+
# create/run/start docker container with:
10+
# $ docker-compose up -d
2211

2312
CMD=(
2413
"cd /var/www/streambed/image_server/plotly.js &&"

test/image/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ docker images
7171
docker ps -a
7272
```
7373

74+
whereas `docker ps` lists only the started containers.
75+
76+
7477
### Stop your testing container
7578

7679
Inside your `plotly.js` directory, run
@@ -87,4 +90,4 @@ Inside your `plotly.js` directory, run
8790
docker-compose rm -f
8891
```
8992

90-
For more comprehensive information about docker, please refer to [docker document](http://docs.docker.com/)
93+
For more comprehensive information about docker, please refer to the [docker docs](http://docs.docker.com/).

test/image/compare_pixels_test.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,21 @@ else runSingle(userFileName);
2626
function runAll () {
2727
test('testing mocks', function (t) {
2828

29-
console.error('### beginning pixel comparison tests ###');
3029
var files = fs.readdirSync(constants.pathToTestImageMocks);
3130

32-
// -1 for font-wishlist and
33-
// -38 for the gl2d mocks
34-
t.plan(files.length - 39);
31+
/*
32+
* Some test cases exhibit run-to-run randomness;
33+
* skip over these few test cases for now.
34+
*
35+
* More info:
36+
* https://github.com/plotly/plotly.js/issues/62
37+
*
38+
* 40 test cases are removed:
39+
* - font-wishlist (1 test case)
40+
* - all gl2d (38)
41+
* - gl2d_bunny-hull (1)
42+
*/
43+
t.plan(files.length - 40);
3544

3645
for (var i = 0; i < files.length; i ++) {
3746
testMock(files[i], t);
@@ -54,6 +63,9 @@ function testMock (fileName, t) {
5463
// TODO fix race condition in gl2d image generation
5564
if(fileName.indexOf('gl2d_') !== -1) return;
5665

66+
// TODO fix run-to-run randomness
67+
if(fileName === 'gl3d_bunny-hull.json') return;
68+
5769
var figure = require(path.join(constants.pathToTestImageMocks, fileName));
5870
var bodyMock = {
5971
figure: figure,
@@ -66,7 +78,6 @@ function testMock (fileName, t) {
6678
var diffPath = path.join(constants.pathToTestImagesDiff, 'diff-' + imageFileName);
6779
var savedImageStream = fs.createWriteStream(savedImagePath);
6880
var options = getOptions(bodyMock, 'http://localhost:9010/');
69-
var statusCode;
7081

7182
function checkImage () {
7283
var options = {
@@ -75,17 +86,12 @@ function testMock (fileName, t) {
7586
tolerance: 0.0
7687
};
7788

78-
if(statusCode === 485) {
79-
console.error(imageFileName, '- skip');
80-
}
81-
else {
82-
gm.compare(
83-
savedImagePath,
84-
path.join(constants.pathToTestImageBaselines, imageFileName),
85-
options,
86-
onEqualityCheck
87-
);
88-
}
89+
gm.compare(
90+
savedImagePath,
91+
path.join(constants.pathToTestImageBaselines, imageFileName),
92+
options,
93+
onEqualityCheck
94+
);
8995
}
9096

9197
function onEqualityCheck (err, isEqual) {
@@ -95,16 +101,12 @@ function testMock (fileName, t) {
95101
}
96102
if (isEqual) {
97103
fs.unlinkSync(diffPath);
98-
console.error(imageFileName + ' is pixel perfect');
99104
}
100105

101-
t.ok(isEqual, savedImagePath + ' should be pixel perfect');
106+
t.ok(isEqual, imageFileName + ' should be pixel perfect');
102107
}
103108

104109
request(options)
105-
.on('response', function(response) {
106-
statusCode = response.statusCode;
107-
})
108110
.pipe(savedImageStream)
109111
.on('close', checkImage);
110112
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
module.exports = function createGraphDiv() {
4+
var gd = document.createElement('div');
5+
gd.id = 'graph';
6+
document.body.appendChild(gd);
7+
return gd;
8+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
3+
module.exports = function destroyGraphDiv() {
4+
var gd = document.getElementById('graph');
5+
document.body.removeChild(gd);
6+
};

test/jasmine/karma.ciconf.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ function func(config) {
77
func.defaultConfig.logLevel = config.LOG_INFO;
88

99
// Continuous Integration mode
10+
11+
/*
12+
* WebGL interaction test cases fail on the CircleCI
13+
* most likely due to a WebGL/driver issue;
14+
* exclude them from the CircleCI test bundle.
15+
*
16+
*/
17+
func.defaultConfig.exclude = ['tests/gl_plot_interact_test.js'];
18+
1019
// if true, Karma captures browsers, runs the tests and exits
1120
func.defaultConfig.singleRun = true;
1221

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
var d3 = require('d3');
2+
3+
var Plotly = require('@src/index');
4+
5+
var createGraphDiv = require('../assets/create_graph_div');
6+
var destroyGraphDiv = require('../assets/destroy_graph_div');
7+
8+
/*
9+
* WebGL interaction test cases fail on the CircleCI
10+
* most likely due to a WebGL/driver issue
11+
*
12+
*/
13+
14+
15+
describe('Test plot structure', function () {
16+
'use strict';
17+
18+
afterEach(destroyGraphDiv);
19+
20+
describe('gl3d plots', function() {
21+
var mock = require('@mocks/gl3d_marker-arrays.json');
22+
23+
beforeEach(function(done) {
24+
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
25+
});
26+
27+
it('has one *canvas* node', function() {
28+
var nodes = d3.selectAll('canvas');
29+
expect(nodes[0].length).toEqual(1);
30+
});
31+
});
32+
33+
describe('gl2d plots', function() {
34+
var mock = require('@mocks/gl2d_10.json');
35+
36+
beforeEach(function(done) {
37+
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
38+
});
39+
40+
it('has one *canvas* node', function() {
41+
var nodes = d3.selectAll('canvas');
42+
expect(nodes[0].length).toEqual(1);
43+
});
44+
});
45+
46+
});

0 commit comments

Comments
 (0)