fix(tests): prevent frontend test dependency on system locale (#6649)

This test depended on system locale. It always failed with `LANG=fr_FR make test-frontend` and always passed with `LANG=C make test-frontend`.

- prevent this dependency by explicitly passing 'en-US'
- avoid process.env.TZ boilerplate with vi.stubEnv

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6649
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Reviewed-by: Beowulf <beowulf@beocode.eu>
This commit is contained in:
0ko 2025-01-22 03:56:36 +00:00
parent c92fe83c40
commit a40284bec4

View file

@ -18,9 +18,7 @@ test('toAbsoluteLocaleDate', () => {
expect(toAbsoluteLocaleDate('10000-01-01', '', {})).toEqual('Invalid Date');
// test different timezone
const oldTZ = process.env.TZ;
process.env.TZ = 'America/New_York';
expect(new Date('2024-03-15').toLocaleString()).toEqual('3/14/2024, 8:00:00 PM');
expect(toAbsoluteLocaleDate('2024-03-15')).toEqual('3/15/2024, 12:00:00 AM');
process.env.TZ = oldTZ;
vi.stubEnv('TZ', 'America/New_York');
expect(new Date('2024-03-15').toLocaleString('en-US')).toEqual('3/14/2024, 8:00:00 PM');
expect(toAbsoluteLocaleDate('2024-03-15', 'en-US')).toEqual('3/15/2024, 12:00:00 AM');
});