From a0f16521ebd02443037bf5d85d0adb2137238f57 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Tue, 27 Apr 2021 15:58:04 -0700 Subject: [PATCH] Remove unused rendering assertion from browser tests --- test/browser/.eslintrc | 4 -- test/browser/karma.config.js | 11 ----- test/browser/module-global.js | 1 - test/browser/test-extensions.js | 82 --------------------------------- 4 files changed, 98 deletions(-) delete mode 100644 test/browser/module-global.js diff --git a/test/browser/.eslintrc b/test/browser/.eslintrc index 0fcec37650..1f710e59d5 100644 --- a/test/browser/.eslintrc +++ b/test/browser/.eslintrc @@ -3,15 +3,11 @@ "mocha": true }, "globals": { - "IMAGE_TOLERANCE": false, "afterLoadText": false, "createMapDiv": true, "disposeMap": true, "expect": false, - "expectResemble": false, "proj4": false, - "pixelmatch": false, - "resembleCanvas": false, "sinon": false, "where": false } diff --git a/test/browser/karma.config.js b/test/browser/karma.config.js index 2bdb8cf334..2e84ea69cc 100644 --- a/test/browser/karma.config.js +++ b/test/browser/karma.config.js @@ -19,10 +19,6 @@ module.exports = function (karma) { ), watched: false, }, - { - pattern: 'module-global.js', - watched: false, - }, { pattern: path.resolve( __dirname, @@ -45,13 +41,6 @@ module.exports = function (karma) { ), watched: false, }, - { - pattern: path.resolve( - __dirname, - require.resolve('pixelmatch/index.js') - ), - watched: false, - }, { pattern: path.resolve(__dirname, './test-extensions.js'), }, diff --git a/test/browser/module-global.js b/test/browser/module-global.js deleted file mode 100644 index 278a7771e0..0000000000 --- a/test/browser/module-global.js +++ /dev/null @@ -1 +0,0 @@ -window.module = {}; diff --git a/test/browser/test-extensions.js b/test/browser/test-extensions.js index 3d0d615dbb..e530ee3e9f 100644 --- a/test/browser/test-extensions.js +++ b/test/browser/test-extensions.js @@ -2,17 +2,6 @@ // since these extensions are global, instanceof checks fail with modules (function (global) { - // show generated maps for rendering tests - const showMap = global.location.search.indexOf('generate') >= 0; - - // show a diff when rendering tests fail - const showDiff = global.location.search.indexOf('showdiff') >= 0; - - /** - * The default tolerance for image comparisons. - */ - global.IMAGE_TOLERANCE = 1.5; - function afterLoad(type, path, next) { const client = new XMLHttpRequest(); client.open('GET', path, true); @@ -401,77 +390,6 @@ map.dispose(); }; - function resembleCanvas(canvas, referenceImage, tolerance, done) { - if (showMap) { - const wrapper = document.createElement('div'); - wrapper.style.width = canvas.width + 'px'; - wrapper.style.height = canvas.height + 'px'; - wrapper.appendChild(canvas); - document.body.appendChild(wrapper); - document.body.appendChild(document.createTextNode(referenceImage)); - } - const width = canvas.width; - const height = canvas.height; - const image = new Image(); - image.addEventListener('load', function () { - expect(image.width).to.be(width); - expect(image.height).to.be(height); - const referenceCanvas = document.createElement('canvas'); - referenceCanvas.width = image.width; - referenceCanvas.height = image.height; - const referenceContext = referenceCanvas.getContext('2d'); - referenceContext.drawImage(image, 0, 0, image.width, image.height); - const context = canvas.getContext('2d'); - const output = context.createImageData(canvas.width, canvas.height); - const mismatchPx = pixelmatch( - context.getImageData(0, 0, width, height).data, - referenceContext.getImageData(0, 0, width, height).data, - output.data, - width, - height - ); - const mismatchPct = (mismatchPx / (width * height)) * 100; - if (showDiff && mismatchPct > tolerance) { - const diffCanvas = document.createElement('canvas'); - diffCanvas.width = width; - diffCanvas.height = height; - diffCanvas.getContext('2d').putImageData(output, 0, 0); - document.body.appendChild(diffCanvas); - } - expect(mismatchPct).to.be.below(tolerance); - done(); - }); - image.addEventListener('error', function () { - expect().fail('Reference image could not be loaded'); - done(); - }); - image.src = referenceImage; - } - global.resembleCanvas = resembleCanvas; - - /** - * Assert that the given map resembles a reference image. - * - * @param {ol.PluggableMap} map A map using the canvas renderer. - * @param {string} referenceImage Path to the reference image. - * @param {number} tolerance The accepted mismatch tolerance. - * @param {Function} done A callback to indicate that the test is done. - */ - global.expectResemble = function (map, referenceImage, tolerance, done) { - map.render(); - map.on('postcompose', function (event) { - if (event.frameState.animate) { - // make sure the tile-queue is empty - return; - } - - const canvas = event.context.canvas; - expect(canvas).to.be.a(HTMLCanvasElement); - - resembleCanvas(canvas, referenceImage, tolerance, done); - }); - }; - const features = { ArrayBuffer: 'ArrayBuffer' in global, 'ArrayBuffer.isView': 'ArrayBuffer' in global && !!ArrayBuffer.isView,