Skill站外收录 @skilllib/skill-2117939930272411012
g2-testing
为 G2 可视化库提供单元测试与集成测试的完整实践指南,涵盖测试目录组织、用例编写规范、图表配置导出约定及本地测试执行流程,确保测试代码风格统一、可维护性强,并能有效验证数据处理逻辑与可视化渲染结果。
测试与安全 AI 技能
Skills.MD
## Document Information
**Document Title:** G2 Unit Testing Skill Specification
**Version:** 1.0
**Author:** G2 Development Team
**Purpose:** Guide for writing effective unit tests in the G2 visualization library
## Overview
This skill specification provides comprehensive guidelines for writing unit tests in the G2 visualization library. It covers directory structure, testing patterns, best practices, and implementation guidelines to ensure consistent and maintainable test code.
## Prerequisites
Before writing unit tests for G2, ensure you have:
- Understanding of TypeScript and Jest testing framework
- Familiarity with G2's codebase structure
- Knowledge of the specific module you are testing
## Test Directory Structure
G2 organizes tests into two main categories:
### Unit Tests (`__tests__/unit/`)
Unit tests are for testing pure data modules or functions. They are located in `__tests__/unit/` and organized by module:
- `api/` - Chart API related tests
- `data/` - Data transformation tests
- `scale/` - Scale related tests
- `encode/` - Encoding related tests
- `component/` - Component related tests
- `utils/` - Utility function tests
- And more...
### Integration Tests (`__tests__/plots/`)
Integration tests test the rendering results of the entire visualization chart by comparing screenshots. Located in `__tests__/plots/`, these are organized by focus areas:
- `static/` - Static drawing related cases
- `animation/` - Animation related cases
- `api/` - Chart API related cases
- `interaction/` - Interaction related cases
- `tooltip/` - Tooltip related cases
- `legend/` - Legend related cases
- `bugfix/` - Bug fix related cases
## Unit Test Implementation Guidelines
### Test Structure
Follow the standard Jest testing structure:
```typescript
import { YourFunction } from '../../../src/your-module';
describe('YourFunction', () => {
it('should perform expected behavior', () => {
// Test implementation
expect(result).toBe(expected);
});
});
```
## Integration Test Guidelines
### Chart Configuration Tests
Integration tests typically export chart configurations:
```typescript
import { G2Spec } from '../../../src';
export function alphabetInterval(): G2Spec {
return {
type: 'interval',
transform: [{ type: 'sortX', by: 'y', reverse: true }],
data: {
type: 'fetch',
value: 'data/alphabet.csv',
},
axis: {
y: { labelFormatter: '.0%' },
},
encode: {
x: 'letter',
y: 'frequency',
},
};
}
```
### Export Convention
- Export each test case as a function that returns a `G2Spec`
- Name the export function descriptively
- Add the export to the appropriate `index.ts` file to make it visible in the preview environment
## Testing Workflow
### Running Tests
To run all tests locally:
```bash
npm run test
```
To run tests on demand (specific test files or directories):
```bash
# Run specific test file
npm run test -- path/to/your/test-file.test.ts
# Run tests matching a pattern
npm run test -- --testNamePattern="legend"
```
This ensures your changes pass all existing tests before submitting a pull request.
### 9.2 Adding New Tests
- Determine the appropriate directory for your test
- Follow existing patterns in the same directory
- Export your test case in the corresponding index.ts file
## 10. Troubleshooting
Common issues and solutions:
- If tests fail due to missing dependencies, ensure all imports are correct
- For async test issues, verify proper use of async/await or Promises
- If tests are slow, check for unnecessary computations or network requests
## 11. References
- Review existing tests in the codebase for examples
- Follow the existing patterns and conventions
- When in doubt, refer to similar tests in the same module
评论 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
举报「g2-testing」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次