happy-dom

happy-dom: a fast JavaScript DOM implementation for running DOM tests in non-browser environments. Suited for "no-browser testing", as an alternative to jsdom, configuring test environments in Vitest or Jest, SSR testing, and scenarios comparing performance with jsdom.

Last repository push
GitHub Stars
219
Forks
38
Issues / PRs
7

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "happy-dom" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-0c7598ececebbefcd08eda946c8cbadf8efe1eeaee6c0a5be8e228840fa9a7fd. Verify the upstream source and version against https://github.com/TerminalSkills/skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

happy-dom: a fast JavaScript DOM implementation for running DOM tests in non-browser environments. Suited for "no-browser testing", as an alternative to jsdom, configuring test environments in Vitest or Jest, SSR testing, and scenarios comparing performance with jsdom.

0 Downloads

Introduction source: third_party · TerminalSkills · 1.0.0 Reference

SkillPi interpretation

Audience
Test environment for React/Vue/Svelte component tests (faster than jsdom) Vitest setup — Happy DOM is the recommended environment Server-side HTML generation or manipulation Parsing and extracting data from HTML strings Email template rendering on the server
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: happy-dom
description: >-
  Run DOM tests without a browser using Happy DOM — fast JavaScript DOM
  implementation. Use when someone asks to "test without a browser", "Happy DOM",
  "fast DOM environment for tests", "replace jsdom", "Vitest DOM environment",
  or "server-side DOM". Covers test environment setup, Vitest/Jest integration,
  SSR testing, and performance comparison with jsdom.
license: Apache-2.0
compatibility: "Node.js 18+. Vitest, Jest, or standalone."
metadata:
  author: terminal-skills
  version: "1.0.0"
  category: development
  tags: ["testing", "dom", "happy-dom", "jsdom", "vitest"]

Happy DOM

Overview

Happy DOM is a JavaScript DOM implementation for Node.js — 3-10x faster than jsdom. It provides window, document, HTMLElement, and 1000+ Web APIs without launching a browser. Use it as the test environment for Vitest or Jest when testing UI components, or for server-side DOM manipulation (email templates, HTML generation, scraping).

When to Use

  • Test environment for React/Vue/Svelte component tests (faster than jsdom)
  • Vitest setup — Happy DOM is the recommended environment
  • Server-side HTML generation or manipulation
  • Parsing and extracting data from HTML strings
  • Email template rendering on the server

Instructions

Vitest Integration

npm install -D happy-dom
// vitest.config.ts — Use Happy DOM for all tests
import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    environment: "happy-dom",
  },
});

That's it — all tests now run with Happy DOM providing DOM APIs.

Per-File Environment

// tests/component.test.ts — Override environment for specific tests
// @vitest-environment happy-dom

import { render, screen } from "@testing-library/react";

test("renders heading", () => {
  render(<h1>Hello</h1>);
  expect(screen.getByRole("heading")).toHaveTextContent("Hello");
});

Jest Integration

// jest.config.js
module.exports = {
  testEnvironment: "@happy-dom/jest-environment",
};

Standalone Usage

// render.ts — Server-side DOM manipulation
import { Window } from "happy-dom";

const window = new Window({ url: "https://localhost:3000" });
const document = window.document;

// Parse HTML
document.body.innerHTML = `
  <div class="container">
    <h1>Hello World</h1>
    <ul id="items">
      <li>Item 1</li>
      <li>Item 2</li>
    </ul>
  </div>
`;

// Query and manipulate
const heading = document.querySelector("h1");
console.log(heading?.textContent); // "Hello World"

const items = document.querySelectorAll("#items li");
console.log(items.length); // 2

// Create elements
const newItem = document.createElement("li");
newItem.textContent = "Item 3";
document.getElementById("items")?.appendChild(newItem);

// Serialize back to HTML
console.log(document.body.innerHTML);

// Clean up
await window.happyDOM.close();

Email Template Rendering

// email.ts — Render email templates server-side
import { Window } from "happy-dom";

function renderEmailTemplate(template: string, data: Record<string, string>): string {
  const window = new Window();
  const document = window.document;

  document.body.innerHTML = template;

  // Replace placeholders
  for (const [key, value] of Object.entries(data)) {
    const elements = document.querySelectorAll(`[data-field="${key}"]`);
    elements.forEach((el) => { el.textContent = value; });
  }

  const html = document.body.innerHTML;
  window.happyDOM.close();
  return html;
}

Examples

Example 1: Speed up Vitest test suite

User prompt: "Our Vitest tests using jsdom take 45 seconds. Make them faster."

The agent will switch the test environment to Happy DOM (one config change), verify all tests still pass, and benchmark the improvement (typically 3-5x faster).

Example 2: Parse and extract data from HTML

User prompt: "Parse HTML pages and extract structured data without a browser."

The agent will use Happy DOM to parse HTML strings, query elements with CSS selectors, and return structured data.

Guidelines

  • One config line for Vitest — environment: "happy-dom" in vitest.config.ts
  • 3-10x faster than jsdom — measurable improvement on large test suites
  • 1000+ Web APIs — fetch, FormData, URL, MutationObserver, IntersectionObserver
  • Not 100% browser-identical — some edge cases differ; test critical paths in a real browser
  • window.happyDOM.close() — clean up resources in standalone usage
  • Works with Testing Library — @testing-library/react works unchanged
  • Lighter than jsdom — less memory, faster startup
  • SSR testing — render components server-side and assert on HTML output
  • Per-file override — // @vitest-environment happy-dom for specific tests

Current listing version

1.0.0

Verify the source revision ↗

Safety and assessment details

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value92/100

Highlights

  • Happy DOM 提供 3-10x 比 jsdom 更快的 DOM 测试性能
  • 覆盖 Vitest/Jest 集成、SSR 测试、服务端 DOM 操作等高频刚需场景
  • 包含完整的端到端示例和实际应用场景说明
Trigger Precision90/100

Highlights

  • 触发词覆盖全面:'无浏览器测试'、'Happy DOM'、'测试用的快速 DOM 环境'等
  • 边界清晰,无明显歧义或重叠
Structure and Standards95/100

Highlights

  • 结构清晰:Vitest/Jest 集成、独立使用、邮件模板渲染等模块分明
  • frontmatter 完整,包含兼容性、许可证、元数据等信息
  • 提供完整的端到端示例和使用指南
Execution Reliability90/100

Highlights

  • 工具来源明确,配置参数正确
  • 包含资源清理机制(window.happyDOM.close())
  • 覆盖主要异常场景和最佳实践
Evidence Verifiability (mean of the first four)92/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

  • Install or fetch external dependencies

    Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.

    Mentioned in main document · lines 37
Domains or addresses referenced in the document

These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.

  • localhost

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.