Skip to content

Files

Latest commit

7a1a36f · Jul 7, 2021

History

History
This branch is 19182 commits behind highcharts/highcharts:master.

test

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jul 5, 2021
Oct 22, 2017
Oct 28, 2017
Aug 27, 2019
Jun 23, 2021
May 7, 2020
Mar 16, 2021
Mar 17, 2019
Apr 29, 2019
May 28, 2018
Sep 18, 2019
Feb 4, 2021
Feb 11, 2021
Mar 26, 2020
Nov 18, 2020
Jul 7, 2021
Jan 23, 2019
Nov 10, 2017
Sep 11, 2019
Apr 28, 2020
Apr 28, 2020
Apr 28, 2020
Apr 15, 2019
Apr 29, 2019
Apr 15, 2019
Sep 5, 2019
Aug 23, 2019
Aug 23, 2019
Mar 22, 2018
Mar 22, 2018
Mar 16, 2018
Mar 26, 2019
Aug 23, 2019

Test Runner

Use gulp test to run the tests using karma and QUnit. All tests in the samples/unit-tests directory will run. For debugging, it may be convenient to use the visual Highcharts Utils.

Tests will run on pre-commit and will block committing in case of failure.

Features

  • Testing animation. Animation is by default disabled by Highcharts.setOptions. For testing animations, TestUtilities.lolex is available. It emulates animation in sync. Use the utility functions TestUtilities.lolexInstall before the test and TestUtilities.lolexRunAndUninstall after (find samples in the test suite).
  • Testing with templates. Test templates provide generic charts between several tests, that can be modified for particular test cases. Use TestTemplate.test inside a QUnit.test with templates found in the test/templates directory. TestTemplate handles most option modifications (except functions) and reverse them after each test case, which is faster than the classic destruction and creation of charts for each test.

Optimize for Speed

We want fast running tests. The time it takes to run the test suite is largely limited by the time it takes to create chart instances. Therefore, we want to limit the number of charts in the test suite.

  • When it feels correct, try reusing an existing chart instance to do your test. For example, when writing a test for a regression related to setExtremes, we would see in the axis tests if there is a chart where we can run the problem code and add an assertion. Of course we shouldn't overdo this - try to find the right balance between well organized code and speed.
  • Don't create a chart unless you have to. For example, tests for text wrapping only needs an SVGRenderer instance, colors can test directly against the Color object, data parsing directly against the Data object.

Troubleshooting

  • All the Highcharts files, including modules and indicators, are loaded in the test runner. A badly written module can cause errors downstream. If you can't pinpoint an error, try removing files from test/karma-files.json.
  • Similar to the above, all tests run in the same thread, so a badly written test may cause errors downstream. Try limiting the number of tests that run by modifying the glob in the files config in tests/karma-config.js.
  • Also keep in mind, that TestTemplate creates additional charts that are kept between tests. It is therefore advisable to limit DOM operations to your own Chart.container element.
  • Traditionally, the Highcharts unit tests have a demo.html file where the tests in demo.js run. In karma/QUnit, the demo.html file is not included. If the test depends on things like the width of the container or other DOM elements, this must be set up by JavaScript in demo.js. A fixed size chart is better defined with the chart.width option.
  • Don't use global variables. ESLint should raise an error on this on pre-commit. If several of the tests in the same demo.js share a function or variables, wrap it all in an IIFE.
  • All the tests run on one Highcharts instance. When running Highcharts.setOptions(), make sure to unset the changed options, otherwise it may break tests downstream.
  • In visual tests, plotOptions and callbacks are reset after each test. If other properties of Highcharts are mutated, a file aftereach.js can be added to reset them. Since the visual tests double as educational demos for the public, it is not recommended to have teardown code in demo.js.

Link References