test: add Vitest with first unit suites (comparison, zcoords) - #388
Merged
Conversation
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.
There was a problem hiding this comment.
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/comparisonandopenlayers/zcoords. - Update GitHub Actions workflow to introduce a dedicated
frontendjob 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.
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.
This was referenced Jun 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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@4, supports Vite 8),nodeenvironment — the covered modules are pure logic, so no jsdom/happy-dom needed. Standalonevitest.config.ts; tests co-located assrc/**/*.test.ts.helpers/comparison.test.ts— the operator lookup table + operand parsing that replaced the oldFunction()evaluator: loose"200" == 200, single-quoted strings staying strings, JS numeric forms JSON rejects (+1,.5,0x10), boolean/undefinedliterals, bare-string operands (which the old evaluator threwReferenceErroron), 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
frontendjob runspnpm typecheck+pnpm testonce (Node 22, pnpm via corepack). The matrixPrepare Pluginstep now only runspnpm install+pnpm build(the assets the Ruby tests need) — typecheck moved to thefrontendjob instead of running 9× across the matrix.Notes
assets/stays gitignored; no built output is committed.pnpm test(26 tests passing),pnpm typecheck, andpnpm buildall green; no test code leaks intomain.js. Confirmed a clean--frozen-lockfileinstall pulls the needed rolldown binary (Vite 8's engine; the lockfile carries the linux-x64 bindings) and pnpm reports no ignored build scripts.