chore: add webgl shadow dom test
This commit is contained in:
@@ -1280,10 +1280,10 @@ enum CellColorPosition {
|
|||||||
* treatment.
|
* treatment.
|
||||||
*/
|
*/
|
||||||
export function injectSharedRendererTestsStandalone(ctx: ISharedRendererTestContext, setupCb: () => Promise<void> | void): void {
|
export function injectSharedRendererTestsStandalone(ctx: ISharedRendererTestContext, setupCb: () => Promise<void> | void): void {
|
||||||
test.describe('standalone tests', () => {
|
const setupTests = ({ shadowDom }: { shadowDom: boolean }): void => {
|
||||||
test.beforeEach(async () => {
|
test.beforeEach(async () => {
|
||||||
// Recreate terminal
|
// Recreate terminal
|
||||||
await openTerminal(ctx.value);
|
await openTerminal(ctx.value, {}, { useShadowDom: shadowDom });
|
||||||
await ctx.value.page.evaluate(`
|
await ctx.value.page.evaluate(`
|
||||||
window.term.options.minimumContrastRatio = 1;
|
window.term.options.minimumContrastRatio = 1;
|
||||||
window.term.options.allowTransparency = false;
|
window.term.options.allowTransparency = false;
|
||||||
@@ -1308,6 +1308,13 @@ export function injectSharedRendererTestsStandalone(ctx: ISharedRendererTestCont
|
|||||||
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 1, 1), [0, 0, 0, 255]);
|
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 1, 1), [0, 0, 0, 255]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
test.describe('standalone tests', () => {
|
||||||
|
setupTests({ shadowDom: false });
|
||||||
|
});
|
||||||
|
test.describe('standalone tests (Shadow dom)', () => {
|
||||||
|
setupTests({ shadowDom: true });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -412,7 +412,7 @@ class TerminalCoreProxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function openTerminal(ctx: ITestContext, options: ITerminalOptions | ITerminalInitOnlyOptions = {}, testOptions: { loadUnicodeGraphemesAddon: boolean } = { loadUnicodeGraphemesAddon: true }): Promise<void> {
|
export async function openTerminal(ctx: ITestContext, options: ITerminalOptions | ITerminalInitOnlyOptions = {}, { useShadowDom = false, loadUnicodeGraphemesAddon = true }: { loadUnicodeGraphemesAddon?: boolean, useShadowDom?: boolean } = { }): Promise<void> {
|
||||||
await ctx.page.evaluate(`
|
await ctx.page.evaluate(`
|
||||||
if ('term' in window) {
|
if ('term' in window) {
|
||||||
try {
|
try {
|
||||||
@@ -423,13 +423,48 @@ export async function openTerminal(ctx: ITestContext, options: ITerminalOptions
|
|||||||
// HACK: Tests may have side effects that could cause the terminal not to be removed. This
|
// HACK: Tests may have side effects that could cause the terminal not to be removed. This
|
||||||
// assertion catches this case early.
|
// assertion catches this case early.
|
||||||
strictEqual(await ctx.page.evaluate(`document.querySelector('#terminal-container').children.length`), 0, 'there must be no terminals on the page');
|
strictEqual(await ctx.page.evaluate(`document.querySelector('#terminal-container').children.length`), 0, 'there must be no terminals on the page');
|
||||||
await ctx.page.evaluate(`
|
|
||||||
|
let script = `
|
||||||
window.term = new window.Terminal(${JSON.stringify({ allowProposedApi: true, ...options })});
|
window.term = new window.Terminal(${JSON.stringify({ allowProposedApi: true, ...options })});
|
||||||
window.term.open(document.querySelector('#terminal-container'));
|
let element = document.querySelector('#terminal-container');
|
||||||
`);
|
|
||||||
|
// Remove shadow root if it exists
|
||||||
|
const newElement = element.cloneNode(false);
|
||||||
|
element.replaceWith(newElement);
|
||||||
|
element = newElement
|
||||||
|
`;
|
||||||
|
|
||||||
|
|
||||||
|
if (useShadowDom) {
|
||||||
|
script += `
|
||||||
|
const shadowRoot = element.attachShadow({ mode: "open" });
|
||||||
|
|
||||||
|
// Copy parent styles to shadow DOM
|
||||||
|
const styles = Array.from(document.querySelectorAll('link[rel="stylesheet"]'));
|
||||||
|
styles.forEach((styleEl) => {
|
||||||
|
const clone = document.createElement('link');
|
||||||
|
clone.rel = 'stylesheet';
|
||||||
|
clone.href = styleEl.href;
|
||||||
|
shadowRoot.appendChild(clone);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create new element inside the shadow DOM
|
||||||
|
element = document.createElement('div');
|
||||||
|
element.style.width = '100%';
|
||||||
|
element.style.height = '100%';
|
||||||
|
shadowRoot.appendChild(element);
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
script += `
|
||||||
|
window.term.open(element);
|
||||||
|
`;
|
||||||
|
|
||||||
|
await ctx.page.evaluate(script);
|
||||||
|
|
||||||
// HACK: This is a soft layer breaker that's temporarily included until unicode graphemes have
|
// HACK: This is a soft layer breaker that's temporarily included until unicode graphemes have
|
||||||
// more complete integration tests. See https://github.com/xtermjs/xterm.js/pull/4519#discussion_r1285234453
|
// more complete integration tests. See https://github.com/xtermjs/xterm.js/pull/4519#discussion_r1285234453
|
||||||
if (testOptions.loadUnicodeGraphemesAddon) {
|
if (loadUnicodeGraphemesAddon) {
|
||||||
await ctx.page.evaluate(`
|
await ctx.page.evaluate(`
|
||||||
window.unicode = new UnicodeGraphemesAddon();
|
window.unicode = new UnicodeGraphemesAddon();
|
||||||
window.term.loadAddon(window.unicode);
|
window.term.loadAddon(window.unicode);
|
||||||
|
|||||||
Reference in New Issue
Block a user