-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(#324): runs xpath tests with the same timezone #323
Open
latin-panda
wants to merge
3
commits into
main
Choose a base branch
from
fixes-xpath-date-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ defaults: | |
|
||
env: | ||
TZ: 'America/Phoenix' | ||
LOCALE_ID: 'en-US' | ||
|
||
jobs: | ||
install-and-build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,14 +10,33 @@ type AnyParentNode = | |
| XMLDocument; | ||
|
||
declare global { | ||
/** | ||
* The timezone identifier used for all date and time operations in tests. | ||
* This string follows the IANA Time Zone Database format (e.g., 'America/Phoenix'). | ||
* It determines the offset and DST behavior for `Date` objects and | ||
* related functions. | ||
* | ||
* @example 'America/Phoenix' // Fixed UTC-7, no DST | ||
* @example 'Europe/London' // UTC+0 (GMT) or UTC+1 (BST) with DST | ||
*/ | ||
// eslint-disable-next-line no-var | ||
var TZ: string | undefined; | ||
// eslint-disable-next-line no-var | ||
var LOCALE_ID: string | undefined; | ||
/** | ||
* The locale string defining the language and regional formatting for tests. | ||
* This follows the BCP 47 language tag format (e.g., 'en-US'). It ensures consistent formatting | ||
* across tests. | ||
* | ||
* @example 'en-US' // American English | ||
*/ | ||
// eslint-disable-next-line no-var | ||
var IMPLEMENTATION: string | undefined; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't find the usage of this |
||
} | ||
|
||
globalThis.IMPLEMENTATION = typeof IMPLEMENTATION === 'string' ? IMPLEMENTATION : undefined; | ||
globalThis.TZ = typeof TZ === 'string' ? TZ : undefined; | ||
globalThis.LOCALE_ID = typeof LOCALE_ID === 'string' ? LOCALE_ID : undefined; | ||
|
||
const namespaces: Record<string, string> = { | ||
xhtml: 'http://www.w3.org/1999/xhtml', | ||
|
@@ -338,3 +357,7 @@ export const getNonNamespaceAttributes = (element: Element): readonly Attr[] => | |
|
||
return attrs.filter(({ name }) => name !== 'xmlns' && !name.startsWith('xmlns:')); | ||
}; | ||
|
||
export const getDefaultDateTimeLocale = (): string => { | ||
return new Date().toLocaleString(LOCALE_ID, { timeZone: TZ }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { afterEach, beforeEach } from 'vitest'; | ||
import { vi } from 'vitest'; | ||
import { getDefaultDateTimeLocale } from './helpers.ts'; | ||
|
||
beforeEach(() => { | ||
const dateOnTimezone = getDefaultDateTimeLocale(); | ||
vi.useFakeTimers({ | ||
now: new Date(dateOnTimezone).getTime(), | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.useRealTimers(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was added for completeness and to clarify that the tests expect the date format in this locale.
When switching to another locale (e.g., es-AR or es-MX), some tests fail because they expect a different date format.
With
es-MX
thenow()
returns a 1-1-1970 date, and tests usingtoday()
fail.With
es-AR
thenow()
returns the current date correctly. But other tests fails, where tomorrow is set in en-US standard 2025-03-05