From 9b6c7ca598b21d0f3b26ccf4b1ccb5e1151737ef Mon Sep 17 00:00:00 2001 From: Buddy Date: Sat, 22 Aug 2026 12:45:00 -0700 Subject: [PATCH] test: add a Vitest + jsdom test suite No test coverage existed before this. Adds vitest + jsdom (2 new devDependencies) and a suite that runs entirely without a browser: real Leaflet objects work fine under jsdom for everything this library needs to verify (option/attribute wiring, event forwarding), given a ResizeObserver stub in test/setup.ts (jsdom's only real gap here). - test/core/with-props.test.ts: the WithProps mixin itself, against a fake Leaflet-like class -- attribute<->setter dispatch, get/attribute/default fallback order, event-driven attribute sync-back, positional/recreate/ attach modes, and the generic fire()-patch event forwarding. Child registration (popup/tooltip/layer binding) uses real Popup/Tooltip/Marker instances since #onChildRegister discriminates by instanceof. - test/core/props.test.ts: the codec functions in isolation. - test/components/*.test.ts: grouped smoke tests across all components. - test/integration.test.ts: full tree wiring (map + tile-layer + feature-group + marker + popup). Caught and fixed one real bug along the way: urlProp's "live url getter" from the last refactor was dead code -- neither ImageOverlay nor VideoOverlay actually expose getUrl(). Removed it and the now-pointless getUrl?() from the Sourced interface in shared-props.ts. tsconfig.test.json keeps test/ out of the tsc build (dist/ stays test-free) while still typechecking it; oxlint.config.ts now covers test/ too, with max-classes-per-file relaxed there since testing a class factory means many small one-off element classes. Co-Authored-By: Claude Sonnet 5 --- CLAUDE.md | 17 +- oxlint.config.ts | 11 + package-lock.json | 2170 +++++++++++++++++-- package.json | 12 +- src/core/shared-props.ts | 5 +- test/components/controls-and-groups.test.ts | 101 + test/components/geojson.test.ts | 56 + test/components/icons.test.ts | 62 + test/components/latlng-bindables.test.ts | 126 ++ test/components/overlays.test.ts | 100 + test/components/shapes.test.ts | 147 ++ test/components/tile-layers.test.ts | 68 + test/core/props.test.ts | 112 + test/core/with-props.test.ts | 481 ++++ test/integration.test.ts | 84 + test/setup.ts | 10 + tsconfig.test.json | 10 + vitest.config.ts | 9 + 18 files changed, 3353 insertions(+), 228 deletions(-) create mode 100644 test/components/controls-and-groups.test.ts create mode 100644 test/components/geojson.test.ts create mode 100644 test/components/icons.test.ts create mode 100644 test/components/latlng-bindables.test.ts create mode 100644 test/components/overlays.test.ts create mode 100644 test/components/shapes.test.ts create mode 100644 test/components/tile-layers.test.ts create mode 100644 test/core/props.test.ts create mode 100644 test/core/with-props.test.ts create mode 100644 test/integration.test.ts create mode 100644 test/setup.ts create mode 100644 tsconfig.test.json create mode 100644 vitest.config.ts diff --git a/CLAUDE.md b/CLAUDE.md index 569e3fa..d0a39fe 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -6,14 +6,25 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co ```bash npm run build # tsc emits individual ESM modules to dist/ (no bundling) -npm run typecheck # tsc --noEmit -npm run lint # oxlint over src/ +npm run typecheck # tsc --noEmit, then tsc -p tsconfig.test.json for test/ +npm run lint # oxlint over src/ and test/ npm run format # Prettier formatting +npm run test # vitest run +npm run test:watch # vitest, watch mode ``` Linting runs on `oxlint`, not ESLint/`@typescript-eslint`. This project pins `typescript@^7.0.2`, and `@typescript-eslint` has no released version that supports it (peer range caps at `<6.1.0`, and even loading `@typescript-eslint/parser` crashes against TS 7's package shape). `oxlint` has its own parser and doesn't touch the `typescript` package, so it works regardless of TS version — the tradeoff is no type-aware rules (no `no-floating-promises`, `no-unnecessary-condition`, etc.). Revisit once `@typescript-eslint` supports TS 7. -There are no tests in this project. To preview components locally, open `index.html` in a browser with any static-file server. +### Testing + +Tests run under Vitest + jsdom (`test/**/*.test.ts`), with a single setup file (`test/setup.ts`) that stubs `ResizeObserver` -- jsdom doesn't implement it, and `leaflet-map.ts` constructs one unconditionally. Real Leaflet objects work fine under jsdom for everything this library actually needs to verify (option/attribute wiring, event forwarding); no browser is required. Two things worth knowing: + +- Some Leaflet DOM state (the ``/`