@hyperfrontend/testing§

A Jest-style spec, cart.spec.ts, types itself onto a sheet line by line, each call opening with its package chip; as each line lands a wire draws across to the Node primitive it rests on, describe and it to node:test, expect to node:assert with a count rising to 2, jest.mock to module.registerHooks and jest.useFakeTimers to mock.timers, each label lighting as its wire arrives; the verdict returns along the test's wire as a green check, the runner's coverage figure counts up to line 100.00, branch 95.65 and funcs 100.00, and a tick lands beside itA Jest-style spec, cart.spec.ts, types itself onto a sheet line by line, each call opening with its package chip; as each line lands a wire draws across to the Node primitive it rests on, describe and it to node:test, expect to node:assert with a count rising to 2, jest.mock to module.registerHooks and jest.useFakeTimers to mock.timers, each label lighting as its wire arrives; the verdict returns along the test's wire as a green check, the runner's coverage figure counts up to line 100.00, branch 95.65 and funcs 100.00, and a tick lands beside it

A lightweight Jest-like testing library built on native Node capabilities.

What is @hyperfrontend/testing?

@hyperfrontend/testing lets you write tests the way you would for Jest and run them on Node's built-in test runner. It adds only what Node lacks and leaves the rest to Node.

It is not Jest, which remains the fuller tool. It is for projects where Node's built-ins are enough and the familiar syntax is worth keeping.

Key Features

  • The Jest syntax you know

    Describe blocks, matchers, mock functions and spies read the way a Jest suite already does

  • Module mocks without a transpiler

    Factories, partial mocks and automocks apply under native ES modules before a spec's imports link

  • Fake timers on Node's clock

    Advance time, drain pending timers and set the system time from inside a test

  • A coverage gate you can trust

    A source file no test loaded fails the run instead of quietly vanishing from the report

  • Optional DOM

    One preload gives browser-facing suites a jsdom window; suites that do not need it never install it

  • TypeScript specs as written

    Node's own type stripping runs them, with extensionless imports and tsconfig path aliases resolved

  • The helpers suites keep rewriting

    Typed object mocks, condition waits, self-cleaning temporary directories, linked windows, and stand-ins for a terminal, the standard streams and child processes

Why Use @hyperfrontend/testing?

Fewer dependencies, same habits

Node already ships a test runner, assertions, module mocking, fake timers and coverage. This package adds the shape of a Jest spec on top: one dev dependency instead of a framework, a transformer and a reporter, with nothing but Node built-ins at runtime.

A migration, not a rewrite

Jest suites keep their describe blocks, matchers and module mocks as written. Migrate a Jest suite to Node's test runner lists what does change.

Installation

npm install --save-dev @hyperfrontend/testing

Add jsdom as well only if a suite needs a DOM.

Quick Start

import { beforeEach } from 'node:test'
import { describe, expect, it, jest } from '@hyperfrontend/testing'
import { createCart } from './cart'

jest.mock('./pricing', () => ({ priceOf: () => 3 }))

describe('cart', () => {
  let cart: ReturnType<typeof createCart>

  beforeEach(() => {
    cart = createCart()
  })

  it('totals the priced lines', () => {
    cart.add('tea', 2)
    expect(cart.total()).toBe(6)
  })

  it('notifies subscribers once per change', () => {
    const onChange = jest.fn()
    cart.subscribe(onChange)
    cart.add('tea', 1)
    expect(onChange).toHaveBeenCalledTimes(1)
  })
})
node --import @hyperfrontend/testing/hooks --test 'src/**/*.spec.ts'

Lifecycle hooks come straight from node:test. The /hooks preload lets the spec load as TypeScript with its module mock in place.

For several environments, setup files and a coverage gate, declare a test.config.ts and run it with runProjectTests. Configure and run TypeScript tests on Node's test runner walks through a full setup.

API Overview

EntryWhat it is
@hyperfrontend/testingWhat a spec imports
/hooksThe node --import preload: TypeScript resolution and mocks
/domThe preload that puts a jsdom window on the global
/browserLinked windows for cross-origin messaging, a driven ResizeObserver
/consumerA packed package installed and run the way a consumer runs it
/fsTemporary directories and fixture trees written from data
/processTerminal, standard stream and child process stand-ins, npm on Windows
/runnerThe config-driven runner, one node --test per environment
/coverageThe lcov merge and the threshold gate
/reporterNode's spec reporter without the per-evaluation coverage noise

Every matcher, option and signature is in the API reference.

Limitations

  • No snapshots, custom matchers or watch mode. A suite that depends on them should stay on Jest.
  • Coverage is V8 through Node's collector: no statements metric and no HTML report.

The full list is in Where behaviour differs from Jest.

Compatibility

Runs on

  • Node.js>=22.18.0supported
  • Browsersnot supported
  • Web Workersnot supported
  • Linuxsupported
  • macOSsupported
  • Windowssupported

Needs Node.js 22.18 or later: the preload installs synchronous module hooks and loads TypeScript specs through Node's own type stripping, neither of which older releases provide.

Ships as

  • ESMTree-shakeable
  • CJSNode and older bundlers

Peer Dependencies

PackageVersionType
jsdom>= 26.0.0Optional

Architecture Highlights§

Nothing is injected into the global scope: a spec imports what it uses. The architecture guide covers the preload, the mock registry and the coverage pipeline.

API Reference§

View:
Organized by entry point

Module Structure

|

10 modules · 119 total exports

Jest-style `describe`, `it`, `expect` and `jest` on Node's built-in test runner: the surface a spec imports.

8 fn25 type4 var

Stand-ins for the browser surfaces a DOM-free test cannot supply: linked windows that message each other, and a `ResizeObserver` the test drives.

3 fn1 int5 type

A packed package installed outside the workspace and driven through plain Node child processes, for testing what a consumer installs rather than what the workspace resolves.

2 fn6 type

The coverage side of a run: lcov reports merged per file, the threshold gate, the per-file table, and the completeness check for source files no test loaded.

9 fn4 type

The preload that gives a suite a browser-shaped global: a jsdom window copied onto `globalThis` before the suite's own setup modules run.

1 fn

Temporary directories that clean up after themselves, and fixture trees written into them from data a spec declares.

4 fn1 int4 type

The preload that makes a Jest-style spec loadable by Node's test runner: path aliases, extensionless specifiers, `moduleNameMapper` redirects and `jest.mock` replacements.

1 fn

Stand-ins for a process's terminal, standard streams and child processes, for testing command-line tools and interactive prompts, and a Windows-safe way to start npm.

10 fn6 int7 type1 var

The reporter a run names with `--test-reporter`: Node's own spec reporter, with the per-evaluation coverage summary held back so the merged table the runner prints is the only verdict a run shows.

1 fn

The runner behind a project's `test.config.ts`: one `node --test` run per environment, then the merged coverage report, the threshold gate and the completeness check.

9 fn6 type1 var

Browse guides filtered to this packageSuggest a guide