Skill站外收录 @skilllib/skill-2117939930272411085
testing
提供项目测试全流程支持,涵盖单元测试与端到端测试的策略选择、目录结构、运行环境、命令调用及 mock 方式,明确两类测试的适用边界,并统一命名规范、断言风格与开发验证流程。
测试与安全 AI 技能
Skills.MD
# Testing in Sandbox SDK
This skill covers project-specific testing conventions. For TDD methodology, use the `superpowers:test-driven-development` skill.
## Two Test Suites
### Unit Tests
**When to use**: Testing isolated logic, client behavior, service methods, utilities.
**Location**:
- SDK: `packages/sandbox/tests/`
- Container: `packages/sandbox-container/tests/`
**Runtime**:
- SDK tests run in Workers runtime via `@cloudflare/vitest-pool-workers`
- Container tests run in Bun runtime
**Commands**:
```bash
npm test # All unit tests
npm test -w @cloudflare/sandbox # SDK tests only
npm test -w @repo/sandbox-container # Container tests only
```
**Mock patterns**:
- SDK tests use a mock container (no Docker needed)
- Container tests mock external dependencies (filesystem, processes)
- Use `createNoOpLogger()` from `@repo/shared` for logger mocks
**Known issue**: SDK unit tests may hang on exit due to vitest-pool-workers workerd shutdown. Tests still pass/fail correctly - the hang is cosmetic.
### E2E Tests
**When to use**: Testing full request flow, container integration, real Docker behavior.
**Location**: `tests/e2e/`
**Runtime**: Real Cloudflare Workers + Docker containers
**Commands**:
```bash
npm run test:e2e # All E2E tests
npm run test:e2e -- -- tests/e2e/process-lifecycle-workflow.test.ts # Single file
npm run test:e2e -- -- tests/e2e/git-clone-workflow.test.ts -t 'test name' # Single test
```
**Key patterns**:
- All tests share ONE container for performance
- Use unique sessions for test isolation
- Tests run in parallel via thread pool
- Config: `vitest.e2e.config.ts` (root level)
**Writing E2E tests**:
```typescript
import { createTestSession } from './helpers';
describe('Feature X', () => {
let session: TestSession;
beforeEach(async () => {
session = await createTestSession(); // Gets unique session
});
it('should do something', async () => {
const result = await session.sandbox.exec('echo hello');
expect(result.stdout).toBe('hello\n');
});
});
```
## When to Use Which
| Scenario | Test Type |
| --------------------------------------- | --------- |
| Client method logic | Unit |
| Service business logic | Unit |
| Request/response handling | Unit |
| Full command execution flow | E2E |
| File operations with real filesystem | E2E |
| Process lifecycle (start, stop, signal) | E2E |
| Port exposure and preview URLs | E2E |
| Git operations | E2E |
## Test-Specific Conventions
**File naming**: `*.test.ts` for both unit and E2E tests
**Test structure**:
```typescript
describe('ComponentName', () => {
describe('methodName', () => {
it('should do X when Y', async () => {
// Arrange
// Act
// Assert
});
});
});
```
**Assertions**: Use vitest's `expect()` with clear, specific assertions
## Running Tests During Development
After making any meaningful code change:
1. `npm run check` - catch type errors first
2. `npm test` - verify unit tests pass
3. `npm run test:e2e` - if touching core functionality
**Build trust**: The monorepo build system handles dependencies automatically. E2E tests always run against latest built code - no manual rebuild needed.
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「testing」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次