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

@longzai-intelligence/testing-utils

v0.0.1

Published

统一的测试工具库,提供异步工具、DI 容器辅助、测试数据工厂、Mock 工具等通用能力。

Downloads

69

Readme

@longzai-intelligence/testing-utils

统一的测试工具库,提供异步工具、DI 容器辅助、测试数据工厂、Mock 工具等通用能力。

安装

bun add @longzai-intelligence/testing-utils

入口说明

本包提供两个导出入口

| 入口 | 导入路径 | 说明 | |------|----------|------| | 主入口 | @longzai-intelligence/testing-utils | 框架无关的通用测试工具,零 Vitest 依赖 | | Vitest 子入口 | @longzai-intelligence/testing-utils/vitest | 依赖 Vitest 运行时的专用工具(需传入 vi) |

快速开始

主入口使用

import {
  waitFor,
  withTimeout,
  createTestContainer,
  registerMock,
  registerSingleton,
  registerTransient,
  resolve,
  tryResolve,
  isRegistered,
  clearContainer,
  snapshotContainer,
  restoreContainer,
  createMany,
  randomString,
  randomInt,
  createSpy,
  captureConsole,
  createSilentConsole,
  withEnv,
  tryCatch,
  setupChromeMock,
  getChromeMock,
  createMockEventPublisher,
} from '@longzai-intelligence/testing-utils';

Vitest 子入口使用

import { vi } from 'vitest';
import {
  createSpyConsole,
  setupTestEnvironment,
  type VitestSpyAPI,
  type SpyConsoleResult,
  type TestEnvironmentOptions,
  type TestEnvironmentResult,
  type ConsoleMockMode,
} from '@longzai-intelligence/testing-utils/vitest';

// 创建控制台 Spy(追踪调用记录)
const spy = createSpyConsole(vi);
spy.enable();
console.log('test');
expect(spy.spies.log).toHaveBeenCalledWith('test');
spy.disable();

// 统一配置测试环境
setupTestEnvironment(vi, { console: 'silent' });

功能模块

异步工具

  • waitFor - 等待条件满足
  • withTimeout - Promise 超时包装器

DI 容器工具

  • createTestContainer - 创建独立子容器
  • registerMock - 注册 Mock 服务
  • registerSingleton - 注册单例服务
  • registerTransient - 注册瞬态服务
  • resolve - 从容器获取服务
  • tryResolve - 尝试从容器获取服务
  • isRegistered - 检查服务是否已注册
  • clearContainer - 清理容器注册
  • snapshotContainer - 创建容器快照
  • restoreContainer - 恢复容器快照

测试数据工厂

  • createMany - 批量创建数据(支持逐条覆盖)
  • randomString - 生成随机字符串
  • randomInt - 生成随机整数

辅助工具

  • createSpy - 函数 Spy 包装器
  • captureConsole - 捕获 console 输出
  • createSilentConsole - 静默 console
  • withEnv - 临时环境变量设置
  • tryCatch - 异步错误捕获
  • setupChromeMock - 设置 Chrome API Mock
  • getChromeMock - 获取 Chrome Mock 对象

Mock 工具

  • createMockEventPublisher - 领域事件发布者 Mock

Vitest 专用工具 (./vitest)

  • createSpyConsole(vi) - Vitest 控制台 Spy(工厂模式)
  • setupTestEnvironment(vi, options) - 统一测试环境配置

开发

# 运行测试
bun run test

# Lint 检查
bun run lint:fix

# 类型检查
bun run typecheck

# 构建
bun run build

# 清理构建产物
bun run clean