Skip to content

Rewrite the test suite: Vitest, real netCDF fixtures, no built-in mocks - #72

Merged
lazarusA merged 1 commit into
mainfrom
test-update
Oct 30, 2026
Merged

lazarusA merged 1 commit into
mainfrom
test-update

Conversation

@Karinon

@Karinon Karinon commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Tackling #65 and #31. Looks scarier than it actually is.

The old tests never touched the WASM module. Both Jest and Vitest set NODE_ENV=test, and in that case the library switched to built-in mocks. So the 159 tests only ever tested the mock. This PR removes the mocks and replaces the suite with tests that run against the real WASM module and real netCDF files.

Changes

  • Jest → Vitest 5. Jest, ts-jest and cross-env are removed. The tests live in a new top-level tests/ directory, split into unit/ (no WASM needed) and wasm/ (real reads and writes). The setup compiles the WASM once per test file, so the suite runs in under a second.
  • Fixtures. Small netCDF files (~200 KB in total), generated by tests/fixtures/generate.py. They cover all numeric types, strings, chars, enums, groups, the classic format, and every supported compression: zlib, zstd, bzip2 and Blosc. szip is included as a negative case.
  • Mocks removed from netcdf4.ts, group.ts and variable.ts, along with src/test-setup.ts, which was being shipped in dist/. There are no other changes to production code.
  • Test triage. The slice, remote-read and worker-init tests were kept and ported. All mock-based tests and TEST_DOCUMENTATION.md were dropped.
  • Docs and tooling. tests/README.md is new, and README and CONTRIBUTING are updated. typecheck, lint and formatcheck now include tests/.

Known bugs

The new tests found several bugs. Each one is recorded as a test.fails test, so CI stays green and the test turns red once the bug is fixed:

  • Writing variable data fails in NETCDF4 format (stack overflow) and in classic format (missing nc_enddef), setAttr doesn't write to the file. This is due that file writing is not really implemented.
  • Files with an enum _FillValue can't be opened.
  • Char arrays lose their row boundaries.
  • isUnlimited is always false.
  • getVariableInfo doesn't reject unknown names.
  • file_format ignores the actual file format. (see file_format and disk_format report the requested format, not the file's actual format #71)

Testing

  • npm run build && npm test: 90 passed, 8 expected failures.
  • Coverage is now about 52% of src/, measured against real code instead of the mocks.

@lazarusA
lazarusA merged commit 398d373 into main Oct 30, 2026
2 checks passed
@Karinon
Karinon deleted the test-update branch November 2, 2026 08:56
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