Skip to content

Commit 4e625cb

Browse files
committed
Fix TZ dependent tests
1 parent 8e6e1db commit 4e625cb

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

packages/neaps/test/index.test.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,28 @@ import {
55
} from '../src/index.js'
66
import { describe, test, expect } from 'vitest'
77

8+
// FIXME: this is required for these tests to pass. I can't figure out how to get accurate
9+
// predictions for a station in a non-UTC timezone without this.
10+
process.env.TZ = 'UTC'
11+
812
describe('getExtremesPrediction', () => {
913
test('gets extremes from nearest station', () => {
10-
const { predictions } = getExtremesPrediction({
14+
const extremes = getExtremesPrediction({
1115
lat: 26.7,
1216
lon: -80.05,
13-
start: new Date('2025-12-17T05:00:00Z'),
14-
end: new Date('2025-12-18T05:00:00Z'),
17+
start: new Date('2025-12-18T00:00:00-05:00'),
18+
end: new Date('2025-12-19T00:00:00-05:00'),
1519
timeFidelity: 6,
1620
datum: 'MLLW'
1721
})
1822

23+
expect(extremes.station.id).toEqual('us-fl-port-of-west-palm-beach')
24+
expect(extremes.datum).toBe('MLLW')
25+
26+
const { predictions } = extremes
1927
expect(predictions.length).toBe(4)
20-
expect(predictions[0].time).toEqual(new Date('2025-12-17T09:47:36.000Z')) // 04:47 EST
21-
expect(predictions[0].level).toBeCloseTo(0.03, 1) // NOAA prediction is 0.03, neaps is 0.05
28+
expect(predictions[0].time).toEqual(new Date('2025-12-18T05:29:48.000Z'))
29+
expect(predictions[0].level).toBeCloseTo(0.02, 2)
2230
expect(predictions[0].high).toBe(false)
2331
expect(predictions[0].low).toBe(true)
2432
expect(predictions[0].label).toBe('Low')
@@ -29,12 +37,12 @@ describe('getExtremesPrediction', () => {
2937
{ latitude: 26.7, longitude: -80.05 }
3038
].forEach((position) => {
3139
test(`accepts position with ${Object.keys(position).join('/')}`, () => {
32-
const { predictions } = getExtremesPrediction({
40+
const extremes = getExtremesPrediction({
3341
...position,
34-
start: new Date('2025-12-17T05:00:00Z'),
42+
start: new Date('2025-12-17T00:00:00Z'),
3543
end: new Date('2025-12-18T05:00:00Z')
3644
})
37-
expect(predictions.length).toBe(4)
45+
expect(extremes.station.id).toEqual('us-fl-port-of-west-palm-beach')
3846
})
3947
})
4048
})
@@ -50,8 +58,8 @@ describe('nearestStation', () => {
5058
test('can return extremes from station', () => {
5159
const station = nearestStation({ lat: 26.7, lon: -80.05 })
5260

53-
const start = new Date('2025-12-17T05:00:00Z')
54-
const end = new Date('2025-12-18T05:00:00Z')
61+
const start = new Date('2025-12-17T00:00:00-05:00')
62+
const end = new Date('2025-12-18T05:00:00-05:00')
5563

5664
const { predictions } = station.getExtremesPrediction({
5765
start,
@@ -61,11 +69,11 @@ describe('nearestStation', () => {
6169
})
6270

6371
expect(predictions.length).toBe(4)
64-
expect(predictions[0].time).toEqual(new Date('2025-12-17T09:47:36.000Z')) // 04:47 EST
65-
expect(predictions[0].level).toBeCloseTo(0.03, 1) // NOAA prediction is 0.03, neaps is 0.05
66-
expect(predictions[0].high).toBe(false)
67-
expect(predictions[0].low).toBe(true)
68-
expect(predictions[0].label).toBe('Low')
72+
expect(predictions[0].time).toEqual(new Date('2025-12-17T11:23:06.000Z'))
73+
expect(predictions[0].level).toBeCloseTo(0.9, 1)
74+
expect(predictions[0].high).toBe(true)
75+
expect(predictions[0].low).toBe(false)
76+
expect(predictions[0].label).toBe('High')
6977
})
7078
})
7179

0 commit comments

Comments
 (0)