Skip to content

feat: extract shared DOM/testing core to @pokujs/dom + benchmark suite#14

Merged
Lojhan merged 10 commits intomainfrom
feat/dom-adapter-and-benchmark-improvements
Apr 5, 2026
Merged

feat: extract shared DOM/testing core to @pokujs/dom + benchmark suite#14
Lojhan merged 10 commits intomainfrom
feat/dom-adapter-and-benchmark-improvements

Conversation

@Lojhan
Copy link
Copy Markdown
Collaborator

@Lojhan Lojhan commented Apr 5, 2026

Summary

This PR extracts the shared DOM and testing infrastructure from @pokujs/react into the new @pokujs/dom package, and introduces a full benchmark suite comparing Poku against Jest and Vitest.


Changes

Source — extract to @pokujs/dom

All modules that were duplicated across @pokujs/react and the upcoming @pokujs/vue have been moved to @pokujs/dom:

File Before After
src/plugin-setup.ts full TSX loader + DOM env setup (~62 lines) export { setupInProcessEnvironment } from '@pokujs/dom'
src/plugin-metrics.ts full metrics emitter implementation (~150 lines) re-export from @pokujs/dom
src/plugin-command.ts runtime detection + arg handling (~130 lines) re-export from @pokujs/dom
src/plugin-types.ts type definitions (~70 lines) re-export from @pokujs/dom
src/plugin.ts full plugin factory (~110 lines) re-export from @pokujs/dom
src/dom-setup-happy.ts happy-dom env setup (~38 lines) re-export from @pokujs/dom
src/dom-setup-jsdom.ts jsdom env setup (~56 lines) re-export from @pokujs/dom
src/runtime-options.ts options parsing (~80 lines) re-export from @pokujs/dom
src/react-testing.ts getNow, metrics state, screen proxy inline imports createRenderMetricsEmitter, createScreen, getNow from @pokujs/dom

Net: −815 lines / +111 lines in src/.

Dependency

  "dependencies": {
+   "@pokujs/dom": "^0.1.0",
    "@testing-library/dom": "^10.4.1"
  }

Benchmark suite (benchmark/)

New benchmark comparing five scenarios across 7 runs (trim ±1):

Scenario Median
poku + happy-dom 0.125 s
poku + jsdom 0.362 s
jest + jsdom 1.048 s
vitest + jsdom 1.352 s
vitest + happy-dom 1.356 s

Timing methodology — Happy DOM teardown skew:

When measuring Poku scenarios with /usr/bin/time wall-clock, Happy DOM's GlobalRegistrator.register() overwrites Node globals and keeps async task queues open after tests finish, inflating the wall-clock reading by ~3 s while Poku's own suite timer correctly reports ~0.1 s.

Fix: parse Poku's reported Duration › Xms from stdout (ANSI-stripped) for Poku scenarios instead of using the outer performance.now() wrap. Jest and Vitest scenarios continue using wall-clock timing.

// In runOnce():
const plainStdout = (result.stdout ?? '').replace(/\x1b\[[0-9;]*m/g, '');
const reportedDurationMatch = plainStdout.match(/Duration\s+\s+([\d.]+)ms/);
const reportedDurationMs = reportedDurationMatch ? Number(reportedDurationMatch[1]) : null;

// Poku scenarios pass:
options: { useReportedDuration: true }

Testing

  • npm run check passes (typecheck + all tests)
  • Benchmark validated with BENCH_RUNS=3 and full BENCH_RUNS=7 run
  • No behaviour changes to the React testing API

Lojhan added 10 commits April 5, 2026 12:42
…uite with teardown-skew fix

- Move shared infrastructure (screen proxy, metrics emitter, getNow, DOM env\n  setup, plugin internals) to @pokujs/dom dependency\n- All src/ modules now re-export from @pokujs/dom; react-specific logic retained\n- Add @pokujs/dom ^0.1.0 as a runtime dependency\n- Add full benchmark suite (Poku vs Jest vs Vitest, happy-dom & jsdom)\n- Fix benchmark happy-dom timing: parse Poku reported Duration from stdout\n  to exclude Happy DOM async-teardown overhead from wall-clock measurements\n- benchmark/results.json and benchmark/REPORT.md included with latest results
Deno with isolation:none loads all test files in the same npm:poku
process. In that context bare specifiers like @pokujs/dom are not
resolved from node_modules automatically. Adding an explicit import
map entry pointing to npm:@pokujs/dom fixes resolution for all
test files that transitively import @pokujs/dom.
@Lojhan Lojhan merged commit cc60962 into main Apr 5, 2026
10 checks passed
@Lojhan Lojhan deleted the feat/dom-adapter-and-benchmark-improvements branch April 5, 2026 21:02
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.

1 participant