Skip to content

Add vitest test infrastructure with initial importer tests#527

Open
ventilla wants to merge 1 commit intoobsidianmd:masterfrom
ventilla:add-test-infrastructure
Open

Add vitest test infrastructure with initial importer tests#527
ventilla wants to merge 1 commit intoobsidianmd:masterfrom
ventilla:add-test-infrastructure

Conversation

@ventilla
Copy link
Copy Markdown

@ventilla ventilla commented Apr 7, 2026

Summary

  • Sets up vitest as the test runner with jsdom environment
  • Adds a lightweight mock of the obsidian module for unit testing
  • Adds initial tests for three areas:
    • Google Keep importer (20 tests): tag sanitization, text/list conversion, labels, colors, attachments
    • Apple Journal importer (20 tests): golden file comparison against existing fixtures, date extraction, front matter tokens
    • Shared utilities (15 tests): sanitizeFileName, parseHTML, serializeFrontMatter, truncateText

Motivation

The repo has excellent test fixture files in tests/ but no automated test runner. This PR adds the infrastructure so that:

  • Contributors can run npm test to validate changes
  • CI can be added later to catch regressions
  • The existing fixtures (Keep JSON, Apple Journal HTML/MD pairs) are exercised automatically

Test plan

  • npx vitest run — all 55 tests pass
  • npx eslint src/**/*.test.ts — no lint violations
  • No changes to existing source files — purely additive
  • Reviewer: verify tests match expected importer behavior

Notes

  • Tests are colocated with source (src/formats/*.test.ts) following vitest conventions
  • The obsidian mock (src/__mocks__/obsidian.ts) stubs UI classes and provides faithful implementations of utility functions (stringifyYaml, htmlToMarkdown, moment, normalizePath)
  • Apple Journal tests document a minor gap: the current importer collects a "Health" token via .gridItemOverlayFooter that the fixture .md files omit

Set up vitest as the test runner with jsdom environment for DOM-dependent
tests. Add a lightweight obsidian module mock and initial test suites for
Google Keep (20 tests), Apple Journal (20 tests), and shared utilities
(15 tests) -- 55 tests total.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant