Skip to content

Commit 7b1f0b0

Browse files
committed
fix
1 parent ebcba9a commit 7b1f0b0

7 files changed

Lines changed: 54 additions & 23 deletions

File tree

.github/workflows/e2e.yaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,18 @@ jobs:
214214
name: gallery-dist
215215
path: gallery/dist/
216216

217+
# Set up BrowserStack credentials
218+
- name: Set up BrowserStack
219+
uses: browserstack/github-actions@93aebce225b754566349151c0676b26b005e591b # v1.0.4
220+
with:
221+
username: ${{ secrets.BROWSERSTACK_USERNAME }}
222+
access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
223+
217224
# Start BrowserStack Local tunnel so BrowserStack's cloud browsers can
218-
# reach the tests running on localhost:5000.
225+
# reach the tests running on localhost.
219226
- name: Start BrowserStack Local tunnel
220-
uses: browserstack/github-actions@d6cb8baf7febe9aabf62ac7a9c449a03076f1289 # master
227+
uses: browserstack/github-actions/setup-local@93aebce225b754566349151c0676b26b005e591b # v1.0.4
221228
with:
222-
action: start
223229
local-testing: start
224230
local-identifier: ${{ env.BROWSERSTACK_LOCAL_IDENTIFIER }}
225231

@@ -230,10 +236,10 @@ jobs:
230236
BROWSERSTACK_LOCAL_IDENTIFIER: ${{ env.BROWSERSTACK_LOCAL_IDENTIFIER }}
231237

232238
- name: Stop BrowserStack Local tunnel
233-
uses: browserstack/github-actions@d6cb8baf7febe9aabf62ac7a9c449a03076f1289 # master
239+
uses: browserstack/github-actions/setup-local@93aebce225b754566349151c0676b26b005e591b # v1.0.4
234240
if: always()
235241
with:
236-
action: stop
242+
local-testing: stop
237243
local-identifier: ${{ env.BROWSERSTACK_LOCAL_IDENTIFIER }}
238244

239245
- name: Upload blob report

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
"postpack": "pinst --enable",
2222
"test": "vitest run --config test/vitest.config.ts",
2323
"test:coverage": "vitest run --config test/vitest.config.ts --coverage",
24-
"test:e2e": "yarn test:e2e:demo && yarn test:e2e:app && yarn test:e2e:gallery && node -e \"const {cpSync,mkdirSync,rmSync,readdirSync}=require('fs');const d='test/e2e/reports/blob';rmSync(d,{recursive:true,force:true});mkdirSync(d,{recursive:true});['demo','app','gallery'].forEach(s=>{readdirSync('test/e2e/reports/'+s).filter(f=>f.endsWith('.zip')).forEach(f=>cpSync('test/e2e/reports/'+s+'/'+f,d+'/'+s+'-'+f))})\" && npx playwright merge-reports -c test/e2e/playwright.merge.config.ts test/e2e/reports/blob && yarn playwright show-report test/e2e/reports/combined",
25-
"test:e2e:local": "yarn test:e2e:demo:local && yarn test:e2e:app:local && yarn test:e2e:gallery:local && node -e \"const {cpSync,mkdirSync,rmSync,readdirSync}=require('fs');const d='test/e2e/reports/blob';rmSync(d,{recursive:true,force:true});mkdirSync(d,{recursive:true});['demo','app','gallery'].forEach(s=>{readdirSync('test/e2e/reports/'+s).filter(f=>f.endsWith('.zip')).forEach(f=>cpSync('test/e2e/reports/'+s+'/'+f,d+'/'+s+'-'+f))})\" && npx playwright merge-reports -c test/e2e/playwright.merge.config.ts test/e2e/reports/blob && yarn playwright show-report test/e2e/reports/combined",
26-
"test:e2e:browserstack": "yarn test:e2e:demo:browserstack && yarn test:e2e:app:browserstack && yarn test:e2e:gallery:browserstack && node -e \"const {cpSync,mkdirSync,rmSync,readdirSync}=require('fs');const d='test/e2e/reports/blob';rmSync(d,{recursive:true,force:true});mkdirSync(d,{recursive:true});['demo','app','gallery'].forEach(s=>{readdirSync('test/e2e/reports/'+s).filter(f=>f.endsWith('.zip')).forEach(f=>cpSync('test/e2e/reports/'+s+'/'+f,d+'/'+s+'-'+f))})\" && npx playwright merge-reports -c test/e2e/playwright.merge.config.ts test/e2e/reports/blob && yarn playwright show-report test/e2e/reports/combined",
24+
"test:e2e": "yarn test:e2e:demo && yarn test:e2e:app && yarn test:e2e:gallery && node test/e2e/collect-blob-reports.mjs && npx playwright merge-reports -c test/e2e/playwright.merge.config.ts test/e2e/reports/blob",
25+
"test:e2e:local": "yarn test:e2e:demo:local && yarn test:e2e:app:local && yarn test:e2e:gallery:local && node test/e2e/collect-blob-reports.mjs && npx playwright merge-reports -c test/e2e/playwright.merge.config.ts test/e2e/reports/blob",
26+
"test:e2e:browserstack": "yarn test:e2e:demo:browserstack && yarn test:e2e:app:browserstack && yarn test:e2e:gallery:browserstack && node test/e2e/collect-blob-reports.mjs && npx playwright merge-reports -c test/e2e/playwright.merge.config.ts test/e2e/reports/blob",
27+
"test:e2e:show-report": "yarn playwright show-report test/e2e/reports/combined",
2728
"test:e2e:demo": "playwright test --config test/e2e/playwright.demo.config.ts",
2829
"test:e2e:demo:local": "playwright test --config test/e2e/playwright.demo.config.ts --project=local",
2930
"test:e2e:demo:browserstack": "BROWSERSTACK=true playwright test --config test/e2e/playwright.demo.config.ts --project=browserstack-*",

test/e2e/app.spec.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,14 @@ test.describe("Theming", () => {
206206
test("dark theme sets darkMode flag", async ({ page }) => {
207207
await goToPanel(page, "/?scenario=dark-theme");
208208

209-
// Verify the app initialized correctly in dark-theme scenario (no crash)
210209
await expect(page.locator("ha-test")).toBeAttached();
211210

212-
// The dark-theme scenario sets themes.darkMode=true; after the themes
213-
// subscription fires it may be overridden by prefers-color-scheme, but
214-
// we can verify updateHass was called by checking the element loaded.
215-
const haTestLoaded = await page.evaluate(() => {
216-
const el = document.querySelector("ha-test") as any;
217-
return Boolean(el?.hass);
218-
});
219-
expect(haTestLoaded).toBe(true);
211+
// The dark-theme scenario calls updateHass({ themes: { darkMode: true } });
212+
// verify that flag is actually set on the mock hass object.
213+
const darkMode = await page.evaluate(
214+
() => (window.__mockHass as any)?.themes?.darkMode
215+
);
216+
expect(darkMode).toBe(true);
220217
});
221218

222219
test("custom theme applies CSS variables", async ({ page }) => {

test/e2e/app/src/ha-test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ export class HaTest extends HomeAssistantAppEl {
5555
const initial: Partial<MockHomeAssistant> = {
5656
// Use the full panel map (history + config + developer-tools enabled)
5757
panels: e2eTestPanels,
58-
panelUrl: (this as any)._panelUrl,
58+
panelUrl: (() => {
59+
const path = window.location.pathname;
60+
const dividerPos = path.indexOf("/", 1);
61+
return dividerPos === -1
62+
? path.substring(1)
63+
: path.substring(1, dividerPos);
64+
})(),
5965
updateHass: (hassUpdate: Partial<HomeAssistant>) =>
6066
this._updateHass(hassUpdate),
6167
};
@@ -120,7 +126,7 @@ export class HaTest extends HomeAssistantAppEl {
120126
{ capture: true }
121127
);
122128

123-
(this as any).hassConnected();
129+
this.hassConnected();
124130
}
125131
}
126132

test/e2e/collect-blob-reports.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env node
2+
// Collects blob reports from each suite into a single staging directory so
3+
// `playwright merge-reports` can consume them from one path.
4+
//
5+
// Usage: node test/e2e/collect-blob-reports.mjs
6+
7+
import { cpSync, mkdirSync, readdirSync, rmSync } from "fs";
8+
9+
const dest = "test/e2e/reports/blob";
10+
rmSync(dest, { recursive: true, force: true });
11+
mkdirSync(dest, { recursive: true });
12+
13+
for (const suite of ["demo", "app", "gallery"]) {
14+
const src = `test/e2e/reports/${suite}`;
15+
for (const file of readdirSync(src).filter((f) => f.endsWith(".zip"))) {
16+
cpSync(`${src}/${file}`, `${dest}/${suite}-${file}`);
17+
}
18+
}

test/e2e/gallery.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ async function goToGalleryPage(page: Page, hash: string) {
1818
// First visit to let ha-gallery boot up
1919
await page.goto(`/#${hash}`);
2020
await page.waitForSelector("ha-gallery", { state: "attached" });
21-
// Gallery uses dynamic imports; give it time to load the page component
22-
await page.waitForTimeout(1500);
21+
// Wait for the gallery to finish rendering the page content inside its shadow root
22+
await page.waitForFunction(() => {
23+
const gallery = document.querySelector("ha-gallery") as any;
24+
return gallery?.shadowRoot?.querySelector("page-description") != null;
25+
});
2326
}
2427

2528
/** Assert a gallery page loads without console errors.

test/vitest.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { defineConfig } from "vitest/config";
1+
import { defineConfig, configDefaults } from "vitest/config";
22
import tsconfigPaths from "vite-tsconfig-paths";
33

44
export default defineConfig({
55
plugins: [tsconfigPaths()],
66
test: {
7-
exclude: ["test/e2e/**"],
7+
exclude: [...configDefaults.exclude, "test/e2e/**"],
88
environment: "jsdom", // to run in browser-like environment
99
env: {
1010
TZ: "Etc/UTC",

0 commit comments

Comments
 (0)