1 | ## Included in this directory
|
2 |
|
3 | - index.html - the web page used to run the test suite.
|
4 |
|
5 | - spec - includes the OpenLayers test/spec files.
|
6 |
|
7 | - test-extensions.js - includes OpenLayers-specific extensions to the
|
8 | testing frameworks.
|
9 |
|
10 |
|
11 | ## Run the test suite
|
12 |
|
13 | Install the test dependencies (from the root of the repository):
|
14 |
|
15 | npm install
|
16 |
|
17 | Run the tests once:
|
18 |
|
19 | npm test
|
20 |
|
21 | This will run tests in Chrome. If you do not have Chrome installed, you can run tests on Firefox instead:
|
22 |
|
23 | npm test -- --browsers Firefox
|
24 |
|
25 | To run tests in other browsers, you need to install [additional Karma launchers](http://karma-runner.github.io/1.0/config/browsers.html).
|
26 |
|
27 | To run the tests continuously:
|
28 |
|
29 | npm run karma
|
30 |
|
31 | After this, the test server is listening on http://localhost:9876/, and you can
|
32 | attach any number of browsers for testing (during development, tests will run
|
33 | in Chrome by default).
|
34 |
|
35 | # Rendering tests
|
36 |
|
37 | The `test/rendering` directory contains rendering tests which compare a rendered map with a
|
38 | reference image using [pixelmatch](https://github.com/mapbox/pixelmatch).
|
39 |
|
40 | To run the tests in the browser, make sure the development server is running
|
41 | (`make serve`) and open the URL
|
42 | [http://localhost:3000/test_rendering/index.html](http://localhost:3000/test_rendering/index.html).
|
43 |
|
44 | From the command-line the tests can be run with the build target `make test-rendering`.
|
45 |
|
46 | ## Adding new tests
|
47 | When creating a new test case, a reference image has to be created. By appending `?generate`
|
48 | to the URL, a canvas with the rendered map will be shown on the page when calling
|
49 | `expectResemble`. Then the reference image can simply be created with a right-click
|
50 | and "Save image as".
|
51 |
|
52 | It is recommended to only run a single test case when generating the reference image.
|
53 |
|
54 | ## Image difference
|
55 | When a test fails, an image showing the difference between the reference image and the
|
56 | rendered map can be displayed by appending `?showdiff` to the URL.
|