Skip to content

Commit

Permalink
Tools: Added hook to allow tearing down non-atomic visual tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TorsteinHonsi committed Sep 11, 2019
1 parent 4823a1a commit fc12bf5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/karma-conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,14 @@ module.exports = function (config) {
function createVisualTestTemplate(argv, path, js, assertion) {
let scriptBody = resolveJSON(js);

let afterEach = 'undefined';
if (fs.existsSync(`samples/${path}/aftereach.js`)) {
afterEach = fs.readFileSync(`samples/${path}/aftereach.js`, 'utf8');
afterEach = `function () {
${afterEach}
}`;
}

// Don't do intervals (typically for gauge samples, add point etc)
scriptBody = scriptBody.replace('setInterval', 'Highcharts.noop');

Expand Down Expand Up @@ -719,6 +727,7 @@ function createVisualTestTemplate(argv, path, js, assertion) {
done();
`}
assert.test.resets = ${resets};
assert.test.sampleAfterEach = ${afterEach};
} else if (attempts < 50) {
setTimeout(waitForChartToLoad, 100);
attempts++;
Expand All @@ -729,6 +738,7 @@ function createVisualTestTemplate(argv, path, js, assertion) {
);
done();
assert.test.resets = ${resets};
assert.test.sampleAfterEach = ${afterEach};
}
}
waitForChartToLoad();
Expand Down
4 changes: 4 additions & 0 deletions test/karma-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ if (window.QUnit) {
}
Highcharts.wrap = origWrap;

if (typeof test.test.sampleAfterEach === 'function') {
test.test.sampleAfterEach();
}

// Reset defaultOptions and callbacks if those are mutated. In
// karma-konf, the scriptBody is inspected to see if these expensive
// operations are necessary. Visual tests only.
Expand Down
4 changes: 4 additions & 0 deletions test/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ limit the number of charts in the test suite.
- 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
- Highchars Utils: https://github.com/highcharts/highcharts-utils
Expand Down

0 comments on commit fc12bf5

Please sign in to comment.