Skip to content

Commit ddf239c

Browse files
committed
cp dines
1 parent b0d81fc commit ddf239c

56 files changed

Lines changed: 13132 additions & 2342 deletions

Some content is hidden

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

TESTING.md

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# Testing Guide
2+
3+
This document explains how to run tests for the Runloop CLI Node.js implementation.
4+
5+
## Test Structure
6+
7+
The test suite is organized into two main categories:
8+
9+
- **Unit Tests** (`tests/__tests__/unit/`) - Fast, isolated tests with mocked dependencies
10+
- **Integration Tests** (`tests/__tests__/integration/`) - End-to-end tests with real API calls
11+
12+
## Environment Setup
13+
14+
### 1. Create Environment File
15+
16+
Copy the example environment file and configure it:
17+
18+
```bash
19+
cp env.example .env
20+
```
21+
22+
Edit `.env` with your actual values:
23+
24+
```bash
25+
# API Configuration
26+
RUNLOOP_API_KEY=your-actual-api-key-here
27+
RUNLOOP_ENV=dev
28+
29+
# Test Configuration
30+
RUN_E2E=false
31+
NODE_ENV=test
32+
```
33+
34+
### 2. Install Dependencies
35+
36+
```bash
37+
npm install
38+
```
39+
40+
## Running Tests
41+
42+
### Unit Tests (Fast, No API Calls)
43+
44+
```bash
45+
# Run all unit tests
46+
npm run test:unit
47+
48+
# Run with coverage
49+
npm run test:coverage
50+
51+
# Run in watch mode
52+
npm run test:watch
53+
```
54+
55+
### Integration Tests (Requires API Key)
56+
57+
```bash
58+
# Run integration tests (requires RUNLOOP_API_KEY)
59+
npm run test:integration
60+
61+
# Run E2E tests with real API calls
62+
npm run test:e2e
63+
```
64+
65+
### All Tests
66+
67+
```bash
68+
# Run all tests
69+
npm test
70+
```
71+
72+
## Test Categories
73+
74+
### Unit Tests
75+
76+
- **Utils Tests** (`utils.test.ts`) - Test utility functions and configuration
77+
- **Command Tests** - Test individual command implementations with mocked API calls
78+
- `devbox.test.ts` - Devbox command tests
79+
- `blueprint.test.ts` - Blueprint command tests
80+
- `object.test.ts` - Object storage command tests
81+
82+
### Integration Tests
83+
84+
- **Devbox E2E** (`devbox.e2e.test.ts`) - Full devbox lifecycle testing
85+
- **Blueprint E2E** (`blueprint.e2e.test.ts`) - Blueprint creation and management
86+
- **Object E2E** (`object.e2e.test.ts`) - Object storage operations
87+
88+
## Environment Variables
89+
90+
| Variable | Description | Default | Required for E2E |
91+
|----------|-------------|---------|------------------|
92+
| `RUNLOOP_API_KEY` | Your Runloop API key | `test-api-key` | ✅ Yes |
93+
| `RUNLOOP_ENV` | API environment (dev/prod) | `dev` | No |
94+
| `RUN_E2E` | Enable E2E test mode | `false` | No |
95+
| `NODE_ENV` | Node environment | `test` | No |
96+
97+
## Test Configuration
98+
99+
### Jest Configuration
100+
101+
The project uses Jest with TypeScript support:
102+
103+
- **Preset**: `ts-jest` for TypeScript compilation
104+
- **Environment**: Node.js
105+
- **Coverage**: 80% threshold for all metrics
106+
- **Timeout**: 30 seconds for integration tests
107+
108+
### Coverage Requirements
109+
110+
- **Branches**: 80%
111+
- **Functions**: 80%
112+
- **Lines**: 80%
113+
- **Statements**: 80%
114+
115+
## Troubleshooting
116+
117+
### Common Issues
118+
119+
1. **Missing API Key**: Integration tests will be skipped if `RUNLOOP_API_KEY` is not set
120+
2. **Network Issues**: E2E tests require internet connectivity
121+
3. **SSH Tools**: Some tests require local SSH/OpenSSL tools
122+
4. **File Permissions**: Ensure write access to temp directories
123+
124+
### Debug Mode
125+
126+
Run tests with verbose output:
127+
128+
```bash
129+
npm test -- --verbose
130+
```
131+
132+
### Skip Integration Tests
133+
134+
To run only unit tests:
135+
136+
```bash
137+
npm run test:unit
138+
```
139+
140+
## Test Development
141+
142+
### Adding New Tests
143+
144+
1. **Unit Tests**: Add to appropriate test file in `tests/__tests__/unit/`
145+
2. **Integration Tests**: Add to appropriate E2E test file in `tests/__tests__/integration/`
146+
3. **Fixtures**: Add mock data to `tests/fixtures/mocks.ts`
147+
4. **Helpers**: Add utilities to `tests/helpers.ts`
148+
149+
### Test Patterns
150+
151+
- Use `describe()` for grouping related tests
152+
- Use `it()` for individual test cases
153+
- Use `beforeEach()` and `afterEach()` for setup/cleanup
154+
- Use `pending()` to skip tests conditionally
155+
- Mock external dependencies with `jest.fn()`
156+
157+
### Mock Data
158+
159+
The test suite includes comprehensive mock data:
160+
161+
- **Devbox Mocks**: `mockDevbox()`, `mockExecution()`, `mockLogEntry()`
162+
- **Blueprint Mocks**: `mockBlueprint()`
163+
- **Object Mocks**: `mockObject()`
164+
- **API Client Mocks**: `mockAPIClient()`
165+
166+
## CI/CD Integration
167+
168+
Tests are designed to work in CI environments:
169+
170+
- Unit tests run without external dependencies
171+
- Integration tests are skipped if API key is not available
172+
- Coverage reports are generated for all test runs
173+
- Tests have appropriate timeouts for CI environments
174+
175+

coverage/clover.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<coverage generated="1759965906200" clover="3.2.0">
3+
<project timestamp="1759965906200" name="All files">
4+
<metrics statements="0" coveredstatements="0" conditionals="0" coveredconditionals="0" methods="0" coveredmethods="0" elements="0" coveredelements="0" complexity="0" loc="0" ncloc="0" packages="0" files="0" classes="0"/>
5+
</project>
6+
</coverage>

coverage/coverage-final.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)