Fix periodic notes crash and add regression test coverage
obsidian-daily-notes-interface sets __esModule: true in its CJS bundle
(via Rollup's named-exports mode) but does not export a default. esbuild
respects the __esModule flag and resolves the default import to
exports.default, which is undefined, causing the crash reported in #255:
TypeError: Cannot read properties of undefined (reading 'getDailyNoteSettings')
at VaultOperations.getPeriodicNoteInterface
Fix: switch to a namespace import (import * as periodicNotes) so all
named exports are captured correctly.
To catch this class of regression at unit-test time:
- Add mocks/obsidian-daily-notes-interface.ts with all named exports as
jest.fn() instances, mirroring the real library's API.
- Register the mock in jest.config.js, taking care to place it before the
bare "obsidian" pattern (which is a regex and would otherwise swallow
"obsidian-daily-notes-interface" first). Also anchor the obsidian
pattern to ^obsidian$ to prevent future similar collisions.
- Expose window.moment in jest.setup.js (moment is available in node_modules
as a transitive dep; Obsidian makes it a global in production).
- Add a "periodicNotes" describe block in requestHandler.test.ts that
exercises the real VaultOperations.getPeriodicNoteInterface() rather
than mocking out periodicGetNote/periodicGetOrCreateNote at the instance
level. Tests cover: unknown period (404), period not enabled (400),
note not found (404, no crash), and note found (200).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> A
Adam Coddington committed
f0d86d662ea5c463d4d151e353f0338eda73de99
Parent: eceb66f