@@ -412,7 +412,7 @@ class TerminalCoreProxy {
412
412
}
413
413
}
414
414
415
- export async function openTerminal ( ctx : ITestContext , options : ITerminalOptions | ITerminalInitOnlyOptions = { } , testOptions : { loadUnicodeGraphemesAddon : boolean } = { loadUnicodeGraphemesAddon : true } ) : Promise < void > {
415
+ export async function openTerminal ( ctx : ITestContext , options : ITerminalOptions | ITerminalInitOnlyOptions = { } , { useShadowDom = false , loadUnicodeGraphemesAddon = true } : { loadUnicodeGraphemesAddon ? : boolean , useShadowDom ?: boolean } = { } ) : Promise < void > {
416
416
await ctx . page . evaluate ( `
417
417
if ('term' in window) {
418
418
try {
@@ -425,18 +425,46 @@ export async function openTerminal(ctx: ITestContext, options: ITerminalOptions
425
425
strictEqual ( await ctx . page . evaluate ( `document.querySelector('#terminal-container').children.length` ) , 0 , 'there must be no terminals on the page' ) ;
426
426
await ctx . page . evaluate ( `
427
427
window.term = new window.Terminal(${ JSON . stringify ( { allowProposedApi : true , ...options } ) } );
428
- window.term.open(document.querySelector('#terminal-container'));
428
+ let element = document.querySelector('#terminal-container');
429
+
430
+ // Remove shadow root if it exists
431
+ const newElement = element.cloneNode(false);
432
+ element.replaceWith(newElement);
433
+ element = newElement
434
+
435
+ ${ useShadowDom ? `
436
+ const shadowRoot = element.attachShadow({ mode: "open" });
437
+
438
+ // Copy parent styles to shadow DOM
439
+ const styles = Array.from(document.querySelectorAll('link[rel="stylesheet"]'));
440
+ styles.forEach((styleEl) => {
441
+ const clone = document.createElement('link');
442
+ clone.rel = 'stylesheet';
443
+ clone.href = styleEl.href;
444
+ shadowRoot.appendChild(clone);
445
+ });
446
+
447
+ // Create new element inside the shadow DOM
448
+ element = document.createElement('div');
449
+ element.style.width = '100%';
450
+ element.style.height = '100%';
451
+ shadowRoot.appendChild(element);
452
+ ` : `
453
+ ` }
454
+
455
+ window.term.open(element);
429
456
` ) ;
457
+
430
458
// HACK: This is a soft layer breaker that's temporarily included until unicode graphemes have
431
459
// more complete integration tests. See https://github.com/xtermjs/xterm.js/pull/4519#discussion_r1285234453
432
- if ( testOptions . loadUnicodeGraphemesAddon ) {
460
+ if ( loadUnicodeGraphemesAddon ) {
433
461
await ctx . page . evaluate ( `
434
462
window.unicode = new UnicodeGraphemesAddon();
435
463
window.term.loadAddon(window.unicode);
436
464
window.term.unicode.activeVersion = '15-graphemes';
437
465
` ) ;
438
466
}
439
- await ctx . page . waitForSelector ( '.xterm-rows' ) ;
467
+ await ctx . page . locator ( '.xterm-rows' ) . waitFor ( ) ;
440
468
ctx . termHandle = await ctx . page . evaluateHandle ( 'window.term' ) ;
441
469
await ctx . proxy . initTerm ( ) ;
442
470
}
0 commit comments