Skip to content

Commit f37c289

Browse files
committed
Fixes type check
1 parent 19113dd commit f37c289

File tree

2 files changed

+25
-30
lines changed

2 files changed

+25
-30
lines changed

packages/xpath/test/helpers.ts

+23
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,33 @@ type AnyParentNode =
1010
| XMLDocument;
1111

1212
declare global {
13+
/**
14+
* The timezone identifier used for all date and time operations in tests.
15+
* This string follows the IANA Time Zone Database format (e.g., 'America/Phoenix').
16+
* It determines the offset and DST behavior for `Date` objects and
17+
* related functions.
18+
*
19+
* @example 'America/Phoenix' // Fixed UTC-7, no DST
20+
* @example 'Europe/London' // UTC+0 (GMT) or UTC+1 (BST) with DST
21+
*/
1322
// eslint-disable-next-line no-var
1423
var TZ: string | undefined;
1524
// eslint-disable-next-line no-var
25+
var LOCALE_ID: string | undefined;
26+
/**
27+
* The locale string defining the language and regional formatting for tests.
28+
* This follows the BCP 47 language tag format (e.g., 'en-US'). It ensures consistent formatting
29+
* across tests.
30+
*
31+
* @example 'en-US' // American English
32+
*/
33+
// eslint-disable-next-line no-var
1634
var IMPLEMENTATION: string | undefined;
1735
}
1836

1937
globalThis.IMPLEMENTATION = typeof IMPLEMENTATION === 'string' ? IMPLEMENTATION : undefined;
2038
globalThis.TZ = typeof TZ === 'string' ? TZ : undefined;
39+
globalThis.LOCALE_ID = typeof LOCALE_ID === 'string' ? LOCALE_ID : undefined;
2140

2241
const namespaces: Record<string, string> = {
2342
xhtml: 'http://www.w3.org/1999/xhtml',
@@ -338,3 +357,7 @@ export const getNonNamespaceAttributes = (element: Element): readonly Attr[] =>
338357

339358
return attrs.filter(({ name }) => name !== 'xmlns' && !name.startsWith('xmlns:'));
340359
};
360+
361+
export const getDefaultDateTimeLocale = (): string => {
362+
return new Date().toLocaleString(LOCALE_ID, { timeZone: TZ });
363+
};

packages/xpath/test/setup.ts

+2-30
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,9 @@
11
import { afterEach, beforeEach } from 'vitest';
22
import { vi } from 'vitest';
3-
4-
/**
5-
* Global constants injected via Vite's `define` configuration option.
6-
* These values are replaced at build time and are available throughout
7-
* the test suite.
8-
*
9-
* @global
10-
*/
11-
declare global {
12-
/**
13-
* The timezone identifier used for all date and time operations in tests.
14-
* This string follows the IANA Time Zone Database format (e.g., 'America/Phoenix').
15-
* It determines the offset and DST behavior for `Date` objects and
16-
* related functions.
17-
*
18-
* @example 'America/Phoenix' // Fixed UTC-7, no DST
19-
* @example 'Europe/London' // UTC+0 (GMT) or UTC+1 (BST) with DST
20-
*/
21-
const TZ: string;
22-
23-
/**
24-
* The locale string defining the language and regional formatting for tests.
25-
* This follows the BCP 47 language tag format (e.g., 'en-US'). It ensures consistent formatting
26-
* across tests.
27-
*
28-
* @example 'en-US' // American English
29-
*/
30-
const LOCALE_ID: string;
31-
}
3+
import { getDefaultDateTimeLocale } from './helpers.ts';
324

335
beforeEach(() => {
34-
const dateOnTimezone = new Date().toLocaleString(LOCALE_ID, { timeZone: TZ });
6+
const dateOnTimezone = getDefaultDateTimeLocale();
357
vi.useFakeTimers({
368
now: new Date(dateOnTimezone).getTime(),
379
});

0 commit comments

Comments
 (0)