Skip to content

Commit

Permalink
Merge pull request #737 from OpenGeoscience/headless-vs-headed-tests
Browse files Browse the repository at this point in the history
Better separate headless tests that require webgl and headed tests.
  • Loading branch information
manthey authored Sep 18, 2017
2 parents a6d5013 + 65c5618 commit b29d5d7
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 64 deletions.
16 changes: 8 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
17 changes: 9 additions & 8 deletions docs/developers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 `<http://localhost:9876/debug.html?test=all>`_.
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
`<http://localhost:9876/debug.html?test=all>`_. Since the browser's direct
screen output is used, the browser must be running on the same machine as the
``npm run start`` command.

2 changes: 1 addition & 1 deletion karma-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
4 changes: 2 additions & 2 deletions tests/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
36 changes: 0 additions & 36 deletions tests/gl-cases/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $('<div id="twomap"/>').css({width: '320px', height: '480px'});
$('#map').remove();
$('body').prepend(twomap);
twomap.append($('<div id="map1"/>').css({width: '100%', height: '50%'}));
twomap.append($('<div id="map2"/>').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);
});
});
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions tests/headed-cases/map.js
Original file line number Diff line number Diff line change
@@ -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 = $('<div id="twomap"/>').css({width: '320px', height: '480px'});
$('#map').remove();
$('body').prepend(twomap);
twomap.append($('<div id="map1"/>').css({width: '100%', height: '50%'}));
twomap.append($('<div id="map2"/>').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);
});
});
5 changes: 2 additions & 3 deletions tests/test-examples.js → tests/test-headed.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit b29d5d7

Please sign in to comment.