|
| 1 | +/** |
| 2 | + * Test to reproduce the replaceChildren crash in terminal widget |
| 3 | + * This test demonstrates that xterm.js's DomRenderer can now call |
| 4 | + * replaceChildren on the mock DOM element without crashing |
| 5 | + */ |
| 6 | + |
| 7 | +var blessed = require('../'); |
| 8 | +var path = require('path'); |
| 9 | + |
| 10 | +console.log('🧪 Testing terminal widget replaceChildren crash fix...'); |
| 11 | + |
| 12 | +var screen = blessed.screen({ |
| 13 | + dump: path.join(__dirname, '/logs/terminal-replacechildren.log'), |
| 14 | + warnings: true, |
| 15 | + fullUnicode: true, |
| 16 | +}); |
| 17 | + |
| 18 | +// Create a terminal similar to the usage in anton app |
| 19 | +var terminal = blessed.terminal({ |
| 20 | + parent: screen, |
| 21 | + top: 0, |
| 22 | + left: 0, |
| 23 | + width: 40, |
| 24 | + height: 20, |
| 25 | + border: 'line', |
| 26 | + label: ' Test Terminal ', |
| 27 | + shell: '/bin/bash', |
| 28 | + args: ['-c', 'sleep 1000000'], |
| 29 | + fullUnicode: true, |
| 30 | +}); |
| 31 | + |
| 32 | +// Write some data to trigger rendering |
| 33 | +terminal.write('Test output\r\n'); |
| 34 | +terminal.write('This should trigger xterm rendering\r\n'); |
| 35 | + |
| 36 | +screen.render(); |
| 37 | + |
| 38 | +// Give it a moment to initialize and render |
| 39 | +setTimeout(function () { |
| 40 | + try { |
| 41 | + // Trigger the problematic cleanup path |
| 42 | + // This simulates what happens when stream.on("end") is called |
| 43 | + terminal.destroy(); |
| 44 | + screen.destroy(); |
| 45 | + |
| 46 | + // If we get here without error, the bug is fixed |
| 47 | + console.log( |
| 48 | + '✅ SUCCESS: Terminal can be destroyed without replaceChildren crash!' |
| 49 | + ); |
| 50 | + process.exit(0); |
| 51 | + } catch (err) { |
| 52 | + if ( |
| 53 | + err.message && |
| 54 | + err.message.includes('replaceChildren is not a function') |
| 55 | + ) { |
| 56 | + console.error('❌ FAIL: replaceChildren is still missing:', err.message); |
| 57 | + process.exit(1); |
| 58 | + } else { |
| 59 | + console.error('❌ UNEXPECTED ERROR:', err.message); |
| 60 | + console.error(err.stack); |
| 61 | + process.exit(2); |
| 62 | + } |
| 63 | + } |
| 64 | +}, 500); |
0 commit comments