From 1925e39b6984f1c9d3e3f22836ad25e3970cf7f9 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 2 Mar 2016 13:20:37 -0700 Subject: [PATCH] Allow tests to be ignored by feature --- test/spec/.eslintrc | 3 ++- test/spec/ol/source/rastersource.test.js | 2 +- test/test-extensions.js | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/test/spec/.eslintrc b/test/spec/.eslintrc index 509c93fc5c..38dceb5d93 100644 --- a/test/spec/.eslintrc +++ b/test/spec/.eslintrc @@ -6,6 +6,7 @@ "afterLoadText": false, "expect": false, "proj4": false, - "sinon": false + "sinon": false, + "where": false } } diff --git a/test/spec/ol/source/rastersource.test.js b/test/spec/ol/source/rastersource.test.js index 559f74813b..9e141c75e8 100644 --- a/test/spec/ol/source/rastersource.test.js +++ b/test/spec/ol/source/rastersource.test.js @@ -9,7 +9,7 @@ var green = 'data:image/gif;base64,R0lGODlhAQABAPAAAAD/AP///yH5BAAAAAAALAAAA' + var blue = 'data:image/gif;base64,R0lGODlhAQABAPAAAAAA/////yH5BAAAAAAALAAAAA' + 'ABAAEAAAICRAEAOw=='; -describe('ol.source.Raster', function() { +where('Uint8ClampedArray').describe('ol.source.Raster', function() { var target, map, redSource, greenSource, blueSource, raster; diff --git a/test/test-extensions.js b/test/test-extensions.js index f2aa98b0c3..0fe24c08a3 100644 --- a/test/test-extensions.js +++ b/test/test-extensions.js @@ -458,4 +458,25 @@ } }; + var features = { + Uint8ClampedArray: ('Uint8ClampedArray' in global) + }; + + /** + * Allow tests to be skipped where certain features are not available. The + * provided key must be in the above `features` lookup. Keys should + * correspond to the feature that is required, but can be any string. + * @param {string} key The required feature name. + * @return {Object} An object with a `describe` function that will run tests + * if the required feature is available and skip them otherwise. + */ + global.where = function(key) { + if (!(key in features)) { + throw new Error('where() called with unknown key: ' + key); + } + return { + describe: features[key] ? global.describe : global.xdescribe + }; + }; + })(this);