Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 0 additions & 128 deletions packages/webui-framework/src/element/styles.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,26 @@ test.describe(`css module fixture [${mode} DOM]`, () => {
});

test('client-created components adopt module styles from registered specifiers', async ({ page }) => {
const before = await page.locator('test-module-host').evaluate((host) => {
const label = (host.shadowRoot ?? host).querySelector('.host-label');
// In shadow DOM mode, stylesheets are on shadowRoot.
// In light DOM mode, styles are injected into document head.
const sr = host.shadowRoot;
const sheetCount = sr
? sr.adoptedStyleSheets?.length ?? 0
: document.querySelectorAll('style').length > 0 ? 1 : 0;
return {
hasStyles: sheetCount > 0,
hostColor: label instanceof HTMLElement ? getComputedStyle(label).color : null,
};
});

expect(before.hasStyles).toBe(true);
expect(before.hostColor).toBe('rgb(0, 102, 204)');
// Wait for async CSS module injection (import().then() in injectModuleStyle)
await expect(async () => {
const hostColor = await page.locator('test-module-host').evaluate((host) => {
const label = (host.shadowRoot ?? host).querySelector('.host-label');
return label instanceof HTMLElement ? getComputedStyle(label).color : null;
});
expect(hostColor).toBe('rgb(0, 102, 204)');
}).toPass({ timeout: 5_000 });

await page.locator('test-module-host .spawn').click();

const after = await page.locator('test-module-host').evaluate((host) => {
const child = (host.shadowRoot ?? host).querySelector('test-module-child');
const label = (child?.shadowRoot ?? child)?.querySelector('.child-label');
return {
childColor: label instanceof HTMLElement ? getComputedStyle(label).color : null,
};
});

expect(after.childColor).toBe('rgb(178, 34, 34)');
// Wait for async CSS module adoption on the dynamically-created child
await expect(async () => {
const childColor = await page.locator('test-module-host').evaluate((host) => {
const child = (host.shadowRoot ?? host).querySelector('test-module-child');
const label = (child?.shadowRoot ?? child)?.querySelector('.child-label');
return label instanceof HTMLElement ? getComputedStyle(label).color : null;
});
expect(childColor).toBe('rgb(178, 34, 34)');
}).toPass({ timeout: 5_000 });
});
});
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>CSS Module Fixture</title>
<style type="module" specifier="test-module-host">.host-label{color:rgb(0, 102, 204);}</style>
<style type="module" specifier="test-module-child">.child-label{color:rgb(178, 34, 34);}</style>
<style type="module" specifier="test-module-host">
.host-label{color:rgb(0, 102, 204);}
</style>
<style type="module" specifier="test-module-child">
.child-label{color:rgb(178, 34, 34);}
</style>
</head>

<body>
<test-module-host></test-module-host>
<script>window.__webui_shadow=true;</script><script src="/dist/css-module/element.js"></script>
<test-module-host>
<template shadowrootmode="open" shadowrootadoptedstylesheets="test-module-host"><button class="spawn">Spawn</button>
<p class="host-label">Host</p>
<div class="slot"></div>
</template>
</test-module-host>
<script>window.__webui_shadow = true;</script>
<script src="/dist/css-module/element.js"></script>
</body>
</html>

</html>
19 changes: 15 additions & 4 deletions packages/webui-framework/tests/fixtures/css-module/fixture.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>CSS Module Fixture</title>
<style type="module" specifier="test-module-host">.host-label{color:rgb(0, 102, 204);}</style>
<style type="module" specifier="test-module-child">.child-label{color:rgb(178, 34, 34);}</style>
<style type="module" specifier="test-module-host">
.host-label{color:rgb(0, 102, 204);}
</style>
<style type="module" specifier="test-module-child">
.child-label{color:rgb(178, 34, 34);}
</style>
</head>

<body>
<test-module-host></test-module-host>
<test-module-host>
<button class="spawn">Spawn</button>
<p class="host-label">Host</p>
<div class="slot"></div>
</test-module-host>
<script src="/dist/css-module/element.js"></script>
</body>
</html>

</html>
1 change: 1 addition & 0 deletions packages/webui-test-support/src/fixture-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export async function buildFixtureEntries({
outbase: fixturesRoot,
platform: 'browser',
target: 'es2022',
supported: { 'import-attributes': true },
tsconfig,
logLevel: 'info',
});
Expand Down
Loading