Skip to content

Commit 3433831

Browse files
authored
fix: mock replaceChildren (#21)
1 parent 33a6a01 commit 3433831

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

lib/widgets/terminal.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ interface MockElement {
5353
getAttribute(): void;
5454
focus(): void;
5555
blur(): void;
56+
replaceChildren(): void;
5657
}
5758

5859
interface TermObject {
@@ -250,6 +251,12 @@ Terminal.prototype.bootstrap = function (this: TerminalInterface): void {
250251
style: {},
251252
focus: function () {},
252253
blur: function () {},
254+
replaceChildren: function () {
255+
// Mock implementation of Element.replaceChildren()
256+
// Accepts any number of Node objects or strings as arguments
257+
// In real DOM, this would replace all children with provided nodes
258+
// For mock, we can just do nothing (no-op)
259+
},
253260
console: console,
254261
// Mock DOM APIs that xterm.js needs
255262
classList: {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)