Skip to content

Commit

Permalink
Tools: Added mocking of time for gant demos.
Browse files Browse the repository at this point in the history
This is needed when running visual comparison tests. I.e if the reference image was created x days ago it wouldn't otherwise match.
  • Loading branch information
Jan Martin Langeland authored and TorsteinHonsi committed Aug 23, 2019
1 parent 9678511 commit f982840
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ workflows:
filters:
branches:
only:
- tools/vis-test-samples
- tools/visual-test-samples
- master
jobs:
- checkout_code
Expand Down
7 changes: 7 additions & 0 deletions test/karma-conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,11 +712,16 @@ function createVisualTestTemplate(argv, path, js, assertion) {
`;
}

var useFakeTime = path.startsWith('gantt/');
var startOfMockedTime = Date.UTC(2019, 7, 1);

return `
QUnit.test('${path}', function (assert) {
// Apply demo.html
document.getElementById('demo-html').innerHTML = \`${html}\`;
${useFakeTime ? `var clock = TestUtilities.lolexInstall({ now: ${startOfMockedTime} });` : ''}
/*
* we expect 2 callbacks if --visualcompare argument is supplied,
* one for the test comparison and one for checking if chart exists.
Expand Down Expand Up @@ -748,6 +753,8 @@ function createVisualTestTemplate(argv, path, js, assertion) {
}
}
assertIfChartExists();
${useFakeTime ? 'TestUtilities.lolexUninstall(clock);' : ''}
});
`;
}
7 changes: 5 additions & 2 deletions test/test-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ var TestUtilities = /** @class */ (function () {
/**
* Convenient wrapper for installing lolex and bypassing
* requestAnimationFrame. Returns a clock object.
*
* @param lolexConfig
* Config supplied to lolex.install
*/
TestUtilities.lolexInstall = function () {
TestUtilities.lolexInstall = function (lolexConfig) {
if (!lolex) {
return;
}
Expand All @@ -48,7 +51,7 @@ var TestUtilities = /** @class */ (function () {
win.requestAnimationFrame = null;
// Abort running animations, otherwise they will take over
Highcharts.timers.length = 0;
return lolex.install();
return lolex.install(lolexConfig);
};
/**
* Convenient wrapper for uninstalling lolex.
Expand Down
8 changes: 5 additions & 3 deletions test/test-utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ class TestUtilities {
/**
* Convenient wrapper for installing lolex and bypassing
* requestAnimationFrame. Returns a clock object.
*
* @param lolexConfig
* Config supplied to lolex.install
*/
private static lolexInstall (): (LolexClock|undefined) {

private static lolexInstall (lolexConfig?: any): (LolexClock|undefined) {
if (!lolex) {
return;
}
Expand All @@ -113,7 +115,7 @@ class TestUtilities {
// Abort running animations, otherwise they will take over
(Highcharts as any).timers.length = 0;

return lolex.install();
return lolex.install(lolexConfig);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/tsglobal.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference path="../code/highcharts.d.ts" />

declare interface Lolex {
install: () => (LolexClock|undefined);
install: (lolexConfig? : any) => (LolexClock|undefined);
}

declare interface LolexClock {
Expand Down

0 comments on commit f982840

Please sign in to comment.