Skill站外收录 @skilllib/skill-2014279386030092292
dust-test
提供针对 Dust 代码库的测试编写方法论,强调聚焦核心路径与高频边缘场景,优先使用真实数据库和工厂函数构造数据,仅对外部服务做必要模拟,通过简洁可维护的用例覆盖八成关键行为。
测试与安全 AI 技能
Skills.MD
# Creating automated tests for Dust codebases
Write focused, practical tests for the current file following the 80/20 principle.
## Instructions
When writing tests for a file:
1. **Identify the core functionality**: Focus on the most important paths and edge cases that provide 80% of the value
2. **Keep it simple**: Write straightforward tests that are easy to understand and maintain
3. **Minimal mocking**:
- DO NOT mock the database
- Only mock external services (APIs, third-party services)
- Prefer real implementations when possible
4. **Use factories**: Leverage test factories to set up data efficiently
5. **Focus on behavior**: Test what the code does, not how it does it
## For Front (TypeScript/Next.js)
### Setup
- Import factories from `front/tests/utils/factories`
- Import utilities from `front/tests/utils/utils`
- Use the test database (no mocking)
### Structure
```typescript
import {describe, it, expect} from "vitest";
import {makeTestWorkspace, makeTestUser} from "tests/utils/factories";
describe ("ComponentName or FunctionName", () => {
it ("should handle the main happy path", async () => {
// Arrange: Set up using factories
const {workspace} = createResourceTest ()
// Act: Execute the code
const result = await functionUnderTest (workspace);
// Assert: Verify behavior
expect (result).toBeDefined ();
});
it ("should handle the most common edge case", async () => {
// Test the second most important scenario
});
});
```
### What to test (80/20 focus)
- Main success paths
- Most common error conditions
- Critical edge cases (null/undefined, empty arrays, etc.)
- Permission checks (if applicable)
### What to skip (diminishing returns)
- Exhaustive parameter combinations
- Unlikely edge cases
- Internal implementation details
- UI component rendering (unless critical)
## For Connectors/Core
Follow similar principles:
- Use factories appropriate to the service
- Focus on integration points
- Mock external APIs only (Slack, Notion, GitHub, etc.)
- Test the database interactions directly
## Example Pattern
```typescript
describe ("createConversation", () => {
it ("creates conversation with valid params", async () => {
const {workspace, user} = createResourceTest ()
const conversation = await createConversation ({
workspace,
userId: user.id,
title: "Test"
});
expect (conversation.sId).toBeDefined ();
expect (conversation.title).toBe ("Test");
});
it ("fails without required permissions", async () => {
const {workspace, user} = createResourceTest ()
await expect (
createConversation ({workspace, userId: user.id})
).rejects.toThrow ("Permission denied");
});
});
```
## Execution Steps
1. Read the file to understand its purpose and main exports
2. Check if a test file already exists (e.g., `file.test.ts`)
3. Identify the 2-4 most important functions/behaviors to test
4. Find or create appropriate factories for test data
5. Write concise, focused tests
6. Run tests with `npm test` to verify they pass
评论 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
举报「dust-test」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次