hass-taste-test 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as hass from 'home-assistant-js-websocket';
2
2
  import type { BrowserIntegration, BrowserPage, DashboardOptions, DiffOptions, LovelaceDashboardCreateParams, LovelaceResourceType } from './types.ts';
3
+ import { type HassEntityStates } from 'home-assistant-js-websocket';
3
4
  export { PlaywrightBrowser, PlaywrightPage, type PlaywrightElement, } from './integrations/playwright.ts';
4
5
  interface HassOptions<E> {
5
6
  hassArgs: string[];
@@ -110,7 +111,7 @@ export declare class HomeAssistant<E> {
110
111
  link(): Promise<string>;
111
112
  openInBrowser(): Promise<void>;
112
113
  }>;
113
- states(): Promise<hass.HassEntityStates>;
114
+ states(): Promise<HassEntityStates>;
114
115
  /** Clean up connections and stop the HomeAssistant server */
115
116
  close(): Promise<void>;
116
117
  HassDashboard: {
package/lib/index.js CHANGED
@@ -50,6 +50,9 @@ const home_assistant_js_websocket_1 = require("home-assistant-js-websocket");
50
50
  var playwright_ts_1 = require("./integrations/playwright.js");
51
51
  Object.defineProperty(exports, "PlaywrightBrowser", { enumerable: true, get: function () { return playwright_ts_1.PlaywrightBrowser; } });
52
52
  Object.defineProperty(exports, "PlaywrightPage", { enumerable: true, get: function () { return playwright_ts_1.PlaywrightPage; } });
53
+ /** First port tried for Home Assistant, and how many ports to cycle through before wrapping */
54
+ const FIRST_PORT = 8130;
55
+ const PORT_RANGE = 1000;
53
56
  /** Sleeps for 100 ms */
54
57
  const sleep = () => new Promise((r) => setTimeout(r, 100));
55
58
  /** Runs a command, rejecting if it cannot be started or exits with a non-zero code */
@@ -298,19 +301,21 @@ class HomeAssistant {
298
301
  }
299
302
  }
300
303
  async readCache() {
304
+ let cached = {};
305
+ let fresh = false;
301
306
  try {
302
- const versionFile = await fs.stat(this.path_cache());
303
- if (Date.now() - versionFile.mtimeMs < 2000) {
304
- const cache = JSON.parse(await fs.readFile(this.path_cache(), 'utf-8'));
305
- if (cache.requiresPython)
306
- return cache;
307
- }
307
+ const cacheFile = await fs.stat(this.path_cache());
308
+ cached = JSON.parse(await fs.readFile(this.path_cache(), 'utf-8'));
309
+ fresh = Date.now() - cacheFile.mtimeMs < 2000;
308
310
  }
309
311
  catch (e) { }
310
- return {
311
- ...(await this.latestHAVersion()),
312
- startPort: 8130,
313
- };
312
+ // Always continue from the last port handed out, even when the cache is stale.
313
+ let startPort = cached.startPort ?? FIRST_PORT;
314
+ if (!(startPort >= FIRST_PORT && startPort < FIRST_PORT + PORT_RANGE))
315
+ startPort = FIRST_PORT;
316
+ if (fresh && cached.requiresPython && cached.latestHass)
317
+ return { ...cached, startPort };
318
+ return { ...(await this.latestHAVersion()), startPort };
314
319
  }
315
320
  /** Fetch the latest hass version, and the Python versions it supports, from pypi */
316
321
  async latestHAVersion() {
@@ -55,6 +55,11 @@ class PlaywrightPage {
55
55
  return await element.evaluate(get_diffable_html_ts_1.getDiffableHTML, options);
56
56
  }
57
57
  async screenshot(element) {
58
+ // Playwright's `animations: 'disabled'` only finishes transitions that have already started.
59
+ // In Firefox and Chromium it doesn't flush styles first, so a state change that was just rendered
60
+ // may not have started its transition yet and gets captured on its first frame. Force a style
61
+ // flush so it starts and is fast-forwarded to its final state.
62
+ await element.evaluate((el) => el.getBoundingClientRect());
58
63
  // The frontend fades the page in when a dashboard opens. Finish those animations first so
59
64
  // the screenshot doesn't depend on how far along the fade is.
60
65
  return await element.screenshot({ animations: 'disabled' });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hass-taste-test",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Integration testing for Home Assistant cards",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  "devDependencies": {
36
36
  "@types/jest": "^30.0.0",
37
37
  "@types/jest-image-snapshot": "^6.4.2",
38
- "@types/node": "^22.0.0",
38
+ "@types/node": "^26.6.11",
39
39
  "@types/proper-lockfile": "^4.1.4",
40
40
  "@types/ws": "^8.18.2",
41
41
  "ava": "^8.5.0",
@@ -46,7 +46,7 @@
46
46
  "playwright": "^1.65.1",
47
47
  "prettier": "^3.10.1",
48
48
  "rimraf": "^6.1.4",
49
- "typescript": "~5.9.3"
49
+ "typescript": "~7.0.2"
50
50
  },
51
51
  "prettier": {
52
52
  "printWidth": 100,