Deps migration (#1988)

* chore: migrate eslint to oxlint

* chore: migrate prettier to oxfmt

* chore: migrate typescript

* chore: toThrow should have a expected value

* chore: cast test value as Day

* chore: small title fix

* chore: mocks should be hoisted

* chore: incorrect async useage

* chore: test should be inside description

* chore: test sohuld include an expeced

* chore: oxfmt

---------

Co-authored-by: alex-Arc <omnivox@LAPTOP-RC5SNBVV.localdomain>
This commit is contained in:
Carlos Valente
2026-03-08 16:22:12 +01:00
committed by GitHub
parent 9516ac21bb
commit 1849b4d39f
501 changed files with 2678 additions and 4654 deletions
@@ -1,52 +1,54 @@
import { Day } from 'ontime-types';
import { checkIsNextDay } from './checkIsNextDay';
import { MILLIS_PER_HOUR } from './conversionUtils';
describe('checkIsNextDay', () => {
it('returns false if there is no previous event', () => {
const current = { timeStart: 0, dayOffset: 0 };
const current = { timeStart: 0, dayOffset: 0 as Day };
const previous = null;
expect(checkIsNextDay(current, previous)).toBeFalsy();
});
it('returns false if event starts after one before', () => {
const current = { timeStart: 11, dayOffset: 0 };
const previous = { timeStart: 10, duration: 2, dayOffset: 0 };
const current = { timeStart: 11, dayOffset: 0 as Day };
const previous = { timeStart: 10, duration: 2, dayOffset: 0 as Day };
expect(checkIsNextDay(current, previous)).toBeFalsy();
});
it('returns true if event starts after one before', () => {
const current = { timeStart: 9, dayOffset: 1 };
const previous = { timeStart: 10, duration: 2, dayOffset: 0 };
const current = { timeStart: 9, dayOffset: 1 as Day };
const previous = { timeStart: 10, duration: 2, dayOffset: 0 as Day };
expect(checkIsNextDay(current, previous)).toBeTruthy();
});
it('returns true if event starts at the same time as one before', () => {
const current = { timeStart: 10, dayOffset: 1 };
const previous = { timeStart: 10, duration: 2, dayOffset: 0 };
const current = { timeStart: 10, dayOffset: 1 as Day };
const previous = { timeStart: 10, duration: 2, dayOffset: 0 as Day };
expect(checkIsNextDay(current, previous)).toBeTruthy();
});
it('should account for an event that crossed midnight', () => {
const current = { timeStart: 1 * MILLIS_PER_HOUR, dayOffset: 1 };
const previous = { timeStart: 20 * MILLIS_PER_HOUR, duration: 6 * MILLIS_PER_HOUR, dayOffset: 0 }; // event finished at 02:00:00
const current = { timeStart: 1 * MILLIS_PER_HOUR, dayOffset: 1 as Day };
const previous = { timeStart: 20 * MILLIS_PER_HOUR, duration: 6 * MILLIS_PER_HOUR, dayOffset: 0 as Day }; // event finished at 02:00:00
expect(checkIsNextDay(current, previous)).toBeFalsy();
});
it('should account for an event that crossed midnight and there is a gap', () => {
const current = { timeStart: 2 * MILLIS_PER_HOUR, dayOffset: 1 };
const previous = { timeStart: 23 * MILLIS_PER_HOUR, duration: 2 * MILLIS_PER_HOUR, dayOffset: 0 }; // event finished at 01:00:00
const current = { timeStart: 2 * MILLIS_PER_HOUR, dayOffset: 1 as Day };
const previous = { timeStart: 23 * MILLIS_PER_HOUR, duration: 2 * MILLIS_PER_HOUR, dayOffset: 0 as Day }; // event finished at 01:00:00
expect(checkIsNextDay(current, previous)).toBeFalsy();
});
it('should account for an event that crossed midnight with no overlaps', () => {
const current = { timeStart: 19 * MILLIS_PER_HOUR, dayOffset: 1 };
const previous = { timeStart: 20 * MILLIS_PER_HOUR, duration: 6 * MILLIS_PER_HOUR, dayOffset: 0 }; // event finished at 02:00:00
const current = { timeStart: 19 * MILLIS_PER_HOUR, dayOffset: 1 as Day };
const previous = { timeStart: 20 * MILLIS_PER_HOUR, duration: 6 * MILLIS_PER_HOUR, dayOffset: 0 as Day }; // event finished at 02:00:00
expect(checkIsNextDay(current, previous)).toBeFalsy();
});
it('should account for an event that finishes exactly at midnight', () => {
const current = { timeStart: 2 * MILLIS_PER_HOUR, dayOffset: 1 };
const previous = { timeStart: 23 * MILLIS_PER_HOUR, duration: 1 * MILLIS_PER_HOUR, dayOffset: 0 }; // event finished at 24:00:00
const current = { timeStart: 2 * MILLIS_PER_HOUR, dayOffset: 1 as Day };
const previous = { timeStart: 23 * MILLIS_PER_HOUR, duration: 1 * MILLIS_PER_HOUR, dayOffset: 0 as Day }; // event finished at 24:00:00
expect(checkIsNextDay(current, previous)).toBeTruthy();
});
});
@@ -1,6 +1,6 @@
import { OffsetMode } from 'ontime-types';
import { Day, OffsetMode } from 'ontime-types';
import { dayInMs, MILLIS_PER_HOUR } from './conversionUtils';
import { MILLIS_PER_HOUR, dayInMs } from './conversionUtils';
import { getExpectedStart } from './getExpectedStart';
describe('getExpectedStart()', () => {
@@ -9,7 +9,7 @@ describe('getExpectedStart()', () => {
const testEvent = {
timeStart: 100,
delay: 0,
dayOffset: 0,
dayOffset: 0 as Day,
};
const testState = {
currentDay: 0,
@@ -27,7 +27,7 @@ describe('getExpectedStart()', () => {
test('running behind', () => {
const testEvent = {
timeStart: 100,
dayOffset: 0,
dayOffset: 0 as Day,
delay: 0,
};
const testState = {
@@ -46,7 +46,7 @@ describe('getExpectedStart()', () => {
test('running ahead', () => {
const testEvent = {
timeStart: 100,
dayOffset: 0,
dayOffset: 0 as Day,
delay: 0,
};
const testState = {
@@ -65,7 +65,7 @@ describe('getExpectedStart()', () => {
test('running behind with enough gaps', () => {
const testEvent = {
timeStart: 100,
dayOffset: 0,
dayOffset: 0 as Day,
delay: 0,
};
const testState = {
@@ -84,7 +84,7 @@ describe('getExpectedStart()', () => {
test('running behind with too little gaps', () => {
const testEvent = {
timeStart: 100,
dayOffset: 0,
dayOffset: 0 as Day,
delay: 0,
};
const testState = {
@@ -120,13 +120,13 @@ describe('getExpectedStart()', () => {
//event 2
expect(
getExpectedStart(
{ dayOffset: 0, delay: 0, timeStart: timeStartEvent2 },
{ dayOffset: 0 as Day, delay: 0, timeStart: timeStartEvent2 },
{ ...testState, isLinkedToLoaded: true },
),
).toBe(110);
expect(
getExpectedStart(
{ dayOffset: 0, delay: 0, timeStart: timeStartEvent2 },
{ dayOffset: 0 as Day, delay: 0, timeStart: timeStartEvent2 },
{ ...testState, isLinkedToLoaded: false },
),
).toBe(110);
@@ -134,13 +134,13 @@ describe('getExpectedStart()', () => {
//event 3
expect(
getExpectedStart(
{ dayOffset: 0, delay: 0, timeStart: timeStartEvent3 },
{ dayOffset: 0 as Day, delay: 0, timeStart: timeStartEvent3 },
{ ...testState, isLinkedToLoaded: true },
),
).toBe(120);
expect(
getExpectedStart(
{ dayOffset: 0, delay: 0, timeStart: timeStartEvent3 },
{ dayOffset: 0 as Day, delay: 0, timeStart: timeStartEvent3 },
{ ...testState, isLinkedToLoaded: false },
),
).toBe(120);
@@ -151,13 +151,13 @@ describe('getExpectedStart()', () => {
//event 2
expect(
getExpectedStart(
{ dayOffset: 0, delay: 0, timeStart: timeStartEvent2 },
{ dayOffset: 0 as Day, delay: 0, timeStart: timeStartEvent2 },
{ ...testState, isLinkedToLoaded: true },
),
).toBe(115);
expect(
getExpectedStart(
{ dayOffset: 0, delay: 0, timeStart: timeStartEvent2 },
{ dayOffset: 0 as Day, delay: 0, timeStart: timeStartEvent2 },
{ ...testState, isLinkedToLoaded: false },
),
).toBe(115);
@@ -165,13 +165,13 @@ describe('getExpectedStart()', () => {
//event 3
expect(
getExpectedStart(
{ dayOffset: 0, delay: 0, timeStart: timeStartEvent3 },
{ dayOffset: 0 as Day, delay: 0, timeStart: timeStartEvent3 },
{ ...testState, isLinkedToLoaded: true },
),
).toBe(125);
expect(
getExpectedStart(
{ dayOffset: 0, delay: 0, timeStart: timeStartEvent3 },
{ dayOffset: 0 as Day, delay: 0, timeStart: timeStartEvent3 },
{ ...testState, isLinkedToLoaded: false },
),
).toBe(125);
@@ -180,7 +180,7 @@ describe('getExpectedStart()', () => {
test('gaps', () => {
const testEvent = {
timeStart: 20,
dayOffset: 0,
dayOffset: 0 as Day,
delay: 0,
};
const testState = {
@@ -204,7 +204,7 @@ describe('getExpectedStart()', () => {
test('added/remove time', () => {
const testEvent = {
timeStart: 20,
dayOffset: 0,
dayOffset: 0 as Day,
delay: 0,
};
const testState = {
@@ -242,7 +242,7 @@ describe('getExpectedStart()', () => {
// this event will start the current day
expect(
getExpectedStart(
{ timeStart: 10, delay: 0, dayOffset: 0 },
{ timeStart: 10, delay: 0, dayOffset: 0 as Day },
{ ...testState, totalGap: 0, isLinkedToLoaded: false },
),
).toBe(110);
@@ -252,7 +252,7 @@ describe('getExpectedStart()', () => {
// but in relative mode with and actual start that is 100 offset it starts in dayInMs
expect(
getExpectedStart(
{ timeStart: 0, delay: 0, dayOffset: 1 },
{ timeStart: 0, delay: 0, dayOffset: 1 as Day },
{ ...testState, totalGap: dayInMs - 20, isLinkedToLoaded: false },
),
).toBe(dayInMs + 100);
@@ -262,7 +262,7 @@ describe('getExpectedStart()', () => {
test('overlap with negative total gap', () => {
const testEvent = {
timeStart: 5,
dayOffset: 0,
dayOffset: 0 as Day,
delay: 0,
};
const testState = {
@@ -281,7 +281,7 @@ describe('getExpectedStart()', () => {
test('we started on the day before', () => {
const testEvent = {
timeStart: 5,
dayOffset: 0,
dayOffset: 0 as Day,
delay: 0,
};
const testState = {
@@ -299,7 +299,7 @@ describe('getExpectedStart()', () => {
test('next day in multi-day rundown', () => {
const testEvent = {
timeStart: 5,
dayOffset: 1,
dayOffset: 1 as Day,
delay: 0,
};
const testState = {
@@ -1,4 +1,6 @@
import { dayInMs, MILLIS_PER_HOUR, MILLIS_PER_MINUTE } from './conversionUtils';
import { Day } from 'ontime-types';
import { MILLIS_PER_HOUR, MILLIS_PER_MINUTE, dayInMs } from './conversionUtils';
import { getTimeFrom } from './getTimeFrom';
describe('getTimeFrom', () => {
@@ -6,28 +8,36 @@ describe('getTimeFrom', () => {
const expected = 75600000 - 71700000; // current start - previousEnd
expect(
getTimeFrom(
{ timeStart: 21 * MILLIS_PER_HOUR, dayOffset: 0 },
{ timeStart: 19 * MILLIS_PER_HOUR + 20 * MILLIS_PER_MINUTE, duration: 35 * MILLIS_PER_MINUTE, dayOffset: 0 },
{ timeStart: 21 * MILLIS_PER_HOUR, dayOffset: 0 as Day },
{
timeStart: 19 * MILLIS_PER_HOUR + 20 * MILLIS_PER_MINUTE,
duration: 35 * MILLIS_PER_MINUTE,
dayOffset: 0 as Day,
},
),
).toBe(expected);
});
it('accounts for partially overlapping events', () => {
const expected = -1;
expect(getTimeFrom({ timeStart: 11, dayOffset: 0 }, { timeStart: 10, duration: 2, dayOffset: 0 })).toBe(expected);
expect(
getTimeFrom({ timeStart: 11, dayOffset: 0 as Day }, { timeStart: 10, duration: 2, dayOffset: 0 as Day }),
).toBe(expected);
});
it('accounts for events that are fully contained', () => {
const expected = -6;
expect(getTimeFrom({ timeStart: 10, dayOffset: 0 }, { timeStart: 8, duration: 8, dayOffset: 0 })).toBe(expected);
expect(
getTimeFrom({ timeStart: 10, dayOffset: 0 as Day }, { timeStart: 8, duration: 8, dayOffset: 0 as Day }),
).toBe(expected);
});
it('fully overlapping events are the next day', () => {
const expected = dayInMs - 2 * MILLIS_PER_HOUR;
expect(
getTimeFrom(
{ timeStart: 10 * MILLIS_PER_HOUR, dayOffset: 1 },
{ timeStart: 10 * MILLIS_PER_HOUR, duration: 2 * MILLIS_PER_HOUR, dayOffset: 0 },
{ timeStart: 10 * MILLIS_PER_HOUR, dayOffset: 1 as Day },
{ timeStart: 10 * MILLIS_PER_HOUR, duration: 2 * MILLIS_PER_HOUR, dayOffset: 0 as Day },
),
).toBe(expected);
});
@@ -36,8 +46,8 @@ describe('getTimeFrom', () => {
const expected = -MILLIS_PER_HOUR; // (previousEnd - currentStart);
expect(
getTimeFrom(
{ timeStart: 22 * MILLIS_PER_HOUR, dayOffset: 0 },
{ timeStart: 20 * MILLIS_PER_HOUR, duration: 3 * MILLIS_PER_HOUR, dayOffset: 0 },
{ timeStart: 22 * MILLIS_PER_HOUR, dayOffset: 0 as Day },
{ timeStart: 20 * MILLIS_PER_HOUR, duration: 3 * MILLIS_PER_HOUR, dayOffset: 0 as Day },
),
).toBe(expected);
});
@@ -46,8 +56,8 @@ describe('getTimeFrom', () => {
const expected = -MILLIS_PER_HOUR; // (previousEnd - currentStart);
expect(
getTimeFrom(
{ timeStart: 1 * MILLIS_PER_HOUR, dayOffset: 1 },
{ timeStart: 20 * MILLIS_PER_HOUR, duration: 6 * MILLIS_PER_HOUR, dayOffset: 0 },
{ timeStart: 1 * MILLIS_PER_HOUR, dayOffset: 1 as Day },
{ timeStart: 20 * MILLIS_PER_HOUR, duration: 6 * MILLIS_PER_HOUR, dayOffset: 0 as Day },
),
).toBe(expected);
});
@@ -1,9 +1,11 @@
import { Day } from 'ontime-types';
import { MILLIS_PER_HOUR, MILLIS_PER_MINUTE } from './conversionUtils';
import { isNewLatest } from './isNewLatest';
describe('isNewLatest', () => {
it('should be true if there is no previous', () => {
const current = { timeStart: 0, duration: MILLIS_PER_HOUR, dayOffset: 0 };
const current = { timeStart: 0, duration: MILLIS_PER_HOUR, dayOffset: 0 as Day };
const previous = null;
expect(isNewLatest(current, previous)).toBe(true);
});
@@ -12,41 +14,41 @@ describe('isNewLatest', () => {
const current = {
timeStart: 21 * MILLIS_PER_HOUR + 10 * MILLIS_PER_MINUTE,
duration: 10 * MILLIS_PER_MINUTE,
dayOffset: 0,
dayOffset: 0 as Day,
};
const previous = { timeStart: 21 * MILLIS_PER_HOUR, duration: MILLIS_PER_HOUR, dayOffset: 0 };
const previous = { timeStart: 21 * MILLIS_PER_HOUR, duration: MILLIS_PER_HOUR, dayOffset: 0 as Day };
expect(isNewLatest(current, previous)).toBe(false);
});
it('should be true if it starts when the previous finishes', () => {
const current = { timeStart: 10 * MILLIS_PER_HOUR, duration: MILLIS_PER_HOUR, dayOffset: 0 };
const previous = { timeStart: 9 * MILLIS_PER_HOUR, duration: MILLIS_PER_HOUR, dayOffset: 0 };
const current = { timeStart: 10 * MILLIS_PER_HOUR, duration: MILLIS_PER_HOUR, dayOffset: 0 as Day };
const previous = { timeStart: 9 * MILLIS_PER_HOUR, duration: MILLIS_PER_HOUR, dayOffset: 0 as Day };
expect(isNewLatest(current, previous)).toBe(true);
});
it('should be true if it starts the same day the previous finishes', () => {
const current = { timeStart: 22 * MILLIS_PER_HOUR, duration: MILLIS_PER_HOUR, dayOffset: 0 };
const previous = { timeStart: 9 * MILLIS_PER_HOUR, duration: MILLIS_PER_HOUR, dayOffset: 0 };
const current = { timeStart: 22 * MILLIS_PER_HOUR, duration: MILLIS_PER_HOUR, dayOffset: 0 as Day };
const previous = { timeStart: 9 * MILLIS_PER_HOUR, duration: MILLIS_PER_HOUR, dayOffset: 0 as Day };
expect(isNewLatest(current, previous)).toBe(true);
});
it('should be true if it finishes after the previous, accounting for passing midnight', () => {
const current = { timeStart: 1 * MILLIS_PER_HOUR, duration: 2 * MILLIS_PER_HOUR, dayOffset: 1 };
const previous = { timeStart: 23 * MILLIS_PER_HOUR, duration: 2 * MILLIS_PER_HOUR, dayOffset: 0 };
const current = { timeStart: 1 * MILLIS_PER_HOUR, duration: 2 * MILLIS_PER_HOUR, dayOffset: 1 as Day };
const previous = { timeStart: 23 * MILLIS_PER_HOUR, duration: 2 * MILLIS_PER_HOUR, dayOffset: 0 as Day };
expect(isNewLatest(current, previous)).toBe(true);
});
it('should be true if it the next day', () => {
const current = { timeStart: 8 * MILLIS_PER_HOUR, duration: 2 * MILLIS_PER_HOUR, dayOffset: 1 };
const previous = { timeStart: 9 * MILLIS_PER_HOUR, duration: 2 * MILLIS_PER_HOUR, dayOffset: 0 };
const current = { timeStart: 8 * MILLIS_PER_HOUR, duration: 2 * MILLIS_PER_HOUR, dayOffset: 1 as Day };
const previous = { timeStart: 9 * MILLIS_PER_HOUR, duration: 2 * MILLIS_PER_HOUR, dayOffset: 0 as Day };
expect(isNewLatest(current, previous)).toBe(true);
});
it('should be true if it the next day (2)', () => {
const current = { timeStart: 9 * MILLIS_PER_HOUR, duration: 2 * MILLIS_PER_HOUR, dayOffset: 1 };
const previous = { timeStart: 9 * MILLIS_PER_HOUR, duration: 11 * MILLIS_PER_HOUR, dayOffset: 0 };
const current = { timeStart: 9 * MILLIS_PER_HOUR, duration: 2 * MILLIS_PER_HOUR, dayOffset: 1 as Day };
const previous = { timeStart: 9 * MILLIS_PER_HOUR, duration: 11 * MILLIS_PER_HOUR, dayOffset: 0 as Day };
expect(isNewLatest(current, previous)).toBe(true);
});
});
@@ -1,14 +1,14 @@
import { isISO8601, isTimeString } from './isTimeString';
describe('test isTimeString() function', () => {
it('it validates time strings', () => {
it('validates time strings', () => {
const ts = ['2', '2:10', '2:10:22'];
for (const s of ts) {
expect(isTimeString(s)).toBe(true);
}
});
it('it fails overloaded times', () => {
it('fails overloaded times', () => {
const ts = ['70', '89:10', '26:10:22'];
for (const s of ts) {
expect(isTimeString(s)).toBe(false);
@@ -45,7 +45,7 @@ describe('test parseUserTime()', () => {
}
});
describe('#33 separators are parsed according to doc examples ', () => {
describe('#33 separators are parsed according to doc examples', () => {
const ts = [
{ value: '0.1', expect: MILLIS_PER_MINUTE },
{ value: '0 1', expect: MILLIS_PER_MINUTE },
@@ -112,7 +112,7 @@ describe('test parseUserTime()', () => {
{ value: '10AM', expect: 10 * MILLIS_PER_HOUR },
{ value: '10PM', expect: (12 + 10) * MILLIS_PER_HOUR },
{ value: '12am', expect: 0 * MILLIS_PER_HOUR },
{ value: '12am', expect: 0 },
{ value: '12pm', expect: 12 * MILLIS_PER_HOUR },
{ value: '1:10am', expect: 1 * MILLIS_PER_HOUR + 10 * MILLIS_PER_MINUTE },
@@ -132,7 +132,7 @@ describe('test parseUserTime()', () => {
{ value: '10:10AM', expect: 10 * MILLIS_PER_HOUR + 10 * MILLIS_PER_MINUTE },
{ value: '10:10PM', expect: (12 + 10) * MILLIS_PER_HOUR + 10 * MILLIS_PER_MINUTE },
{ value: '12:10am', expect: 0 * MILLIS_PER_HOUR + 10 * MILLIS_PER_MINUTE },
{ value: '12:10am', expect: 10 * MILLIS_PER_MINUTE },
{ value: '12:10pm', expect: 12 * MILLIS_PER_HOUR + 10 * MILLIS_PER_MINUTE },
{ value: '1:10:10am', expect: 1 * MILLIS_PER_HOUR + 10 * MILLIS_PER_MINUTE + 10 * MILLIS_PER_SECOND },
@@ -152,7 +152,7 @@ describe('test parseUserTime()', () => {
{ value: '10:10:10AM', expect: 10 * MILLIS_PER_HOUR + 10 * MILLIS_PER_MINUTE + 10 * MILLIS_PER_SECOND },
{ value: '10:10:10PM', expect: (12 + 10) * MILLIS_PER_HOUR + 10 * MILLIS_PER_MINUTE + 10 * MILLIS_PER_SECOND },
{ value: '12:10:10am', expect: 0 * MILLIS_PER_HOUR + 10 * MILLIS_PER_MINUTE + 10 * MILLIS_PER_SECOND },
{ value: '12:10:10am', expect: 10 * MILLIS_PER_MINUTE + 10 * MILLIS_PER_SECOND },
{ value: '12:10:10pm', expect: 12 * MILLIS_PER_HOUR + 10 * MILLIS_PER_MINUTE + 10 * MILLIS_PER_SECOND },
];
@@ -1,6 +1,6 @@
import { TimerType } from 'ontime-types';
import { dayInMs, MILLIS_PER_HOUR } from './conversionUtils';
import { MILLIS_PER_HOUR, dayInMs } from './conversionUtils';
import { formatFromMillis, millisToString, removeLeadingZero } from './timeFormatting';
describe('millisToString()', () => {