From 65c56189ec953f295332bee3d3acedc39791ad46 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Fri, 15 Sep 2017 14:07:30 -0400 Subject: [PATCH] Better separate headless tests that require webgl and headed tests. Move example-cases to headed-cases. Move the two-map test from gl-cases to the headed-cases directory. Change the glheadless test to use headless Chrome. The headless tests can be run without xvfb. --- CMakeLists.txt | 16 ++++----- docs/developers.rst | 17 ++++----- karma-base.js | 2 +- package.json | 12 +++---- tests/all.js | 4 +-- tests/gl-cases/map.js | 36 ------------------- .../blog-lines.js | 0 .../{example-cases => headed-cases}/lines.js | 0 tests/headed-cases/map.js | 35 ++++++++++++++++++ tests/{test-examples.js => test-headed.js} | 5 ++- 10 files changed, 63 insertions(+), 64 deletions(-) rename tests/{example-cases => headed-cases}/blog-lines.js (100%) rename tests/{example-cases => headed-cases}/lines.js (100%) create mode 100644 tests/headed-cases/map.js rename tests/{test-examples.js => test-headed.js} (61%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 31b995802c..a204b6895e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,14 +134,14 @@ if(WEBGLHEADLESS_TESTS) set_property(TEST "webglheadless" APPEND PROPERTY DEPENDS "build_examples") add_test( - NAME "examplesheadless" + NAME "headed" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - COMMAND "${NPM_EXECUTABLE}" run examplesci + COMMAND "${NPM_EXECUTABLE}" run headedci ) - set_property(TEST "examplesheadless" APPEND PROPERTY ENVIRONMENT "CTEST_IMAGE_PATH=${CMAKE_CURRENT_BINARY_DIR}/images") - set_property(TEST "examplesheadless" APPEND PROPERTY ENVIRONMENT "TEST_SAVE_IMAGE=${TEST_SAVE_IMAGE}") - set_property(TEST "total-coverage" APPEND PROPERTY DEPENDS "examplesheadless") - set_property(TEST "examplesheadless" APPEND PROPERTY DEPENDS "build_examples") + set_property(TEST "headed" APPEND PROPERTY ENVIRONMENT "CTEST_IMAGE_PATH=${CMAKE_CURRENT_BINARY_DIR}/images") + set_property(TEST "headed" APPEND PROPERTY ENVIRONMENT "TEST_SAVE_IMAGE=${TEST_SAVE_IMAGE}") + set_property(TEST "total-coverage" APPEND PROPERTY DEPENDS "headed") + set_property(TEST "headed" APPEND PROPERTY DEPENDS "build_examples") configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/testing/test-runners/baseline_images.py" @@ -158,8 +158,8 @@ add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/base-images.tgz" COMMAND TEST_SAVE_IMAGE=all "${NPM_EXECUTABLE}" run glci # Build examples to make sure that they are available. COMMAND "${NPM_EXECUTABLE}" run build-examples - # Run the examplesheadless test, asking to save all images - COMMAND TEST_SAVE_IMAGE=all "${NPM_EXECUTABLE}" run examplesci + # Run the headed test, asking to save all images + COMMAND TEST_SAVE_IMAGE=all "${NPM_EXECUTABLE}" run headedci # If optipng is available, reduce the size of the images # COMMAND bash -c "optipng '${CMAKE_CURRENT_BINARY_DIR}'/images/*.png || true" COMMAND bash -c "find '${CMAKE_CURRENT_BINARY_DIR}'/images -name '*.png' -a -not -name '*-test.png' -a -not -name '*-diff.png' -a -not -name '*-base.png' -a -not -name '*-screen.png' -print0 | xargs -0 -n 1 -P 8 optipng || true" diff --git a/docs/developers.rst b/docs/developers.rst index d362960e41..6bd3a3460d 100644 --- a/docs/developers.rst +++ b/docs/developers.rst @@ -81,9 +81,9 @@ will run the headless WebGL tests. After the data for tests is downloaded, the tests can also be run via ``npm run test-webgl``, which assumes that ``xvfb-run`` is available. -The headless unit tests that require WebGL or should run in a standard browser -should be placed in the ``tests/gl-cases/`` directory. When tests are run in a -normal browser via ``npm run start``, the webgl tests are included. +The headless unit tests that require WebGL should be placed in the +``tests/gl-cases/`` directory. When tests are run in a normal browser via +``npm run start``, the webgl tests are included. Many of these tests compare against a baseline image. If a test is changed or added, new baselines can be generated and optionally uploaded via the script @@ -109,9 +109,10 @@ test command or set this parameter in CMake. build correctly. Try running ``ccmake /path/to/geojs`` for a full list of configuration options. -Examples should be tested by creating an entry in the ``tests/example-cases/`` -directory. To run these tests in a normal browser, run -``npm run start`` and browse to ``_. -Since the browser's direct screen output is used, the browser must be running -on the same machine as the ``npm run start`` command. +Examples and tests that need to run in a standard browser should be tested by +creating an entry in the ``tests/headed-cases/`` directory. To run these tests +in a normal browser, run ``npm run start`` and browse to +``_. Since the browser's direct +screen output is used, the browser must be running on the same machine as the +``npm run start`` command. diff --git a/karma-base.js b/karma-base.js index 69eb00b48c..680d23152d 100644 --- a/karma-base.js +++ b/karma-base.js @@ -212,7 +212,7 @@ module.exports = function (config) { {pattern: 'tests/data/**/*', included: false}, {pattern: 'tests/cases/**/*.js', included: false, served: false, watched: true}, {pattern: 'tests/gl-cases/**/*.js', included: false, served: false, watched: true}, - {pattern: 'tests/example-cases/**/*.js', included: false, served: false, watched: true}, + {pattern: 'tests/headed-cases/**/*.js', included: false, served: false, watched: true}, {pattern: 'dist/data/**/*', included: false}, {pattern: 'dist/examples/**/*', included: false}, {pattern: 'dist/tutorials/**/*', included: false}, diff --git a/package.json b/package.json index 5597531936..1efb27df86 100644 --- a/package.json +++ b/package.json @@ -93,14 +93,14 @@ "test": "GEOJS_TEST_CASE=tests/test-unit.js karma start karma-cov.conf.js --single-run --browsers ChromeHeadlessTouch,FirefoxTouch,PhantomJS", "test-all": "GEOJS_TEST_CASE=tests/test-unit.js karma start karma-cov.conf.js --single-run --browsers ChromeHeadlessTouch,FirefoxTouch,PhantomJS", "start": "karma start karma.conf.js", - "glci": "GEOJS_TEST_CASE=tests/test-gl.js karma start karma-cov.conf.js --single-run --browsers ChromeFull", - "glci-all": "GEOJS_TEST_CASE=tests/test-gl.js karma start karma-cov.conf.js --single-run --browsers ChromeFull,FirefoxTouch", - "examplesci": "GEOJS_TEST_CASE=tests/test-examples.js karma start karma-cov.conf.js --single-run --browsers ChromeWithProxy", - "examplesci-all": "GEOJS_TEST_CASE=tests/test-examples.js karma start karma-cov.conf.js --single-run --browsers ChromeWithProxy,FirefoxWithProxy", + "glci": "GEOJS_TEST_CASE=tests/test-gl.js karma start karma-cov.conf.js --single-run --browsers ChromeHeadlessTouch", + "glci-all": "GEOJS_TEST_CASE=tests/test-gl.js karma start karma-cov.conf.js --single-run --browsers ChromeHeadlessTouch,FirefoxTouch", + "headedci": "GEOJS_TEST_CASE=tests/test-headed.js karma start karma-cov.conf.js --single-run --browsers ChromeWithProxy", + "headedci-all": "GEOJS_TEST_CASE=tests/test-headed.js karma start karma-cov.conf.js --single-run --browsers ChromeWithProxy,FirefoxWithProxy", "tutorialsci": "GEOJS_TEST_CASE=tests/tutorials.js karma start karma-cov.conf.js --single-run --browsers ChromeHeadlessTouch,PhantomJS", "tutorialsci-all": "GEOJS_TEST_CASE=tests/tutorials.js karma start karma-cov.conf.js --single-run --browsers ChromeHeadlessTouch,FirefoxTouch,PhantomJS", - "test-webgl": "GEOJS_TEST_CASE=tests/test-gl.js xvfb-run -s '-ac -screen 0 1280x1024x24' karma start karma-cov.conf.js --single-run --browsers ChromeFull", - "test-examples": "GEOJS_TEST_CASE=tests/test-examples.js xvfb-run -s '-ac -screen 0 1280x1024x24' karma start karma-cov.conf.js --single-run --browsers ChromeWithProxy", + "test-webgl": "GEOJS_TEST_CASE=tests/test-gl.js karma start karma-cov.conf.js --single-run --browsers ChromeHeadlessTouch", + "test-headed": "GEOJS_TEST_CASE=tests/test-headed.js xvfb-run -s '-ac -screen 0 1280x1024x24' karma start karma-cov.conf.js --single-run --browsers ChromeWithProxy", "codecov": "codecov", "combine-coverage": "istanbul-combine -d dist/cobertura -r cobertura 'dist/coverage/json/**/coverage-final.json'", "examples": "webpack-dev-server --config webpack-examples.config.js --host ${HOST-127.0.0.1} --port ${PORT-8082} --content-base dist/", diff --git a/tests/all.js b/tests/all.js index 5738f1a0fa..29d967081b 100644 --- a/tests/all.js +++ b/tests/all.js @@ -16,7 +16,7 @@ if (query.test === 'all' || query.test === 'gl' || query.test === undefined) { tests = require.context('./gl-cases', true, /.*\.js$/); tests.keys().forEach(tests); } -if (query.test === 'all' || query.test === 'examples') { - tests = require.context('./example-cases', true, /.*\.js$/); +if (query.test === 'all' || query.test === 'headed') { + tests = require.context('./headed-cases', true, /.*\.js$/); tests.keys().forEach(tests); } diff --git a/tests/gl-cases/map.js b/tests/gl-cases/map.js index 70218782a9..1c6af80dc7 100644 --- a/tests/gl-cases/map.js +++ b/tests/gl-cases/map.js @@ -43,39 +43,3 @@ describe('map', function () { imageTest.imageTest('mapZoom', null, 0.0015, done, myMap.onIdle, 0, 2); }); }); - -describe('two maps', function () { - var imageTest = require('../image-test'); - var common = require('../test-common'); - var $ = require('jquery'); - - var map1, map2; - - beforeEach(function () { - var twomap = $('
').css({width: '320px', height: '480px'}); - $('#map').remove(); - $('body').prepend(twomap); - twomap.append($('
').css({width: '100%', height: '50%'})); - twomap.append($('
').css({width: '100%', height: '50%'})); - }); - afterEach(function () { - map1.exit(); - map2.exit(); - $('#twomap').remove(); - }); - - it('two maps', function (done) { - map1 = common.createOsmMap({node: '#map1', center: {x: -70, y: 40}, zoom: 3}); - map2 = common.createOsmMap({node: '#map2', center: {x: 70, y: 40}, zoom: 3}); - map1.draw(); - map2.draw(); - - var idle = function (callback) { - map1.onIdle(function () { - map2.onIdle(callback); - }); - }; - - imageTest.imageTest('mapTwo', '#twomap', 0.0015, done, idle, 0, 2); - }); -}); diff --git a/tests/example-cases/blog-lines.js b/tests/headed-cases/blog-lines.js similarity index 100% rename from tests/example-cases/blog-lines.js rename to tests/headed-cases/blog-lines.js diff --git a/tests/example-cases/lines.js b/tests/headed-cases/lines.js similarity index 100% rename from tests/example-cases/lines.js rename to tests/headed-cases/lines.js diff --git a/tests/headed-cases/map.js b/tests/headed-cases/map.js new file mode 100644 index 0000000000..9d3358b589 --- /dev/null +++ b/tests/headed-cases/map.js @@ -0,0 +1,35 @@ +describe('two maps', function () { + var imageTest = require('../image-test'); + var common = require('../test-common'); + var $ = require('jquery'); + + var map1, map2; + + beforeEach(function () { + var twomap = $('
').css({width: '320px', height: '480px'}); + $('#map').remove(); + $('body').prepend(twomap); + twomap.append($('
').css({width: '100%', height: '50%'})); + twomap.append($('
').css({width: '100%', height: '50%'})); + }); + afterEach(function () { + map1.exit(); + map2.exit(); + $('#twomap').remove(); + }); + + it('two maps', function (done) { + map1 = common.createOsmMap({node: '#map1', center: {x: -70, y: 40}, zoom: 3}); + map2 = common.createOsmMap({node: '#map2', center: {x: 70, y: 40}, zoom: 3}); + map1.draw(); + map2.draw(); + + var idle = function (callback) { + map1.onIdle(function () { + map2.onIdle(callback); + }); + }; + + imageTest.imageTest('mapTwo', '#twomap', 0.0015, done, idle, 0, 2); + }); +}); diff --git a/tests/test-examples.js b/tests/test-headed.js similarity index 61% rename from tests/test-examples.js rename to tests/test-headed.js index c175518a0b..f2fdc476e5 100644 --- a/tests/test-examples.js +++ b/tests/test-headed.js @@ -1,9 +1,8 @@ /** - * Entry point for all tests in ./example-cases/* + * Entry point for all tests in ./headed-cases/* * This is here to prevent webpack from creating a seperate bundle for each * test case. See: https://github.com/webpack/karma-webpack/issues/23 */ -var tests = require.context('./example-cases', true, /.*\.js$/); +var tests = require.context('./headed-cases', true, /.*\.js$/); tests.keys().forEach(tests); -