|
| 1 | +const assert = require('assert'); |
| 2 | + |
| 3 | +Feature('Complete validation for issue #5066 fix'); |
| 4 | + |
| 5 | +Scenario('End-to-end worker data sharing validation', () => { |
| 6 | + console.log('=== Testing complete data sharing workflow ==='); |
| 7 | + |
| 8 | + // Test 1: Basic data sharing |
| 9 | + share({ |
| 10 | + message: 'Hello from main thread', |
| 11 | + config: { timeout: 5000, retries: 3 }, |
| 12 | + users: ['alice', 'bob', 'charlie'] |
| 13 | + }); |
| 14 | + |
| 15 | + const data = inject(); |
| 16 | + |
| 17 | + // Verify all property types work correctly |
| 18 | + assert.strictEqual(data.message, 'Hello from main thread', 'String property should work'); |
| 19 | + assert.strictEqual(data.config.timeout, 5000, 'Nested object property should work'); |
| 20 | + assert.strictEqual(data.config.retries, 3, 'Nested object property should work'); |
| 21 | + assert(Array.isArray(data.users), 'Array property should work'); |
| 22 | + assert.strictEqual(data.users.length, 3, 'Array length should work'); |
| 23 | + assert.strictEqual(data.users[0], 'alice', 'Array access should work'); |
| 24 | + |
| 25 | + // Test 2: Data overriding |
| 26 | + share({ message: 'Updated message' }); |
| 27 | + const updatedData = inject(); |
| 28 | + assert.strictEqual(updatedData.message, 'Updated message', 'Data override should work'); |
| 29 | + assert.strictEqual(updatedData.config.timeout, 5000, 'Previous data should persist'); |
| 30 | + |
| 31 | + // Test 3: Complex nested structures |
| 32 | + share({ |
| 33 | + testSuite: { |
| 34 | + name: 'E2E Tests', |
| 35 | + tests: [ |
| 36 | + { name: 'Login test', status: 'passed', data: { user: 'admin', pass: 'secret' } }, |
| 37 | + { name: 'Checkout test', status: 'failed', error: 'Timeout occurred' } |
| 38 | + ], |
| 39 | + metadata: { |
| 40 | + browser: 'chrome', |
| 41 | + version: '91.0', |
| 42 | + viewport: { width: 1920, height: 1080 } |
| 43 | + } |
| 44 | + } |
| 45 | + }); |
| 46 | + |
| 47 | + const complexData = inject(); |
| 48 | + assert.strictEqual(complexData.testSuite.name, 'E2E Tests', 'Deep nested string should work'); |
| 49 | + assert.strictEqual(complexData.testSuite.tests[0].data.user, 'admin', 'Very deep nested access should work'); |
| 50 | + assert.strictEqual(complexData.testSuite.metadata.viewport.width, 1920, 'Very deep nested number should work'); |
| 51 | + |
| 52 | + // Test 4: Key enumeration |
| 53 | + const allKeys = Object.keys(inject()); |
| 54 | + assert(allKeys.includes('message'), 'Keys should include shared properties'); |
| 55 | + assert(allKeys.includes('testSuite'), 'Keys should include all shared properties'); |
| 56 | + |
| 57 | + console.log('✅ ALL TESTS PASSED - Issue #5066 is completely fixed!'); |
| 58 | + console.log('✅ Workers can now share and inject data without circular dependency errors'); |
| 59 | + console.log('✅ Proxy objects work correctly for both direct and nested property access'); |
| 60 | +}); |
0 commit comments