Skip to content

Commit 08de2e9

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

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

test/playwright/SharedRendererTests.ts

Lines changed: 10 additions & 3 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 run = (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+
run(false);
1315+
});
1316+
test.describe('standalone tests (Shadow dom)', () => {
1317+
run(true);
13111318
});
13121319
}
13131320

@@ -1332,7 +1339,7 @@ function getCellColor(ctx: ITestContext, col: number, row: number, position: Cel
13321339
let frameDetails: { cols: number, rows: number, decoded: IImage32 } | undefined = undefined;
13331340
async function getFrameDetails(ctx: ITestContext): Promise<{ cols: number, rows: number, decoded: IImage32 }> {
13341341
const screenshotOptions: LocatorScreenshotOptions | undefined = process.env.DEBUG ? { path: 'out-esbuild-test/playwright/screenshot.png' } : undefined;
1335-
const buffer = await ctx.page.locator('#terminal-container .xterm-screen').screenshot(screenshotOptions);
1342+
const buffer = await ctx.page.locator('#terminal-container').locator('.xterm-screen').screenshot(screenshotOptions);
13361343
frameDetails = {
13371344
cols: await ctx.proxy.cols,
13381345
rows: await ctx.proxy.rows,

test/playwright/TestUtils.ts

Lines changed: 32 additions & 4 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 {
@@ -425,18 +425,46 @@ export async function openTerminal(ctx: ITestContext, options: ITerminalOptions
425425
strictEqual(await ctx.page.evaluate(`document.querySelector('#terminal-container').children.length`), 0, 'there must be no terminals on the page');
426426
await ctx.page.evaluate(`
427427
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);
429456
`);
457+
430458
// HACK: This is a soft layer breaker that's temporarily included until unicode graphemes have
431459
// more complete integration tests. See https://github.com/xtermjs/xterm.js/pull/4519#discussion_r1285234453
432-
if (testOptions.loadUnicodeGraphemesAddon) {
460+
if (loadUnicodeGraphemesAddon) {
433461
await ctx.page.evaluate(`
434462
window.unicode = new UnicodeGraphemesAddon();
435463
window.term.loadAddon(window.unicode);
436464
window.term.unicode.activeVersion = '15-graphemes';
437465
`);
438466
}
439-
await ctx.page.waitForSelector('.xterm-rows');
467+
await ctx.page.locator('.xterm-rows').waitFor();
440468
ctx.termHandle = await ctx.page.evaluateHandle('window.term');
441469
await ctx.proxy.initTerm();
442470
}

0 commit comments

Comments
 (0)