Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c71973b

Browse filesBrowse files
committed
Merge pull request #266 from plotly/improve-gl-test
Make gl plot interaction test more robust
2 parents 0c3b14b + b33607a commit c71973b
Copy full SHA for c71973b

File tree

Expand file treeCollapse file tree

2 files changed

+34
-5
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+34
-5
lines changed
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = {
2+
3+
// toBeCloseTo... but for arrays
4+
toBeCloseToArray: function(){
5+
return {
6+
compare: function(actual, expected, precision) {
7+
if(precision !== 0){
8+
precision = Math.pow(10, -precision) / 2 || 0.005;
9+
}
10+
11+
var tested = actual.map(function(element, i) {
12+
return Math.abs(expected[i] - element) < precision;
13+
});
14+
15+
var passed = tested.indexOf(false) < 0;
16+
17+
return {
18+
pass: passed,
19+
message: 'Expected ' + actual + ' to be close to ' + expected + '.'
20+
};
21+
}
22+
};
23+
}
24+
};

‎test/jasmine/tests/gl_plot_interact_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/gl_plot_interact_test.js
+10-5Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var Lib = require('@src/lib');
77
var createGraphDiv = require('../assets/create_graph_div');
88
var destroyGraphDiv = require('../assets/destroy_graph_div');
99
var selectButton = require('../assets/modebar_button');
10+
var customMatchers = require('../assets/custom_matchers');
1011

1112
/*
1213
* WebGL interaction test cases fail on the CircleCI
@@ -18,6 +19,10 @@ var selectButton = require('../assets/modebar_button');
1819
describe('Test plot structure', function() {
1920
'use strict';
2021

22+
beforeEach(function() {
23+
jasmine.addMatchers(customMatchers);
24+
});
25+
2126
afterEach(destroyGraphDiv);
2227

2328
describe('gl3d plots', function() {
@@ -148,7 +153,7 @@ describe('Test plot structure', function() {
148153

149154
describe('buttons resetCameraDefault3d and resetCameraLastSave3d', function() {
150155
// changes in scene objects are not instantaneous
151-
var DELAY = 1000;
156+
var DELAY = 200;
152157

153158
it('should update the scene camera', function(done) {
154159
var sceneLayout = gd._fullLayout.scene,
@@ -166,22 +171,22 @@ describe('Test plot structure', function() {
166171
expect(sceneLayout.camera.eye)
167172
.toEqual({x: 0.1, y: 0.1, z: 1}, 'does not change the layout objects');
168173
expect(scene.camera.eye)
169-
.toEqual([1.2500000000000002, 1.25, 1.25]);
174+
.toBeCloseToArray([1.25, 1.25, 1.25], 4);
170175
expect(sceneLayout2.camera.eye)
171176
.toEqual({x: 2.5, y: 2.5, z: 2.5}, 'does not change the layout objects');
172177
expect(scene2.camera.eye)
173-
.toEqual([1.2500000000000002, 1.25, 1.25]);
178+
.toBeCloseToArray([1.25, 1.25, 1.25], 4);
174179

175180
selectButton(modeBar, 'resetCameraLastSave3d').click();
176181
setTimeout(function() {
177182
expect(sceneLayout.camera.eye)
178183
.toEqual({x: 0.1, y: 0.1, z: 1}, 'does not change the layout objects');
179184
expect(scene.camera.eye)
180-
.toEqual([ 0.10000000000000016, 0.10000000000000016, 1]);
185+
.toBeCloseToArray([ 0.1, 0.1, 1], 4);
181186
expect(sceneLayout2.camera.eye)
182187
.toEqual({x: 2.5, y: 2.5, z: 2.5}, 'does not change the layout objects');
183188
expect(scene2.camera.eye)
184-
.toEqual([2.500000000000001, 2.5000000000000004, 2.5000000000000004]);
189+
.toBeCloseToArray([2.5, 2.5, 2.5], 4);
185190

186191
done();
187192
}, DELAY);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.