Skip to content

Test IE9 by mocking window globals #1299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 13, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions test/jasmine/assets/ie9_mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
delete window.Promise;

delete window.ArrayBuffer;
delete window.Uint8Array;
delete window.Float32Array;
delete window.Float64Array;
delete window.Int16Array;
delete window.Int32Array;
40 changes: 40 additions & 0 deletions test/jasmine/bundle_tests/ie9_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var Plotly = require('@lib/core');

Plotly.register([
require('@lib/bar'),
require('@lib/box'),
require('@lib/heatmap'),
require('@lib/histogram'),
require('@lib/histogram2d'),
require('@lib/histogram2dcontour'),
require('@lib/pie'),
require('@lib/contour'),
require('@lib/scatterternary'),
require('@lib/ohlc'),
require('@lib/candlestick')
]);

var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');

describe('Bundle with IE9 supported trace types:', function() {

afterEach(destroyGraphDiv);

it('[wip] check that ie9_mock.js did its job', function() {
expect(window.ArrayBuffer).toBeUndefined();
expect(window.Uint8Array).toBeUndefined();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool - can we also do something like

expect(function() { return ArrayBuffer; }).toThrow('ReferenceError: ArrayBuffer is not defined');

to make sure it's really inaccessible in the way it actually gets invoked in the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 7cb691e

});

it('heatmaps with smoothing should work', function(done) {
var gd = createGraphDiv();
var data = [{
type: 'heatmap',
z: [[1, 2, 3], [2, 1, 2]],
zsmooth: 'best'
}];

Plotly.plot(gd, data).then(done);
});

});
10 changes: 10 additions & 0 deletions test/jasmine/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var arg = process.argv[4];
var testFileGlob = arg ? arg : 'tests/*_test.js';
var isSingleSuiteRun = (arg && arg.indexOf('bundle_tests/') === -1);
var isRequireJSTest = (arg && arg.indexOf('bundle_tests/requirejs') !== -1);
var isIE9Test = (arg && arg.indexOf('bundle_tests/ie9') !== -1);

var pathToMain = '../../lib/index.js';
var pathToJQuery = 'assets/jquery-1.8.3.min.js';
Expand Down Expand Up @@ -127,6 +128,15 @@ else if(isRequireJSTest) {
testFileGlob
];
}
else if(isIE9Test) {
func.defaultConfig.files = [
'./assets/ie9_mock.js',
// '../../dist/extras/typedarray.min.js',
testFileGlob
];

func.defaultConfig.preprocessors[testFileGlob] = ['browserify'];
}
else {
func.defaultConfig.files = [
pathToJQuery,
Expand Down
32 changes: 32 additions & 0 deletions test/jasmine/tests/ie9_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var Plotly = require('@lib');

var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');

describe('IE9 environment', function() {

var uint8Array = window.Uint8Array;

beforeAll(function() {
window.Uint8Array = undefined;
});

afterAll(function() {
window.Uint8Array = uint8Array;
});

afterEach(function() {
destroyGraphDiv();
});

it('heatmaps with smoothing should work', function(done) {
var gd = createGraphDiv();
var data = [{
type: 'heatmap',
z: [[1, 2, 3], [2, 1, 2]],
zsmooth: 'best'
}];

Plotly.plot(gd, data).then(done);
});
});