Skip to content

Testing

dweller long gone edited this page May 21, 2026 · 1 revision

Testing

PkiStudioJS uses npm test to protect the public Core API, viewer package contract, OID resolver behavior, and important documentation promises.

Run the test suite from the main repository:

npm test

The command runs Node.js tests under test/*.test.js. The main test file is test/core-api.test.js.

What npm test Covers

Core API Contracts

The tests verify that the Core API can parse and serialize a minimal DER document:

SEQUENCE { INTEGER 1 }

They also verify that parsed nodes can be re-encoded and that getNodeBytes(nodes, nodeId) returns the DER bytes for a selected node subtree.

Input Format Handling

The tests cover automatic detection and decoding for common text inputs:

  • HEX text such as 3003020101.
  • PEM text with BEGIN and END markers.

These checks help preserve the behavior used by both the browser viewer and the reusable Core API.

OID Resolution

The tests verify two OID lookup paths:

  • Supplying an oidNames object directly to Core serializers.
  • Supplying an oidResolver created by @pkistudio/pkistudiojs/oid-resolver.

They also check that custom resolver entries can override bundled OID names and that unresolved OIDs return an empty string.

Version Metadata

The tests verify that public version metadata stays synchronized across:

  • package.json
  • app/static/pkistudio-core.js
  • app/static/pkistudio.js
  • README.md

This helps prevent releases where the package version, viewer version, Core API version, and documentation disagree.

Viewer Package Contract

The tests verify that @pkistudio/pkistudiojs/viewer can be imported in a Node-like module evaluation context. This protects the package contract that importing the viewer is safe even though init() still requires a browser DOM.

The tests also verify viewer exports such as:

  • version
  • core
  • init
  • autoInit

Editable Mode Documentation

The tests check that editable viewer mode is implemented and documented. This includes the editable: false initialization option and the setEditable(false) / setEditable(true) runtime control.

DER Inspector Documentation

The tests check that DER inspector tag editing behavior is implemented and documented. This includes identifier class and tag index editing, validation against the selected universal tag, and error display behavior.

New-Window Behavior

The tests verify that selected-node new-window actions use the configured newWindowUrl when supplied.

Disabled Document Actions

The tests verify that document actions such as save, close, expand all, and collapse all are disabled until data is loaded.

Browser DOM Requirement

The tests verify that calling viewer.init() without a browser DOM throws a clear error message.

What npm test Does Not Cover

npm test is focused on API contracts and important source/documentation alignment. It does not replace full browser verification.

It does not currently cover:

  • Full browser UI interaction flows.
  • Visual regression checks.
  • Cross-browser behavior.
  • Large real-world certificate corpora.
  • Drag-and-drop behavior.
  • Clipboard permission behavior across browsers.
  • Package tarball contents.
  • GitHub release or npm publish workflows.

Use browser verification when changing user-facing viewer behavior, dialogs, menus, editing flows, drag-and-drop, or clipboard behavior.

Related Checks

Run syntax checks with:

npm run check

For package or release-related changes, also run:

npm pack --dry-run

Use the local static server when browser verification is needed:

node app/server.js

Then open:

http://localhost:8080/

How to Update This Page

Update this page when tests add or remove public API guarantees, documentation contract checks, package export checks, or important viewer behavior checks.

Clone this wiki locally