Skip to content

Commit eccdebe

Browse files
authored
Merge pull request #12 from objectstack-ai/copilot/add-test-scripts
2 parents be03cf3 + b666627 commit eccdebe

18 files changed

Lines changed: 6376 additions & 3 deletions

packages/spec/README.md

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,77 @@ These can be used with:
8282
pnpm build
8383
```
8484

85+
### Testing
86+
87+
This package includes comprehensive test coverage for all Zod schemas using **Vitest**.
88+
89+
```bash
90+
# Run tests once
91+
pnpm test
92+
93+
# Run tests in watch mode
94+
pnpm test:watch
95+
96+
# Run tests with coverage report
97+
pnpm test:coverage
98+
```
99+
100+
#### Test Structure
101+
102+
Tests are co-located with schema files using the `.test.ts` suffix:
103+
104+
```text
105+
src/
106+
├── data/
107+
│ ├── field.zod.ts # Schema definition
108+
│ ├── field.test.ts # Tests
109+
│ ├── object.zod.ts
110+
│ └── object.test.ts
111+
├── ui/
112+
│ ├── view.zod.ts
113+
│ └── view.test.ts
114+
└── system/
115+
├── manifest.zod.ts
116+
└── manifest.test.ts
117+
```
118+
119+
#### Test Coverage
120+
121+
Each test file includes:
122+
* **Schema Validation Tests**: Verify valid inputs pass and invalid inputs fail
123+
* **Default Value Tests**: Ensure default values are applied correctly
124+
* **Type Tests**: Test discriminated unions and type narrowing
125+
* **Constraint Tests**: Validate naming conventions (snake_case), regex patterns, enums
126+
* **Real-World Examples**: Complete, realistic examples from CRM, HR, Sales domains
127+
128+
**Current Coverage**: 263 tests across 13 test files with 100% coverage for tested schemas.
129+
130+
#### Writing Tests
131+
132+
When adding new schemas, follow these patterns:
133+
134+
```typescript
135+
import { describe, it, expect } from 'vitest';
136+
import { YourSchema } from './your-schema.zod';
137+
138+
describe('YourSchema', () => {
139+
it('should accept valid data', () => {
140+
const valid = { /* valid data */ };
141+
expect(() => YourSchema.parse(valid)).not.toThrow();
142+
});
143+
144+
it('should reject invalid data', () => {
145+
const invalid = { /* invalid data */ };
146+
expect(() => YourSchema.parse(invalid)).toThrow();
147+
});
148+
149+
it('should apply defaults', () => {
150+
const result = YourSchema.parse({ /* minimal data */ });
151+
expect(result.someField).toBe('default-value');
152+
});
153+
});
154+
```
155+
85156
### Directory Structure
86157

87158
```text
@@ -91,5 +162,6 @@ packages/spec/
91162
│ ├── ui/ # ObjectUI Protocol
92163
│ └── system/ # ObjectOS Protocol
93164
├── json-schema/ # Auto-generated (npm run gen:schema)
94-
└── dist/ # Compiled JS/D.TS
165+
├── dist/ # Compiled JS/D.TS
166+
└── vitest.config.ts # Test configuration
95167
```

packages/spec/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
"dev": "tsc --watch",
1515
"clean": "rm -rf dist",
1616
"gen:schema": "tsx scripts/build-schemas.ts",
17-
"gen:docs": "tsx scripts/build-docs.ts"
17+
"gen:docs": "tsx scripts/build-docs.ts",
18+
"test": "vitest run",
19+
"test:watch": "vitest",
20+
"test:coverage": "vitest run --coverage"
1821
},
1922
"keywords": [
2023
"objectstack",
@@ -27,8 +30,10 @@
2730
"license": "Apache-2.0",
2831
"devDependencies": {
2932
"@types/node": "^20.10.0",
33+
"@vitest/coverage-v8": "^2.1.8",
3034
"tsx": "^4.21.0",
3135
"typescript": "^5.3.0",
36+
"vitest": "^2.1.8",
3237
"zod-to-json-schema": "^3.25.1"
3338
},
3439
"dependencies": {

0 commit comments

Comments
 (0)