-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-server.ts
More file actions
76 lines (61 loc) · 2.01 KB
/
test-server.ts
File metadata and controls
76 lines (61 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* Simple Node.js TypeScript test to demonstrate FlowTrace with decorators
* This runs in Node.js (not browser) so FlowTrace can instrument it
*/
import { Trace, TraceClass } from '../../flowtrace-agent-js/src/decorators';
/**
* Test service with automatic tracing
*/
@TraceClass()
class TestService {
private counter: number = 0;
increment(): number {
this.counter++;
console.log(`Counter incremented to: ${this.counter}`);
return this.counter;
}
@Trace({ methodName: 'process-data' })
processData(data: string[]): { processed: number; items: string[] } {
const result = data.map(item => item.toUpperCase());
console.log(`Processed ${result.length} items`);
return { processed: result.length, items: result };
}
async delay(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
}
async asyncOperation(value: number): Promise<number> {
console.log(`Starting async operation with value: ${value}`);
await this.delay(100);
const result = value * 2;
console.log(`Async operation completed: ${value} * 2 = ${result}`);
return result;
}
}
/**
* Main execution function
*/
async function main() {
console.log('=== FlowTrace TypeScript Decorator Test ===\n');
const service = new TestService();
// Test 1: Simple method call
console.log('Test 1: Increment counter');
service.increment();
service.increment();
service.increment();
console.log('\n');
// Test 2: Method with data processing
console.log('Test 2: Process data');
const data = ['hello', 'world', 'flowtrace', 'typescript'];
const result = service.processData(data);
console.log('Result:', result);
console.log('\n');
// Test 3: Async operation
console.log('Test 3: Async operations');
await service.asyncOperation(5);
await service.asyncOperation(10);
await service.asyncOperation(15);
console.log('\n=== Test completed ===');
console.log('Check flowtrace.jsonl for execution logs');
}
// Run main function
main().catch(console.error);