Skip to content

Expand filters.js coverage + fix nearestPoint ESM regression - #5

Open
RichardLitt wants to merge 1 commit into
tests-appears-during-expected-datesfrom
tests-filters
Open

Expand filters.js coverage + fix nearestPoint ESM regression#5
RichardLitt wants to merge 1 commit into
tests-appears-during-expected-datesfrom
tests-filters

Conversation

@RichardLitt

Copy link
Copy Markdown
Owner

Summary

Stacks on #4. Brings project test count from 98 to 154 (+56 tests). Covers every previously-untested export in filters.js and extends the existing coverage:

New coverage

Function Tests Notes
orderByDate 5 both YYYY-MM-DD and MM/DD/YYYY date formats
durationFilter 6 inclusive boundary, string vs number values
createPeriodArray 6 spuhs excluded from SpeciesTotal
removeSpuh 13 trinomial truncation, Subspecies marking, reverse-mode (kept-everything) semantics, reference-based dedup
removeSpuhFromCounties 3 uses bundled CountyBarcharts
pointLookup 5 town + region resolution, also accepts GeoJSON Point shape
getPoint 4 UPPERCASE keys, nearest-in-county fallback
getTownCentroids 6 regression test for the West Haven turf.center fix

Extended existing coverage

  • dateFilter +3 (number vs string year, strict isAfter, zero-match)
  • completeChecklistFilter +4 (noIncidental drops Incidental + Historical)
  • locationFilter +3 (populates Country, Region, discards no-Latitude records)

Production fix included

filters.js:89 was calling nearestPoint.default(...), which worked under CommonJS (the interop wrapper exposed .default on the module export) but threw default is not a function in ESM. Changed to nearestPoint(...) — the ESM default import IS the function.

This is a real ESM-migration regression caught by the new getPoint fallback test. Without this fix, locationFilter (which uses getPoint for points on rivers / borders) would silently log errors and miss those checklists.

Test plan

  • npm test — 154 pass + 2 todo, 0 fail
  • All new tests verified against actual behavior (probed module before writing assertions)

Stack

Base: tests-appears-during-expected-dates (#4). GitHub auto-retargets up the stack as PRs merge.

Adds ~50 tests to filters.test.js, bringing the total project test
count from 98 to 154. Covers every previously-untested export:

- orderByDate (5 tests): ascending sort, stable order, both
  YYYY-MM-DD and MM/DD/YYYY input formats
- durationFilter (6 tests): inclusive boundary, opts.duration
  optional, string/number duration values
- createPeriodArray (6 tests): per-period grouping, descending
  SpeciesTotal sort, spuhs excluded from the count
- removeSpuh (13 tests): clean species, sp./hybrid/Domestic
  filtering, trinomial truncation + Subspecies recording, reverse
  mode (kept-everything semantics), reference-based dedup
- removeSpuhFromCounties (3 tests): county-keyed, non-empty per
  county, no spuh markers in output
- pointLookup (5 tests): Burlington/Montpelier resolution,
  out-of-state returns undefined, accepts both {Latitude,Longitude}
  and GeoJSON Point shapes, also works for biophysical regions
- getPoint (4 tests): point inside, UPPERCASE LATITUDE/LONGITUDE
  keys, nearest-in-county fallback for offshore points
- getTownCentroids (6 tests): 255 features for all VT towns,
  single feature for a named town, West Haven centroid lands in
  VT (regression test for the centerOfMass -> turf.center fix),
  Point geometry type, undefined for unknown town

Also extends existing coverage:
- dateFilter (+3): number vs string year, strict after boundary,
  zero-match returns empty
- completeChecklistFilter (+4): noIncidental drops Incidental /
  Historical, accepts both 1 and "1" for All Obs Reported
- locationFilter (+3): populates Country, populates Region,
  discards no-Latitude records

Production fix: filters.js:89 was calling nearestPoint.default(...)
which worked when @turf/nearest-point was loaded via CommonJS
(.default exposed by the CJS interop wrapper) but threw "default
is not a function" in ESM. Changed to nearestPoint(...) -- the
ESM default import IS the function. The getPoint fallback (for
points on rivers / borders) was effectively broken on the
esm-migration branch until this fix; the new test for that
fallback path would have surfaced the regression.
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