Skip to content

Commit 4a8563b

Browse files
committed
add webgl-support check in mapbox test suites
- to skip over test the require a gl context, if gl isn't supported - allows us to run _some_ mapbox tests on CircleCI
1 parent 9c72548 commit 4a8563b

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
4+
module.exports = function hasWebGLSupport(testName) {
5+
var gl, canvas;
6+
7+
try {
8+
canvas = document.createElement('canvas');
9+
gl = canvas.getContext('webgl');
10+
}
11+
catch(err) {
12+
gl = null;
13+
}
14+
15+
var hasSupport = !!gl;
16+
17+
if(!hasSupport) {
18+
console.warn('Cannot get WebGL context. Skip test *' + testName + '*');
19+
}
20+
21+
return hasSupport;
22+
};

test/jasmine/karma.ciconf.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ function func(config) {
1717
func.defaultConfig.exclude = [
1818
'tests/gl_plot_interact_test.js',
1919
'tests/gl_plot_interact_basic_test.js',
20-
'tests/gl2d_scatterplot_contour_test.js',
21-
'tests/mapbox_test.js',
22-
'tests/scattermapbox_test.js'
20+
'tests/gl2d_scatterplot_contour_test.js'
2321
];
2422

2523
// if true, Karma captures browsers, runs the tests and exits

test/jasmine/tests/mapbox_test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var supplyLayoutDefaults = require('@src/plots/mapbox/layout_defaults');
77
var d3 = require('d3');
88
var createGraphDiv = require('../assets/create_graph_div');
99
var destroyGraphDiv = require('../assets/destroy_graph_div');
10+
var hasWebGLSupport = require('../assets/has_webgl_support');
1011
var mouseEvent = require('../assets/mouse_event');
1112
var customMatchers = require('../assets/custom_matchers');
1213

@@ -121,6 +122,8 @@ describe('mapbox defaults', function() {
121122
describe('mapbox credentials', function() {
122123
'use strict';
123124

125+
if(!hasWebGLSupport('scattermapbox hover')) return;
126+
124127
var dummyToken = 'asfdsa124331wersdsa1321q3';
125128
var gd;
126129

@@ -168,6 +171,8 @@ describe('mapbox credentials', function() {
168171
describe('mapbox plots', function() {
169172
'use strict';
170173

174+
if(!hasWebGLSupport('scattermapbox hover')) return;
175+
171176
var mock = require('@mocks/mapbox_0.json'),
172177
gd;
173178

test/jasmine/tests/scattermapbox_test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var convert = require('@src/traces/scattermapbox/convert');
77

88
var createGraphDiv = require('../assets/create_graph_div');
99
var destroyGraphDiv = require('../assets/destroy_graph_div');
10+
var hasWebGLSupport = require('../assets/has_webgl_support');
1011
var customMatchers = require('../assets/custom_matchers');
1112

1213
// until it is part of the main plotly.js bundle
@@ -410,6 +411,8 @@ describe('scattermapbox convert', function() {
410411
describe('scattermapbox hover', function() {
411412
'use strict';
412413

414+
if(!hasWebGLSupport('scattermapbox hover')) return;
415+
413416
var hoverPoints = ScatterMapbox.hoverPoints;
414417

415418
var gd;
@@ -456,7 +459,7 @@ describe('scattermapbox hover', function() {
456459

457460
expect(out.index).toEqual(0);
458461
expect([out.x0, out.x1, out.y0, out.y1]).toBeCloseToArray([
459-
444.444, 446.444, 105.410, 107.410
462+
297.444, 299.444, 105.410, 107.410
460463
]);
461464
expect(out.extraText).toEqual('(10°, 10°)<br>A');
462465
expect(out.color).toEqual('#1f77b4');
@@ -470,7 +473,7 @@ describe('scattermapbox hover', function() {
470473

471474
expect(out.index).toEqual(0);
472475
expect([out.x0, out.x1, out.y0, out.y1]).toBeCloseToArray([
473-
2492.444, 2494.444, 105.410, 107.410
476+
2345.444, 2347.444, 105.410, 107.410
474477
]);
475478
expect(out.extraText).toEqual('(10°, 10°)<br>A');
476479
expect(out.color).toEqual('#1f77b4');
@@ -484,7 +487,7 @@ describe('scattermapbox hover', function() {
484487

485488
expect(out.index).toEqual(0);
486489
expect([out.x0, out.x1, out.y0, out.y1]).toBeCloseToArray([
487-
-2627.555, -2625.555, 105.410, 107.410
490+
-2774.555, -2772.555, 105.410, 107.410
488491
]);
489492
expect(out.extraText).toEqual('(10°, 10°)<br>A');
490493
expect(out.color).toEqual('#1f77b4');

0 commit comments

Comments
 (0)