Skip to content

test: add Vitest with first unit suites (comparison, zcoords) - #388

Merged
dkastl merged 3 commits into
nextfrom
feat/vitest-setup
Jun 14, 2026
Merged

test: add Vitest with first unit suites (comparison, zcoords)#388
dkastl merged 3 commits into
nextfrom
feat/vitest-setup

Conversation

@dkastl

@dkastl dkastl commented Jun 14, 2026

Copy link
Copy Markdown
Member

Summary

First step of Phase 4: the plugin had zero JS tests. This sets up Vitest and adds suites for the two helpers whose behavior was subtlest (and which had real bugs during the v7 refactor), so their contracts are locked down.

  • Vitest (vitest@4, supports Vite 8), node environment — the covered modules are pure logic, so no jsdom/happy-dom needed. Standalone vitest.config.ts; tests co-located as src/**/*.test.ts.
  • helpers/comparison.test.ts — the operator lookup table + operand parsing that replaced the old Function() evaluator: loose "200" == 200, single-quoted strings staying strings, JS numeric forms JSON rejects (+1, .5, 0x10), boolean/undefined literals, bare-string operands (which the old evaluator threw ReferenceError on), operator whitespace trimming, and the unknown-operator guard.
  • openlayers/zcoords.test.ts — the recursive z-coordinate walk across Point / LineString / Polygon and the Multi* nesting that used to be missed (the bug fixed in refactor: split the openlayers module by concern; native GeoJSON upload dialog #375), plus the average-z and add-z-to-2D behaviors.

CI

A dedicated frontend job runs pnpm typecheck + pnpm test once (Node 22, pnpm via corepack). The matrix Prepare Plugin step now only runs pnpm install + pnpm build (the assets the Ruby tests need) — typecheck moved to the frontend job instead of running 9× across the matrix.

Notes

  • assets/ stays gitignored; no built output is committed.
  • Verified: pnpm test (26 tests passing), pnpm typecheck, and pnpm build all green; no test code leaks into main.js. Confirmed a clean --frozen-lockfile install pulls the needed rolldown binary (Vite 8's engine; the lockfile carries the linux-x64 bindings) and pnpm reports no ignored build scripts.

The plugin had no JS tests. Sets up Vitest (node environment; the covered
modules are pure logic) and adds suites for the two helpers with the
subtlest behavior, locking down the contracts that broke before:

- helpers/comparison.ts: operator table + operand parsing that replaced the
  Function() evaluator (loose '200'==200, single-quoted strings, JS numeric
  forms, boolean/undefined literals, bare-string operands, unknown-operator
  guard).
- openlayers/zcoords.ts: recursive z-coordinate walk across Point/Line/
  Polygon and the Multi* nesting that used to be missed.

CI: a dedicated 'frontend' job runs typecheck + unit tests once (Node 22,
pnpm); the matrix 'Prepare Plugin' step now only builds the assets the Ruby
tests need (typecheck moved to the frontend job to avoid running it 9x).

Tests co-located as src/**/*.test.ts; assets/ stays gitignored. 26 tests.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a first JavaScript unit-testing setup for the plugin’s framework-agnostic TypeScript logic by adding Vitest and initial suites for two previously subtle helpers (comparison parsing/evaluation and OpenLayers z-coordinate traversal/preservation). It also updates CI to run frontend typechecking + unit tests once in a dedicated job, reducing redundant work across the Ruby/PostGIS matrix.

Changes:

  • Add Vitest configuration and npm scripts (pnpm test, pnpm test:watch) to enable running unit tests in a Node environment.
  • Add initial unit test suites for helpers/comparison and openlayers/zcoords.
  • Update GitHub Actions workflow to introduce a dedicated frontend job and remove repeated frontend checks from the matrix job.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
vitest.config.ts Adds Vitest configuration targeting Node and src/**/*.test.ts.
src/components/gtt-client/openlayers/zcoords.test.ts Adds unit tests for z-coordinate reading/writing across nested coordinate structures.
src/components/gtt-client/helpers/comparison.test.ts Adds unit tests covering operator handling and operand parsing semantics.
package.json Replaces placeholder test script with Vitest run/watch scripts and adds Vitest devDependency.
pnpm-lock.yaml Locks Vitest and its transitive dependencies.
.github/workflows/test-postgis.yml Adds a dedicated frontend CI job and removes repeated typecheck from the matrix job’s prepare step.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/test-postgis.yml
dkastl added 2 commits June 14, 2026 23:18
Node 22 was the carried-over pin; bump both Node usages in test-postgis.yml
(the frontend job's setup-node, and the matrix NodeSource install) to 24,
the current LTS. Independent of #387, which bumped the action runtime.
The matrix job pinned ubuntu-22.04 while the frontend job already used
ubuntu-latest; align both. The job runs inside a ruby:*-bullseye container,
so the runner image only hosts the container and service DB.
@dkastl
dkastl merged commit b16fe28 into next Jun 14, 2026
19 of 20 checks passed
@dkastl
dkastl deleted the feat/vitest-setup branch June 14, 2026 14:29
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.

2 participants