Skip to content

Commit 957ca83

Browse files
authored
Specify UTC time zone for the test suite (#9945)
The controller.bar/not-grouped/on-time test was failing on my computer because the date ranges happen to cross the end of Daylight Saving Time in the U.S., so chart was generated with one more hour of time than the test fixture expected. Using moment-timezone to specify a fixed time zone with no DST seemed like the most robust fix. (Alternatively, I could pick a date range that doesn't change DST; that ought to work.)
1 parent 4ac11a7 commit 957ca83

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ module.exports = function(karma) {
8282
{pattern: 'test/fixtures/**/*.json', included: false},
8383
{pattern: 'test/fixtures/**/*.png', included: false},
8484
'node_modules/moment/min/moment.min.js',
85+
'node_modules/moment-timezone/builds/moment-timezone-with-data.min.js',
8586
{pattern: 'test/index.js', watched: false},
8687
{pattern: 'test/BasicChartWebWorker.js', included: false},
8788
{pattern: 'src/index.js', watched: false},

package-lock.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"luxon": "^1.26.0",
8888
"markdown-it-include": "^2.0.0",
8989
"moment": "^2.29.1",
90+
"moment-timezone": "^0.5.34",
9091
"pixelmatch": "^5.2.1",
9192
"rollup": "^2.44.0",
9293
"rollup-plugin-analyzer": "^4.0.0",

test/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ jasmine.fixture = {
1818

1919
jasmine.triggerMouseEvent = triggerMouseEvent;
2020

21+
// Set a fixed time zone (and, in particular, disable Daylight Saving Time) for
22+
// more stable test results.
23+
window.moment.tz.setDefault('Etc/UTC');
24+
2125
beforeEach(function() {
2226
addMatchers();
2327
});

test/specs/scale.time.tests.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,11 @@ describe('Time scale tests', function() {
450450
datasets: [{
451451
xAxisID: 'x',
452452
data: [
453-
{t: +new Date('2018-01-08 05:14:23.234'), y: 10},
454-
{t: +new Date('2018-01-09 06:17:43.426'), y: 3}
453+
// Normally (at least with the moment.js adapter), times would be in
454+
// the user's local time zone. To allow for more stable tests, our
455+
// tests/index.js sets moment.js to use UTC; use `Z` here to match.
456+
{t: +new Date('2018-01-08 05:14:23.234Z'), y: 10},
457+
{t: +new Date('2018-01-09 06:17:43.426Z'), y: 3}
455458
]
456459
}],
457460
},
@@ -1175,7 +1178,7 @@ describe('Time scale tests', function() {
11751178
}
11761179
});
11771180

1178-
// NOTE: built-in adapter uses moment
1181+
// NOTE: the test suite is configured to use moment
11791182
var expected = {
11801183
datetime: 'MMM D, YYYY, h:mm:ss a',
11811184
millisecond: 'h:mm:ss.SSS a',
@@ -1213,7 +1216,7 @@ describe('Time scale tests', function() {
12131216
}
12141217
});
12151218

1216-
// NOTE: built-in adapter uses moment
1219+
// NOTE: the test suite is configured to use moment
12171220
var expected = {
12181221
datetime: 'MMM D, YYYY, h:mm:ss a',
12191222
millisecond: 'foo',

0 commit comments

Comments
 (0)