@monochromatic-dev/module-test-diagnostic #
Test-failure formatting, assertion-source inspection, and shared harness-frame classification. The module-test runner still re-exports the existing diagnostic functions.
Responsibilities #
formatErrorDeeprenders error chains and aggregate members while filtering harness frames.formatFailurecombines a verdict summary with the formatted error.readAssertionSitesenriches failures with readable assertion source when available.extractAssertionExpression,extractLocationSubstring, andisIntegerStringsupport source extraction.
This is test-oriented formatting,
not a generic replacement for module-caught-value.
Workspace-prefix discovery and source reads stay behind the existing Node runtime checks.
The neutral artifact can be imported without Node filesystem access.
Use #
// consumer.ts
import { formatFailure, } from '@monochromatic-dev/module-test-diagnostic/ts';
const diagnostic = await formatFailure({
summary: 'test failed',
value: new Error('unexpected value',),
},);
Workspace consumers use /ts.
The root entry selects the Node artifact under Node and the neutral artifact otherwise.
This preserves filesystem-backed workspace-root discovery for Node consumers,
while keeping browser imports free of Node filesystem initialization.
Verification #
# From the repository root.
mise run //package/module/test-diagnostic:buildAndTest
mise run //package/module/test-diagnostic:lint
Example and property tests exercise the built diagnostic artifact.
Frame tests cover runner and extracted-package source paths,
built paths,
and preservation of actual test frames.
fast-check is a development dependency only.