mirror of
https://github.com/MichMich/MagicMirror.git
synced 2026-06-04 10:19:29 +00:00
node-ical 0.25.x added `expandRecurringEvent()` — a proper API for
expanding both recurring and non-recurring events, including EXDATE
filtering and RECURRENCE-ID overrides. This PR replaces our hand-rolled
equivalent with it.
`calendarfetcherutils.js` loses ~125 lines of code. What's left only
deals with MagicMirror-specific concerns: timezone conversion,
config-based filtering, and output formatting. The extra lines in the
diff come from new tests.
## What was removed
- `getMomentsFromRecurringEvent()` — manual rrule.js wrapping with
custom date extraction
- `isFullDayEvent()` — heuristic with multiple fallback checks
- `isFacebookBirthday` workaround — patched years < 1900 and
special-cased `@facebook.com` UIDs
- The `if (event.rrule) / else` split — all events now go through a
single code path
## Bugs fixed along the way
Both were subtle enough to go unnoticed before:
- **`[object Object]` in event titles/description/location** — node-ical
represents ICS properties with parameters (e.g.
`DESCRIPTION;LANGUAGE=de:Text`) as `{val, params}` objects. The old code
passed them straight through. Mainly affected multilingual Exchange/O365
setups. Fixed with `unwrapParameterValue()`.
- **`excludedEvents` with `until` never worked** —
`shouldEventBeExcluded()` returned `{ excluded, until }` but the caller
destructured it as `{ excluded, eventFilterUntil }`, so the until date
was always `undefined` and events were never hidden. Fixed by correcting
the destructuring key.
The expansion loop also gets error isolation: a single broken event is
logged and skipped instead of aborting the whole feed.
## Other clean-ups
- Replaced `this.shouldEventBeExcluded` with
`CalendarFetcherUtils.shouldEventBeExcluded` — avoids context-loss bugs
when the method is destructured or called indirectly.
- Replaced deprecated `substr()` with `slice()`.
- Replaced `now < filterUntil` (operator overloading) with
`now.isBefore(filterUntil)` — idiomatic Moment.js comparison.
- Fixed `@returns` JSDoc: `string[]` → `object[]`.
- Moved verbose `Log.debug("Processing entry...")` after the `VEVENT`
type guard to reduce log noise from non-event entries.
- Replaced `JSON.stringify(event)` debug log with a lightweight summary
to avoid unnecessary serialization cost.
- Added comment explaining the 0-duration → end-of-day fallback for
events without DTEND.
## Tests
24 unit tests, all passing (`npx vitest run
tests/unit/modules/default/calendar/`).
New coverage: `excludedEvents` with/without `until`, Facebook birthday
year expansion, output object shape, no-DTEND fallback, error isolation,
`unwrapParameterValue`, `getTitleFromEvent`, ParameterValue properties,
RECURRENCE-ID overrides, DURATION (single and recurring).
106 lines
2.4 KiB
JavaScript
106 lines
2.4 KiB
JavaScript
import { defineConfig } from "vitest/config";
|
|
|
|
/*
|
|
* Sequential execution keeps our shared test server stable:
|
|
* - All suites bind to port 8080
|
|
* - Fixtures and temp paths are reused between tests
|
|
* - Debugging becomes predictable
|
|
*
|
|
* Parallel execution would require dynamic ports and isolated fixtures,
|
|
* so we intentionally cap Vitest at a single worker for now.
|
|
*
|
|
* Projects separate unit, e2e (Playwright), and electron tests with
|
|
* appropriate timeouts for each test type.
|
|
*/
|
|
|
|
export default defineConfig({
|
|
test: {
|
|
// Shared settings for all test types
|
|
globals: true,
|
|
environment: "node",
|
|
setupFiles: ["./tests/utils/vitest-setup.js"],
|
|
// Stop test execution on first failure
|
|
bail: 3,
|
|
// Automatically restore all mocks after each test to prevent leaks
|
|
restoreAllMocks: true,
|
|
|
|
// Shared exclude patterns
|
|
exclude: [
|
|
"**/node_modules/**",
|
|
"**/dist/**",
|
|
"tests/unit/mocks/**",
|
|
"tests/unit/helpers/**",
|
|
"tests/electron/helpers/**",
|
|
"tests/e2e/helpers/**",
|
|
"tests/e2e/mocks/**",
|
|
"tests/configs/**",
|
|
"tests/utils/**"
|
|
],
|
|
|
|
// Projects with specific configurations per test type
|
|
projects: [
|
|
{
|
|
test: {
|
|
name: "unit",
|
|
globals: true,
|
|
environment: "node",
|
|
setupFiles: ["./tests/utils/vitest-setup.js"],
|
|
include: [
|
|
"tests/unit/**/*_spec.js",
|
|
"tests/unit/defaultmodules/calendar/calendar_fetcher_utils_bad_rrule.js"
|
|
],
|
|
testTimeout: 20000,
|
|
hookTimeout: 10000
|
|
}
|
|
},
|
|
{
|
|
test: {
|
|
name: "e2e",
|
|
globals: true,
|
|
environment: "node",
|
|
setupFiles: ["./tests/utils/vitest-setup.js"],
|
|
include: ["tests/e2e/**/*_spec.js"],
|
|
testTimeout: 60000,
|
|
hookTimeout: 30000
|
|
}
|
|
},
|
|
{
|
|
test: {
|
|
name: "electron",
|
|
globals: true,
|
|
environment: "node",
|
|
setupFiles: ["./tests/utils/vitest-setup.js"],
|
|
include: ["tests/electron/**/*_spec.js"],
|
|
testTimeout: 120000,
|
|
hookTimeout: 30000
|
|
}
|
|
}
|
|
],
|
|
|
|
// Coverage configuration
|
|
coverage: {
|
|
provider: "v8",
|
|
reporter: ["lcov", "text"],
|
|
include: [
|
|
"clientonly/**/*.js",
|
|
"js/**/*.js",
|
|
"defaultmodules/**/*.js",
|
|
"serveronly/**/*.js"
|
|
],
|
|
exclude: [
|
|
"**/node_modules/**",
|
|
"**/tests/**",
|
|
"**/dist/**"
|
|
]
|
|
},
|
|
|
|
/*
|
|
* Pool settings for isolated test execution. Keep maxWorkers at 1 so
|
|
* port 8080 and shared fixtures remain safe across the full suite.
|
|
*/
|
|
pool: "forks",
|
|
maxWorkers: 1,
|
|
isolate: true
|
|
}
|
|
});
|