]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Specify UTC time zone for the test suite (#9945)
authorJosh Kelley <joshkel@gmail.com>
Mon, 6 Dec 2021 12:38:39 +0000 (07:38 -0500)
committerGitHub <noreply@github.com>
Mon, 6 Dec 2021 12:38:39 +0000 (07:38 -0500)
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.)

karma.conf.js
package-lock.json
package.json
test/index.js
test/specs/scale.time.tests.js

index 3a93f07eb9a3c87eb6dfd30a9f29937463a346fc..b122c306191de1b765eed4832aaf43282ca06714 100644 (file)
@@ -82,6 +82,7 @@ module.exports = function(karma) {
       {pattern: 'test/fixtures/**/*.json', included: false},
       {pattern: 'test/fixtures/**/*.png', included: false},
       'node_modules/moment/min/moment.min.js',
+      'node_modules/moment-timezone/builds/moment-timezone-with-data.min.js',
       {pattern: 'test/index.js', watched: false},
       {pattern: 'test/BasicChartWebWorker.js', included: false},
       {pattern: 'src/index.js', watched: false},
index 66f1ceea1ce0c2a9bdf535abe6e982df83bb80fd..1d94b187c8f20f9bb71b63c8aeec7f346c7fab23 100644 (file)
@@ -47,6 +47,7 @@
                 "luxon": "^1.26.0",
                 "markdown-it-include": "^2.0.0",
                 "moment": "^2.29.1",
+                "moment-timezone": "^0.5.34",
                 "pixelmatch": "^5.2.1",
                 "rollup": "^2.44.0",
                 "rollup-plugin-analyzer": "^4.0.0",
                 "node": "*"
             }
         },
+        "node_modules/moment-timezone": {
+            "version": "0.5.34",
+            "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.34.tgz",
+            "integrity": "sha512-3zAEHh2hKUs3EXLESx/wsgw6IQdusOT8Bxm3D9UrHPQR7zlMmzwybC8zHEM1tQ4LJwP7fcxrWr8tuBg05fFCbg==",
+            "dev": true,
+            "dependencies": {
+                "moment": ">= 2.9.0"
+            },
+            "engines": {
+                "node": "*"
+            }
+        },
         "node_modules/move-concurrently": {
             "version": "1.0.1",
             "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz",
             "integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==",
             "dev": true
         },
+        "moment-timezone": {
+            "version": "0.5.34",
+            "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.34.tgz",
+            "integrity": "sha512-3zAEHh2hKUs3EXLESx/wsgw6IQdusOT8Bxm3D9UrHPQR7zlMmzwybC8zHEM1tQ4LJwP7fcxrWr8tuBg05fFCbg==",
+            "dev": true,
+            "requires": {
+                "moment": ">= 2.9.0"
+            }
+        },
         "move-concurrently": {
             "version": "1.0.1",
             "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz",
index e56174eb9e8aa926853797281025fc8156bc9993..ee472f639089a0ee3664c878db2cfd3c644bf963 100644 (file)
@@ -87,6 +87,7 @@
         "luxon": "^1.26.0",
         "markdown-it-include": "^2.0.0",
         "moment": "^2.29.1",
+        "moment-timezone": "^0.5.34",
         "pixelmatch": "^5.2.1",
         "rollup": "^2.44.0",
         "rollup-plugin-analyzer": "^4.0.0",
index 489fca0a797dd30dcf15f72de2e533bbcece5f97..8f1b7ced3c6173621a61434ce5d1e96dc88b6d3b 100644 (file)
@@ -18,6 +18,10 @@ jasmine.fixture = {
 
 jasmine.triggerMouseEvent = triggerMouseEvent;
 
+// Set a fixed time zone (and, in particular, disable Daylight Saving Time) for
+// more stable test results.
+window.moment.tz.setDefault('Etc/UTC');
+
 beforeEach(function() {
   addMatchers();
 });
index 4113d8a497e59a895556eae99ba2966269f7f875..6e673157fc2728017c1c4a72327f24b33cc9b5b3 100644 (file)
@@ -450,8 +450,11 @@ describe('Time scale tests', function() {
         datasets: [{
           xAxisID: 'x',
           data: [
-            {t: +new Date('2018-01-08 05:14:23.234'), y: 10},
-            {t: +new Date('2018-01-09 06:17:43.426'), y: 3}
+            // Normally (at least with the moment.js adapter), times would be in
+            // the user's local time zone.  To allow for more stable tests, our
+            // tests/index.js sets moment.js to use UTC; use `Z` here to match.
+            {t: +new Date('2018-01-08 05:14:23.234Z'), y: 10},
+            {t: +new Date('2018-01-09 06:17:43.426Z'), y: 3}
           ]
         }],
       },
@@ -1175,7 +1178,7 @@ describe('Time scale tests', function() {
           }
         });
 
-        // NOTE: built-in adapter uses moment
+        // NOTE: the test suite is configured to use moment
         var expected = {
           datetime: 'MMM D, YYYY, h:mm:ss a',
           millisecond: 'h:mm:ss.SSS a',
@@ -1213,7 +1216,7 @@ describe('Time scale tests', function() {
           }
         });
 
-        // NOTE: built-in adapter uses moment
+        // NOTE: the test suite is configured to use moment
         var expected = {
           datetime: 'MMM D, YYYY, h:mm:ss a',
           millisecond: 'foo',