npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@type-editor/test-builder

v0.0.3

Published

Test helper utilities for Type Editor packages

Downloads

165

Readme

@type-editor/test-builder

This largely corresponds the prosemirror-test-builder module.

Test helper utilities for Type Editor packages. This module provides builder functions for creating document nodes and marks in tests, along with JSDOM mocks for testing in Node.js environments.

Installation

npm install @type-editor/test-builder

Overview

The test-builder module simplifies the creation of document structures in tests. Instead of manually constructing nodes and fragments, you can use intuitive builder functions that mirror your document structure.

Exports

Pre-configured Builders

The module exports pre-configured builders for common node and mark types:

import { doc, p, h1, h2, h3, strong, em, code, a, ul, ol, li, blockquote, br, hr, img, pre } from '@type-editor/test-builder';

// Create a simple document
const myDoc = doc(
  h1('Hello World'),
  p('This is a ', strong('bold'), ' and ', em('italic'), ' text.'),
  ul(
    li(p('First item')),
    li(p('Second item'))
  )
);

Node Builders

| Builder | Description | |----------------------|--------------------------------| | doc | Document root node | | p | Paragraph | | h1, h2, h3 | Headings (levels 1-3) | | pre / code_block | Code block | | blockquote | Block quote | | ul | Bullet (unordered) list | | ol | Ordered list | | li | List item | | br | Hard break | | hr | Horizontal rule | | img | Image (default src: 'img.png') |

Mark Builders

| Builder | Description | |----------|----------------------------| | strong | Bold text | | em | Italic text | | code | Inline code | | a | Link (default href: 'foo') |

Position Tags

You can mark positions in your document using angle-bracket syntax for testing selections and cursors:

import { doc, p } from '@type-editor/test-builder';

const myDoc = doc(p('Hello <a>world<b>!'));
// myDoc.tag.a === position before 'world'
// myDoc.tag.b === position after 'world'

Custom Builders

Create builders for your own schema:

import { builders, type NodeBuilder, type MarkBuilder } from '@type-editor/test-builder';
import { mySchema } from './my-schema';

const b = builders(mySchema, {
  // Define aliases with default attributes
  note: { nodeType: 'note', level: 'info' },
  warning: { nodeType: 'note', level: 'warning' },
  mention: { markType: 'mention', userId: '123' }
});

const myDoc = b.doc(
  b.note('This is an info note'),
  b.warning('This is a warning')
);

Schema

The module exports a pre-configured schema with common nodes and marks:

import { schema } from '@type-editor/test-builder';

// Use the schema directly
const node = schema.nodes.paragraph.create({}, schema.text('Hello'));

It also exports the basic schema components:

import * as bSchema from '@type-editor/test-builder';

// Access prosemirror-schema-basic compatible exports
const { nodes, marks } = bSchema.bSchema;

Equality Helper

A utility function for comparing nodes:

import { eq, doc, p } from '@type-editor/test-builder';

const doc1 = doc(p('Hello'));
const doc2 = doc(p('Hello'));

eq(doc1, doc2); // true

JSDOM Mocks

For tests running in JSDOM (Node.js), the module provides mocks for DOM methods not implemented by JSDOM:

import { setupJSDOMMocks } from '@type-editor/test-builder';

describe('My Editor Tests', () => {
  setupJSDOMMocks();

  it('should handle text positioning', () => {
    // Tests that use getClientRects() or getBoundingClientRect()
    // will work with the mocked implementations
  });
});

The mocks provide minimal implementations for:

  • Range.prototype.getClientRects()
  • Range.prototype.getBoundingClientRect()
  • Element.prototype.getClientRects()

API Reference

builders(schema, names?)

Creates a set of builder functions for a given schema.

Parameters:

  • schema: The document schema to create builders for
  • names (optional): An object mapping alias names to node/mark configurations

Returns: An object with builder functions for each node and mark type in the schema, plus any aliases defined in names.

NodeBuilder

A function type for building nodes:

type NodeBuilder = (
  attrsOrFirstChild?: Attrs | ChildSpec,
  ...children: ChildSpec[]
) => Node & { tag: Tags };

MarkBuilder

A function type for building marked content:

type MarkBuilder = (
  attrsOrFirstChild?: Attrs | ChildSpec,
  ...children: ChildSpec[]
) => ChildSpec;

FlattenedNodes

Represents a sequence of nodes with optional position tags:

interface FlattenedNodes {
  flat: ReadonlyArray<Node>;
  tag?: Record<string, number>;
}

License

MIT