Skip to content

Commit 3ad83dd

Browse files
author
Loïc Mangeonjean
committed
chore: add webgl shadow dom test
1 parent 496b53d commit 3ad83dd

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

test/playwright/SharedRendererTests.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,10 +1280,10 @@ enum CellColorPosition {
12801280
* treatment.
12811281
*/
12821282
export function injectSharedRendererTestsStandalone(ctx: ISharedRendererTestContext, setupCb: () => Promise<void> | void): void {
1283-
test.describe('standalone tests', () => {
1283+
const setupTests = ({ shadowDom }: { shadowDom: boolean }): void => {
12841284
test.beforeEach(async () => {
12851285
// Recreate terminal
1286-
await openTerminal(ctx.value);
1286+
await openTerminal(ctx.value, {}, { useShadowDom: shadowDom });
12871287
await ctx.value.page.evaluate(`
12881288
window.term.options.minimumContrastRatio = 1;
12891289
window.term.options.allowTransparency = false;
@@ -1308,6 +1308,13 @@ export function injectSharedRendererTestsStandalone(ctx: ISharedRendererTestCont
13081308
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 1, 1), [0, 0, 0, 255]);
13091309
});
13101310
});
1311+
};
1312+
1313+
test.describe('standalone tests', () => {
1314+
setupTests({ shadowDom: false });
1315+
});
1316+
test.describe('standalone tests (Shadow dom)', () => {
1317+
setupTests({ shadowDom: true });
13111318
});
13121319
}
13131320

test/playwright/TestUtils.ts

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ class TerminalCoreProxy {
412412
}
413413
}
414414

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> {
416416
await ctx.page.evaluate(`
417417
if ('term' in window) {
418418
try {
@@ -423,13 +423,48 @@ export async function openTerminal(ctx: ITestContext, options: ITerminalOptions
423423
// HACK: Tests may have side effects that could cause the terminal not to be removed. This
424424
// assertion catches this case early.
425425
strictEqual(await ctx.page.evaluate(`document.querySelector('#terminal-container').children.length`), 0, 'there must be no terminals on the page');
426-
await ctx.page.evaluate(`
426+
427+
let script = `
427428
window.term = new window.Terminal(${JSON.stringify({ allowProposedApi: true, ...options })});
428-
window.term.open(document.querySelector('#terminal-container'));
429-
`);
429+
let element = document.querySelector('#terminal-container');
430+
431+
// Remove shadow root if it exists
432+
const newElement = element.cloneNode(false);
433+
element.replaceWith(newElement);
434+
element = newElement
435+
`;
436+
437+
438+
if (useShadowDom) {
439+
script += `
440+
const shadowRoot = element.attachShadow({ mode: "open" });
441+
442+
// Copy parent styles to shadow DOM
443+
const styles = Array.from(document.querySelectorAll('link[rel="stylesheet"]'));
444+
styles.forEach((styleEl) => {
445+
const clone = document.createElement('link');
446+
clone.rel = 'stylesheet';
447+
clone.href = styleEl.href;
448+
shadowRoot.appendChild(clone);
449+
});
450+
451+
// Create new element inside the shadow DOM
452+
element = document.createElement('div');
453+
element.style.width = '100%';
454+
element.style.height = '100%';
455+
shadowRoot.appendChild(element);
456+
`;
457+
}
458+
459+
script += `
460+
window.term.open(element);
461+
`;
462+
463+
await ctx.page.evaluate(script);
464+
430465
// HACK: This is a soft layer breaker that's temporarily included until unicode graphemes have
431466
// more complete integration tests. See https://github.com/xtermjs/xterm.js/pull/4519#discussion_r1285234453
432-
if (testOptions.loadUnicodeGraphemesAddon) {
467+
if (loadUnicodeGraphemesAddon) {
433468
await ctx.page.evaluate(`
434469
window.unicode = new UnicodeGraphemesAddon();
435470
window.term.loadAddon(window.unicode);

0 commit comments

Comments
 (0)