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 🙏

© 2025 – Pkg Stats / Ryan Hefner

synthia-test

v0.0.2

Published

Synthia Engine Test Plugin - 提供测试功能的 Synthia 插件

Downloads

11

Readme

Synthia Test Plugin

npm version License: MIT

Synthia Test Plugin 是 Synthia Engine 的测试插件,提供统一的测试运行和覆盖率报告功能。支持多种测试框架,包括 Vitest、Jest、Mocha、Cypress 和 Playwright。

✨ 特性

  • 🧪 多框架支持: 支持 Vitest、Jest、Mocha、Cypress、Playwright
  • 🔍 自动检测: 自动检测项目中安装的测试框架
  • 👀 监听模式: 支持文件变化监听和自动重新运行测试
  • 📊 覆盖率报告: 生成详细的测试覆盖率报告
  • 🚀 CI 模式: 专为持续集成优化的测试模式
  • 快速执行: 优化的测试执行性能
  • 🎯 精确配置: 灵活的配置选项支持

📦 安装

# 使用 pnpm
pnpm add -D synthia-test

# 使用 npm
npm install -D synthia-test

# 使用 yarn
yarn add -D synthia-test

🚀 快速开始

1. 在 Synthia 配置中启用插件

// synthia.config.ts
import { defineConfig } from 'synthia-cli';
import { testPlugin } from 'synthia-test';

export default defineConfig({
  plugins: [
    {
      name: 'test',
      plugin: testPlugin({
        framework: 'vitest', // 可选,会自动检测
        watch: false,
        coverage: false,
      }),
    },
  ],
});

2. 运行测试

# 运行所有测试
synthia test

# 监听模式运行测试
synthia test --watch

# 生成覆盖率报告
synthia test --coverage

# CI 模式运行测试
synthia test --ci

📋 命令选项

| 选项 | 类型 | 描述 | 默认值 | | ------------- | ------- | ------------------------------------------------------- | ------------------------------- | | --watch | boolean | 监听模式运行测试 | false | | --coverage | boolean | 生成测试覆盖率报告 | false | | --ci | boolean | CI模式运行测试 | false | | --framework | string | 指定测试框架 (vitest|jest|mocha|cypress|playwright) | auto | | --pattern | string | 文件匹配模式 | src/**/*.test.{ts,js,tsx,jsx} | | --config | string | 指定配置文件 | auto | | --ui | boolean | 启动UI界面 (仅Vitest) | false | | --headless | boolean | 无头模式运行 (仅Cypress|Playwright) | false | | --browser | string | 指定浏览器 (仅Cypress|Playwright) | chromium | | --threshold | number | 设置覆盖率阈值 | 80 |

⚙️ 配置选项

TestPluginOptions

interface TestPluginOptions {
  enabled?: boolean; // 是否启用插件
  framework?: 'vitest' | 'jest' | 'mocha' | 'cypress' | 'playwright'; // 测试框架
  watch?: boolean; // 默认监听模式
  coverage?: boolean; // 默认生成覆盖率
  ci?: boolean; // 默认CI模式
  pattern?: string; // 文件匹配模式
  config?: string; // 配置文件路径

  // Vitest 配置
  vitest?: {
    enabled?: boolean;
    config?: string;
    ui?: boolean;
  };

  // Jest 配置
  jest?: {
    enabled?: boolean;
    config?: string;
    watchAll?: boolean;
  };

  // Mocha 配置
  mocha?: {
    enabled?: boolean;
    config?: string;
    reporter?: string;
  };

  // Cypress 配置
  cypress?: {
    enabled?: boolean;
    config?: string;
    headless?: boolean;
    browser?: string;
  };

  // Playwright 配置
  playwright?: {
    enabled?: boolean;
    config?: string;
    headless?: boolean;
    browser?: string;
  };

  // 覆盖率配置
  coverageConfig?: {
    enabled?: boolean;
    threshold?: number;
    reporters?: string[];
    output?: string;
  };
}

🎯 支持的测试框架

Vitest

# 安装 Vitest
pnpm add -D vitest

# 运行 Vitest 测试
synthia test --framework vitest

# 启动 UI 界面
synthia test --framework vitest --ui

# 监听模式
synthia test --framework vitest --watch

Jest

# 安装 Jest
pnpm add -D jest

# 运行 Jest 测试
synthia test --framework jest

# 监听模式
synthia test --framework jest --watch

Mocha

# 安装 Mocha
pnpm add -D mocha

# 运行 Mocha 测试
synthia test --framework mocha

Cypress

# 安装 Cypress
pnpm add -D cypress

# 运行 Cypress 测试
synthia test --framework cypress

# 无头模式
synthia test --framework cypress --headless

Playwright

# 安装 Playwright
pnpm add -D playwright

# 运行 Playwright 测试
synthia test --framework playwright

# 无头模式
synthia test --framework playwright --headless

📊 覆盖率报告

配置覆盖率

// synthia.config.ts
export default defineConfig({
  plugins: [
    {
      name: 'test',
      plugin: testPlugin({
        coverageConfig: {
          enabled: true,
          threshold: 85,
          reporters: ['text', 'html', 'json'],
          output: 'coverage',
        },
      }),
    },
  ],
});

生成覆盖率报告

# 生成覆盖率报告
synthia test --coverage

# 设置覆盖率阈值
synthia test --coverage --threshold 90

🔧 高级用法

自定义文件模式

# 只测试特定文件
synthia test --pattern "src/components/**/*.test.ts"

# 测试多个模式
synthia test --pattern "src/**/*.test.{ts,tsx}" --pattern "tests/**/*.spec.js"

指定配置文件

# 使用自定义配置文件
synthia test --config custom-test.config.js

CI 集成

# .github/workflows/test.yml
name: Test
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '18'
      - run: pnpm install
      - run: synthia test --ci --coverage

📁 项目结构

your-project/
├── src/
│   ├── components/
│   │   └── Button.test.tsx
│   ├── utils/
│   │   └── helpers.test.ts
│   └── __tests__/
│       └── integration.test.ts
├── tests/
│   ├── e2e/
│   │   └── user-flow.spec.ts
│   └── fixtures/
│       └── test-data.json
├── coverage/                 # 覆盖率报告输出目录
├── vitest.config.ts         # Vitest 配置
├── jest.config.js           # Jest 配置
└── synthia.config.ts        # Synthia 配置

🐛 故障排除

常见问题

Q: 测试框架未检测到

# 确保已安装测试框架
pnpm add -D vitest

# 手动指定框架
synthia test --framework vitest

Q: 覆盖率报告未生成

# 确保启用了覆盖率
synthia test --coverage

# 检查配置文件
synthia test --coverage --config vitest.config.ts

Q: 监听模式不工作

# 确保文件变化检测正常
synthia test --watch --pattern "src/**/*.test.ts"

调试模式

# 启用详细日志
synthia test --verbose

# 查看检测到的框架
synthia test --framework auto

🤝 贡献

欢迎贡献代码!请查看 贡献指南 了解详细信息。

开发环境设置

# 克隆仓库
git clone https://github.com/your-org/synthia-engine.git

# 安装依赖
pnpm install

# 运行测试
pnpm test

# 构建插件
pnpm build

📄 许可证

MIT License - 查看 LICENSE 文件了解详细信息。

🔗 相关链接

📞 支持

如果您遇到问题或有任何疑问,请:

  1. 查看 FAQ
  2. 搜索 Issues
  3. 创建新的 Issue
  4. 加入我们的 Discord 社区