-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-simple.js
More file actions
90 lines (76 loc) · 2.25 KB
/
test-simple.js
File metadata and controls
90 lines (76 loc) · 2.25 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* Simple Node.js test to demonstrate FlowTrace
* Using direct function calls instead of decorators
*/
/**
* Test service - FlowTrace will automatically instrument functions
* that match the package prefix
*/
class TestService {
constructor() {
this.counter = 0;
console.log('TestService initialized');
}
increment() {
this.counter++;
console.log(`Counter incremented to: ${this.counter}`);
return this.counter;
}
processData(data) {
console.log(`Processing ${data.length} items`);
const result = data.map(item => item.toUpperCase());
console.log(`Processed result: ${result.join(', ')}`);
return { processed: result.length, items: result };
}
delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async asyncOperation(value) {
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;
}
calculateSum(a, b) {
console.log(`Calculating sum of ${a} + ${b}`);
const result = a + b;
console.log(`Sum result: ${result}`);
return result;
}
}
/**
* Main execution function
*/
async function main() {
console.log('\n=== FlowTrace Node.js Test ===\n');
const service = new TestService();
// Test 1: Simple method calls
console.log('Test 1: Increment counter');
service.increment();
service.increment();
service.increment();
console.log('');
// Test 2: Data processing
console.log('Test 2: Process data');
const data = ['hello', 'world', 'flowtrace', 'test'];
const result = service.processData(data);
console.log('Result:', JSON.stringify(result));
console.log('');
// Test 3: Calculate sum
console.log('Test 3: Calculate sums');
service.calculateSum(5, 3);
service.calculateSum(10, 20);
service.calculateSum(100, 50);
console.log('');
// Test 4: Async operations
console.log('Test 4: Async operations');
await service.asyncOperation(5);
await service.asyncOperation(10);
await service.asyncOperation(15);
console.log('');
console.log('=== Test completed ===');
console.log('✅ Check flowtrace.jsonl for execution logs\n');
}
// Run main function
main().catch(console.error);