From a4b3d76da1b92d4704a624db6fedd43e9d882bd2 Mon Sep 17 00:00:00 2001 From: David Richardson Date: Mon, 2 Nov 2026 17:30:09 -0600 Subject: [PATCH] Tests: Record dates by instant in the drop-in snapshot * DropInSnapshot.j: - Describe a CPDate by its UTC instant instead of its class name. - Record the string value of a control holding a date by the date's instant, since the browser formats it in the local time zone. * DropInArchives.json: Update the CPDatePicker entry to the instant it archives. * DropInArchiveTest.j: State that the test must pass in every time zone, and how to check it in UTC. --- Tests/AppKit/DropInArchiveTest.j | 8 ++++++++ Tests/AppKit/DropInSnapshot.j | 16 ++++++++++++++++ Tests/AppKit/Resources/DropInArchives.json | 4 ++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Tests/AppKit/DropInArchiveTest.j b/Tests/AppKit/DropInArchiveTest.j index d7165f03a..e1132369a 100644 --- a/Tests/AppKit/DropInArchiveTest.j +++ b/Tests/AppKit/DropInArchiveTest.j @@ -125,6 +125,14 @@ var fs = require("fs"), /* An archive written by main must restore the view it was written from. + + The descriptions compared must be the same on every machine. A date, and the + string value of a control that holds one, are recorded by the date's instant in + UTC, because their text is in the local time zone (DropInSnapshot.j). GitHub's + continuous integration runs this test in UTC, so run it in UTC as well as in the + local time zone before committing a change: + + TZ=UTC npx jake test */ - (void)testExistingArchivesRestoreTheOriginalView { diff --git a/Tests/AppKit/DropInSnapshot.j b/Tests/AppKit/DropInSnapshot.j index 1247781b9..f097190a0 100644 --- a/Tests/AppKit/DropInSnapshot.j +++ b/Tests/AppKit/DropInSnapshot.j @@ -165,6 +165,13 @@ function DropInDescribeValue(aValue) if (aValue.isa) { + /* + A date is recorded by its instant in UTC. Its description is in the time zone + of the machine that runs the test, so it differs between machines. + */ + if ([aValue isKindOfClass:[CPDate class]]) + return "CPDate:" + (isNaN(aValue.getTime()) ? "invalid" : aValue.toISOString()); + if ([aValue isKindOfClass:[CPColor class]]) return "CPColor:" + [aValue cssString]; @@ -286,6 +293,15 @@ function DropInViewTreeState(aView) var value = [aView performSelector:selector]; + /* + A control that holds a date gives its string value in the time zone of the + machine that runs the test, because the browser formats it, not Cappuccino. It + is recorded by the date's instant instead, so that every machine records the + same snapshot. + */ + if (aGetter === @"stringValue" && [aView respondsToSelector:@selector(objectValue)] && [[aView objectValue] isKindOfClass:[CPDate class]]) + value = [aView objectValue]; + state[aGetter] = DropInDescribeValue(DropInBooleanGetters.indexOf(aGetter) !== -1 ? !!value : value); }); diff --git a/Tests/AppKit/Resources/DropInArchives.json b/Tests/AppKit/Resources/DropInArchives.json index 3875862d4..8c6fa8389 100644 --- a/Tests/AppKit/Resources/DropInArchives.json +++ b/Tests/AppKit/Resources/DropInArchives.json @@ -755,8 +755,8 @@ "lineBreakMode": "2", "verticalAlignment": "1", "doubleValue": "0", - "objectValue": "CPDate", - "stringValue": "Sat Oct 31 2026 06:00:00 GMT-0600 (Mountain Daylight Time)", + "objectValue": "CPDate:2026-10-31T12:00:00.000Z", + "stringValue": "CPDate:2026-10-31T12:00:00.000Z", "tag": "-1" }, "subviews": [