hass-taste-test 0.2.7 → 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.
@@ -2,8 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PlaywrightPage = exports.PlaywrightBrowser = void 0;
4
4
  const playwright_1 = require("playwright");
5
- const fs_1 = require("fs");
6
- const htmlScript = (0, fs_1.readFileSync)(__dirname + '/../../lib/integrations/get-diffable-html.js', 'utf-8');
5
+ const get_diffable_html_ts_1 = require("./get-diffable-html.js");
7
6
  class PlaywrightBrowser {
8
7
  static browsers = { chromium: playwright_1.chromium, webkit: playwright_1.webkit, firefox: playwright_1.firefox };
9
8
  browserName;
@@ -53,11 +52,17 @@ class PlaywrightPage {
53
52
  async shadowHTML(element, options) {
54
53
  if (!element)
55
54
  throw new Error('shadowHTML expects a non-null element');
56
- const func = new Function('args', htmlScript + 'return getDiffableHTML(args[0], args[1])');
57
- return (await this.page.evaluate(func, [element, options]));
55
+ return await element.evaluate(get_diffable_html_ts_1.getDiffableHTML, options);
58
56
  }
59
57
  async screenshot(element) {
60
- return await element.screenshot();
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());
63
+ // The frontend fades the page in when a dashboard opens. Finish those animations first so
64
+ // the screenshot doesn't depend on how far along the fade is.
65
+ return await element.screenshot({ animations: 'disabled' });
61
66
  }
62
67
  async find(element, selector) {
63
68
  return await element.$(selector);
package/lib/socket.d.ts CHANGED
@@ -2,5 +2,5 @@
2
2
  * src/language-service/src/home-assistant/socket.ts from github.com/keesschollaart81/vscode-home-assistant
3
3
  * Licensed under the MIT license.
4
4
  ************************************************************************************************/
5
- import type { Auth } from 'home-assistant-js-websocket/dist/auth';
5
+ import type { Auth } from 'home-assistant-js-websocket';
6
6
  export declare function createSocket(auth: Auth, ignoreCertificates: boolean): Promise<any>;
package/lib/socket.js CHANGED
@@ -3,10 +3,13 @@
3
3
  * src/language-service/src/home-assistant/socket.ts from github.com/keesschollaart81/vscode-home-assistant
4
4
  * Licensed under the MIT license.
5
5
  ************************************************************************************************/
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
6
9
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.createSocket = void 0;
10
+ exports.createSocket = createSocket;
8
11
  // eslint-disable-next-line import/order
9
- const WebSocket = require("ws");
12
+ const ws_1 = __importDefault(require("ws"));
10
13
  const MSG_TYPE_AUTH_REQUIRED = 'auth_required';
11
14
  const MSG_TYPE_AUTH_INVALID = 'auth_invalid';
12
15
  const MSG_TYPE_AUTH_OK = 'auth_ok';
@@ -21,7 +24,7 @@ function createSocket(auth, ignoreCertificates) {
21
24
  function connect(triesLeft, promResolve, promReject) {
22
25
  if (DEBUG)
23
26
  console.log(`[Auth Phase] Connecting to Home Assistant... Tries left: ${triesLeft}`, url);
24
- const socket = new WebSocket(url, {
27
+ const socket = new ws_1.default(url, {
25
28
  rejectUnauthorized: !ignoreCertificates,
26
29
  });
27
30
  // If invalid auth, we will not try to reconnect.
@@ -105,4 +108,3 @@ function createSocket(auth, ignoreCertificates) {
105
108
  }
106
109
  return new Promise((resolve, reject) => connect(3, resolve, reject));
107
110
  }
108
- exports.createSocket = createSocket;
package/lib/types.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- /// <reference types="node" />
2
- interface IgnoreAttributesForTags {
1
+ export interface IgnoreAttributesForTags {
3
2
  /** tags on which to ignore the given attributes */
4
3
  tags: string[];
5
4
  /** attributes to ignore for the given tags */
@@ -48,4 +47,3 @@ export interface LovelaceDashboardCreateParams extends LovelaceDashboardMutableP
48
47
  url_path: string;
49
48
  mode: 'storage';
50
49
  }
51
- export {};
package/package.json CHANGED
@@ -1,12 +1,22 @@
1
1
  {
2
2
  "name": "hass-taste-test",
3
- "version": "0.2.7",
3
+ "version": "0.3.1",
4
4
  "description": "Integration testing for Home Assistant cards",
5
5
  "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./lib/index.d.ts",
10
+ "default": "./lib/index.js"
11
+ }
12
+ },
6
13
  "scripts": {
7
- "test": "jest && ava",
8
- "prepare": "husky install",
9
- "prepublishOnly": "tsc"
14
+ "test": "npm run test:jest && ava",
15
+ "test:jest": "node --experimental-vm-modules --disable-warning=ExperimentalWarning node_modules/jest/bin/jest.js",
16
+ "typecheck": "tsc",
17
+ "build": "rimraf lib && tsc -p tsconfig.build.json",
18
+ "prepare": "husky",
19
+ "prepublishOnly": "npm run build"
10
20
  },
11
21
  "bin": {
12
22
  "hass-taste-test": "lib/bin.js"
@@ -14,28 +24,29 @@
14
24
  "author": "rianadon",
15
25
  "homepage": "https://github.com/rianadon/hass-taste-test#readme",
16
26
  "license": "AGPL-3.0-or-later",
27
+ "engines": {
28
+ "node": ">=18"
29
+ },
17
30
  "dependencies": {
18
- "home-assistant-js-websocket": "^8.2.0",
19
- "node-fetch": "^2.6.4",
31
+ "home-assistant-js-websocket": "^9.9.0",
20
32
  "proper-lockfile": "^4.1.2",
21
- "ws": "^8.13.0"
33
+ "ws": "^8.23.0"
22
34
  },
23
35
  "devDependencies": {
24
- "@types/jest": "^29.5.3",
25
- "@types/jest-image-snapshot": "^6.1.0",
26
- "@types/node-fetch": "^2.6.4",
27
- "@types/proper-lockfile": "^4.1.2",
28
- "@types/ws": "^8.5.5",
29
- "ava": "^5.3.1",
30
- "husky": "^8.0.3",
31
- "jest": "^29.6.1",
32
- "jest-image-snapshot": "^6.1.0",
33
- "lint-staged": "^13.2.3",
34
- "playwright": "^1.36.1",
35
- "prettier": "^3.0.0",
36
- "ts-jest": "^29.1.1",
37
- "ts-node": "^10.9.1",
38
- "typescript": "^5.1.6"
36
+ "@types/jest": "^30.0.0",
37
+ "@types/jest-image-snapshot": "^6.4.2",
38
+ "@types/node": "^26.6.11",
39
+ "@types/proper-lockfile": "^4.1.4",
40
+ "@types/ws": "^8.18.2",
41
+ "ava": "^8.5.0",
42
+ "husky": "^9.1.7",
43
+ "jest": "^30.5.2",
44
+ "jest-image-snapshot": "^6.5.2",
45
+ "lint-staged": "^17.6.2",
46
+ "playwright": "^1.65.1",
47
+ "prettier": "^3.10.1",
48
+ "rimraf": "^6.1.4",
49
+ "typescript": "~7.0.2"
39
50
  },
40
51
  "prettier": {
41
52
  "printWidth": 100,
@@ -49,18 +60,18 @@
49
60
  ],
50
61
  "extensions": [
51
62
  "ts"
52
- ],
53
- "require": [
54
- "ts-node/register"
55
63
  ]
56
64
  },
57
65
  "jest": {
58
66
  "rootDir": "test",
59
- "preset": "ts-jest",
60
67
  "testEnvironment": "node",
61
68
  "testMatch": [
62
69
  "**/*.jest.ts"
63
- ]
70
+ ],
71
+ "extensionsToTreatAsEsm": [
72
+ ".ts"
73
+ ],
74
+ "transform": {}
64
75
  },
65
76
  "lint-staged": {
66
77
  "*.{ts,js,json,css,md}": "prettier --write"
@@ -1,103 +0,0 @@
1
- /// <reference types="node" />
2
- import * as hass from 'home-assistant-js-websocket';
3
- import { BrowserPage, DashboardOptions, DiffOptions, LovelaceDashboardCreateParams, LovelaceResourceType } from './types';
4
- import { BrowserIntegration } from './types';
5
- interface HassTestOptions<E> {
6
- python: string;
7
- hassArgs: string[];
8
- host: string;
9
- port: number | null;
10
- username: string;
11
- password: string;
12
- userLanguage: string;
13
- userDisplayName: string;
14
- customComponents: string[];
15
- integration?: BrowserIntegration<E>;
16
- }
17
- export default class HassTest<E> {
18
- private config;
19
- private venvDir;
20
- private configDir;
21
- private cache;
22
- private chosenPort;
23
- private process;
24
- private accessCode;
25
- private accessToken;
26
- private options;
27
- private dashboards;
28
- ws: hass.Connection;
29
- constructor(config: string, options?: Partial<HassTestOptions<E>>);
30
- private path_confFile;
31
- private path_componentsDir;
32
- private path_wwwDir;
33
- private path_hass;
34
- private path_pip;
35
- private path_cache;
36
- /** Start the HomeAssistant server and connect to its websocket */
37
- start(): Promise<void>;
38
- /** Write configuration.yaml */
39
- private writeYAMLConfiguration;
40
- /** Symlink custom component directories to the configuration directory */
41
- private linkComponents;
42
- /** Wait for lockfile to become released. Forces HassTest instances to start up one at a time */
43
- private acquireLock;
44
- /** Find an open port to launch Home Assistant */
45
- private findPort;
46
- /** Creates a python virtual environment and installs Home Assistant */
47
- private setupVenv;
48
- private readCache;
49
- /** Fetch the latest hass version from online, caching for 2 minutes */
50
- private latestHAVersion;
51
- /** Finds the version of Home Assistant installed */
52
- private hassVersion;
53
- /** Checks if Home Assistant is listening on its TCP port */
54
- private isUp;
55
- /** Complete onboarding and fetch short-lived access token */
56
- onboard(): Promise<void>;
57
- get url(): string;
58
- get clientId(): string;
59
- get link(): string;
60
- customDashboard(name: string, code?: string): string;
61
- post(url: string, body: any, authorize?: boolean): Promise<any>;
62
- /** Fetch a access code from username and password */
63
- fetchLoginCode(): Promise<any>;
64
- /** Login and create tokens and websocket */
65
- login(): Promise<void>;
66
- private launchWebsocket;
67
- addIntegration(name: string): Promise<any>;
68
- addResource(filename: string, resourceType: LovelaceResourceType): Promise<void>;
69
- createDashboard(options?: Partial<LovelaceDashboardCreateParams>): Promise<string>;
70
- setDashboardView(dashboard_path: string, config: object[]): Promise<void>;
71
- callService(domain: string, service: string, serviceData?: object, target?: hass.HassServiceTarget): Promise<unknown>;
72
- Dashboard(config: object[], options?: DashboardOptions): Promise<{
73
- cards: HassCard<E>[];
74
- parent: HassTest<E>;
75
- name: string;
76
- link(): Promise<string>;
77
- openInBrowser(): Promise<void>;
78
- }>;
79
- /** Clean up connections and stop the HomeAssistant server */
80
- close(): Promise<void>;
81
- HassDashboard: {
82
- new (parent: HassTest<E>, name: string, config: object[], page: BrowserPage<E>): {
83
- cards: HassCard<E>[];
84
- parent: HassTest<E>;
85
- name: string;
86
- link(): Promise<string>;
87
- openInBrowser(): Promise<void>;
88
- };
89
- };
90
- }
91
- export declare class HassCard<E> {
92
- private n;
93
- private page;
94
- private selectors;
95
- constructor(n: number, page: BrowserPage<E>, selectors?: string[]);
96
- private element;
97
- narrow(selector: string): HassCard<E>;
98
- html(options?: DiffOptions): Promise<string>;
99
- text(): Promise<string>;
100
- screenshot(): Promise<Buffer>;
101
- }
102
- export declare function multiply(n: number, configFn: (i: number) => string): string;
103
- export {};