Skip to content

Commit a572fa8

Browse files
committed
feat(*): add FakeServer and temp directory utilities for testing
- Implemented FakeServer class for mocking HTTP requests in tests. - Added tests for FakeServer handling various HTTP methods and responses. - Created temp directory utilities with automatic cleanup for testing file operations. - Introduced writeFiles function to facilitate writing multiple files in tests. - Updated package.json files for @eser/testing and @eser/writer with new dependencies. - Added README documentation for testing utilities and examples. - Refactored format registry and error handling in writer module. - Updated JSX runtime app and vanilla app examples for better integration.
1 parent c0f3cc6 commit a572fa8

File tree

148 files changed

+12093
-2084
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+12093
-2084
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name: architecture-guidelines
3+
description: High-level system architecture including module systems, project structure, architectural decision records (ADRs), and testing strategies. Use when designing systems, reviewing structure, or discussing architecture.
4+
---
5+
6+
# Architecture Guidelines
7+
8+
Guidelines for system design, project structure, and architectural decisions.
9+
10+
## Quick Start
11+
12+
```typescript
13+
// Use ES Modules with explicit extensions
14+
import * as path from "@std/path";
15+
import { readFile } from "./utils.ts";
16+
17+
export function processFile() {}
18+
```
19+
20+
## Key Principles
21+
22+
- Use ES Modules (avoid CommonJS/AMD)
23+
- Follow consistent directory structure with kebab-case directories
24+
- Document architectural decisions with ADRs including trade-offs
25+
- Write automated tests with CI (target 80%+ coverage for critical paths)
26+
- Use naming conventions: PascalCase for components, camelCase for utilities
27+
28+
## References
29+
30+
See [rules.md](references/rules.md) for complete guidelines with examples.
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
# Architecture Guidelines - Detailed Rules
2+
3+
## Module System
4+
5+
Scope: JS/TS projects Rule: Use ES Modules. ES Modules is official standard
6+
supported by all modern browsers and WinterCG runtimes. Avoid CommonJS and AMD.
7+
8+
Correct:
9+
10+
```typescript
11+
import * as path from "@std/path";
12+
import { readFile } from "./utils.ts";
13+
14+
export function processFile() {}
15+
export const CONFIG = {};
16+
```
17+
18+
Incorrect:
19+
20+
```typescript
21+
const path = require("path"); // CommonJS
22+
const { readFile } = require("./utils");
23+
24+
module.exports = { processFile }; // CommonJS
25+
exports.CONFIG = {}; // CommonJS
26+
```
27+
28+
---
29+
30+
## Project Structure
31+
32+
Scope: All projects Rule: Follow consistent directory and file structure. Makes
33+
it easier to locate and manage files.
34+
35+
Example structure:
36+
37+
```
38+
project/
39+
├── src/
40+
│ ├── app/ # Application code
41+
│ ├── components/ # Reusable components
42+
│ └── utils/ # Utility functions
43+
├── tests/ # Test files
44+
├── docs/ # Documentation
45+
├── public/ # Static assets
46+
└── config/ # Configuration files
47+
```
48+
49+
Naming conventions:
50+
51+
- Use kebab-case for directories: `user-service/`
52+
- Use PascalCase for component files: `UserProfile.tsx`
53+
- Use camelCase for utility files: `formatDate.ts`
54+
- Test files: `*.test.ts` or `*.spec.ts`
55+
56+
---
57+
58+
## Architectural Decision Records
59+
60+
Scope: All projects Rule: Document architectural design records (ADRs) with
61+
trade-offs. Captures important decisions with context and consequences.
62+
63+
ADR template (docs/adr/001-decision-title.md):
64+
65+
```markdown
66+
# ADR 001: Decision Title
67+
68+
Date: 2025-01-15 Status: Accepted
69+
70+
## Context
71+
72+
What is the issue we're facing that motivates this decision?
73+
74+
## Decision
75+
76+
What is the change we're making?
77+
78+
## Consequences
79+
80+
What becomes easier or more difficult as a result of this change?
81+
82+
## Alternatives Considered
83+
84+
- Option A: pros/cons
85+
- Option B: pros/cons
86+
87+
## Trade-offs
88+
89+
What are we optimizing for and what are we sacrificing?
90+
```
91+
92+
---
93+
94+
## Testing
95+
96+
Scope: All projects Rule: Write tests for code. Prefer automated testing with
97+
CI. Ensures code works as expected and catches issues early.
98+
99+
Test structure:
100+
101+
```typescript
102+
import { assertEquals } from "@std/assert";
103+
104+
Deno.test("function name - should do something", () => {
105+
const result = myFunction(input);
106+
assertEquals(result, expected);
107+
});
108+
```
109+
110+
CI configuration (.github/workflows/test.yml):
111+
112+
```yaml
113+
name: Test
114+
on: [push, pull_request]
115+
jobs:
116+
test:
117+
runs-on: ubuntu-latest
118+
steps:
119+
- uses: actions/checkout@v4
120+
- uses: denoland/setup-deno@v2
121+
- run: deno test --allow-all
122+
```
123+
124+
Coverage target: Aim for 80%+ code coverage for critical paths.
125+
126+
---
127+
128+
## Entry Point Convention
129+
130+
Scope: JS/TS projects Rule: Use `mod.ts` as module entry points, not `index.ts`.
131+
Follows Deno convention and makes exports explicit.
132+
133+
Correct:
134+
135+
```
136+
package/
137+
├── mod.ts # Main entry point
138+
├── types.ts
139+
├── utils.ts
140+
└── submodule/
141+
└── mod.ts # Submodule entry point
142+
```
143+
144+
```typescript
145+
// mod.ts - explicit re-exports
146+
export { createUser, type User } from "./user.ts";
147+
export { formatDate } from "./utils.ts";
148+
export * from "./types.ts";
149+
```
150+
151+
Incorrect:
152+
153+
```
154+
package/
155+
├── index.ts # Node.js convention
156+
├── index.js
157+
└── submodule/
158+
└── index.ts
159+
```
160+
161+
---
162+
163+
## Co-located Tests
164+
165+
Scope: JS/TS projects Rule: Place test files alongside source files with
166+
`.test.ts` suffix. Makes tests easy to find and maintain.
167+
168+
Correct:
169+
170+
```
171+
src/
172+
├── user.ts
173+
├── user.test.ts # Co-located with source
174+
├── utils.ts
175+
├── utils.test.ts # Co-located with source
176+
└── api/
177+
├── client.ts
178+
└── client.test.ts # Co-located in subdirectory
179+
```
180+
181+
Incorrect:
182+
183+
```
184+
src/
185+
├── user.ts
186+
├── utils.ts
187+
└── api/
188+
└── client.ts
189+
190+
tests/ # Separate tests directory
191+
├── user.test.ts # Far from source
192+
├── utils.test.ts
193+
└── api/
194+
└── client.test.ts
195+
```
196+
197+
Exception: Integration tests that span multiple modules may live in a dedicated
198+
`tests/` directory.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
name: coding-practices
3+
description: Coding practices including error handling, input validation, logging, self-documenting code, and DRY principles. Use when writing code, handling errors, or improving code quality.
4+
---
5+
6+
# Coding Practices
7+
8+
Guidelines for writing maintainable, robust, and self-documenting code.
9+
10+
## Quick Start
11+
12+
```typescript
13+
// Self-documenting with proper error handling
14+
function createUser(email: string, age: number): User {
15+
if (!email.includes("@")) throw new Error("Invalid email");
16+
if (age < 0 || age > 150) throw new Error("Invalid age");
17+
return { email, age };
18+
}
19+
```
20+
21+
## Key Principles
22+
23+
- Use meaningful names (self-documenting code)
24+
- Comments explain "why", not "what"
25+
- DRY: abstract when used 3+ times
26+
- Validate all input data
27+
- Handle all error cases with proper Error objects
28+
- Never ignore errors
29+
- Use named constants instead of magic values
30+
- Avoid circular dependencies
31+
32+
## References
33+
34+
See [rules.md](references/rules.md) for complete guidelines with examples.

0 commit comments

Comments
 (0)