-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_stream_phase2.js
More file actions
86 lines (78 loc) · 2.98 KB
/
test_stream_phase2.js
File metadata and controls
86 lines (78 loc) · 2.98 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
import stream from 'node:stream';
console.log('=== Testing Stream Phase 2 Features ===\n');
// Test 1: PassThrough stream
console.log('1. Testing PassThrough stream...');
try {
const passthrough = new stream.PassThrough();
console.log(' ✓ PassThrough created');
console.log(' - readable:', passthrough.readable);
console.log(' - writable:', passthrough.writable);
} catch (e) {
console.log(' ✗ Error:', e.message);
}
// Test 2: Additional properties (closed, destroyed, errored)
console.log('\n2. Testing additional properties...');
try {
const readable = new stream.Readable();
console.log(' Readable properties:');
console.log(' - closed:', readable.closed);
console.log(' - destroyed:', readable.destroyed);
console.log(' - errored:', readable.errored);
const writable = new stream.Writable();
console.log(' Writable properties:');
console.log(' - closed:', writable.closed);
console.log(' - destroyed:', writable.destroyed);
console.log(' - errored:', writable.errored);
console.log(' ✓ Properties accessible');
} catch (e) {
console.log(' ✗ Error:', e.message);
}
// Test 3: Duplex.from() static method
console.log('\n3. Testing Duplex.from()...');
try {
const duplex = stream.Duplex.from([1, 2, 3]);
console.log(' ✓ Duplex.from() created instance');
console.log(' - readable:', duplex.readable);
console.log(' - writable:', duplex.writable);
} catch (e) {
console.log(' ✗ Error:', e.message);
}
// Test 4: Collection methods
console.log('\n4. Testing collection methods...');
try {
const testMethods = [
'map', 'filter', 'forEach', 'toArray',
'some', 'find', 'every', 'flatMap',
'drop', 'take', 'reduce'
];
const readable = new stream.Readable();
let methodCount = 0;
for (const method of testMethods) {
try {
if (typeof readable[method] === 'function') {
methodCount++;
}
} catch (e) {
console.log(` ✗ ${method}:`, e.message);
}
}
console.log(` ✓ ${methodCount}/${testMethods.length} collection methods available`);
} catch (e) {
console.log(' ✗ Error in test 4:', e.message);
}
// Test 5: PassThrough basic functionality
console.log('\n5. Testing PassThrough...');
try {
const passthrough = new stream.PassThrough();
console.log(' ✓ PassThrough instance created');
console.log(' - readable:', passthrough.readable);
console.log(' - writable:', passthrough.writable);
console.log(' - Has write method:', typeof passthrough.write === 'function');
console.log(' - Has push method:', typeof passthrough.push === 'function');
console.log('\n=== Phase 2 Tests Complete ===');
process.exit(0);
} catch (e) {
console.log(' ✗ Error:', e.message);
console.log('\n=== Phase 2 Tests Complete ===');
process.exit(1);
}