hass-taste-test 0.1.0 → 0.2.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 +2 -0
- package/lib/index.js +9 -3
- package/lib/integrations/playwright.d.ts +4 -2
- package/lib/integrations/playwright.js +8 -2
- package/lib/types.d.ts +3 -2
- package/package.json +19 -18
package/lib/index.d.ts
CHANGED
|
@@ -77,6 +77,7 @@ export declare class HomeAssistant<E> {
|
|
|
77
77
|
cards: HassCard<E>[];
|
|
78
78
|
parent: HomeAssistant<E>;
|
|
79
79
|
path: string;
|
|
80
|
+
page: BrowserPage<E>;
|
|
80
81
|
link(): Promise<string>;
|
|
81
82
|
openInBrowser(): Promise<void>;
|
|
82
83
|
}>;
|
|
@@ -87,6 +88,7 @@ export declare class HomeAssistant<E> {
|
|
|
87
88
|
cards: HassCard<E>[];
|
|
88
89
|
parent: HomeAssistant<E>;
|
|
89
90
|
path: string;
|
|
91
|
+
page: BrowserPage<E>;
|
|
90
92
|
link(): Promise<string>;
|
|
91
93
|
openInBrowser(): Promise<void>;
|
|
92
94
|
};
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -348,8 +352,8 @@ class HomeAssistant {
|
|
|
348
352
|
mode: 'storage',
|
|
349
353
|
require_admin: false,
|
|
350
354
|
show_in_sidebar: true,
|
|
351
|
-
title: `Dashboard ${id}`,
|
|
352
355
|
...options,
|
|
356
|
+
title: options?.title || `Dashboard ${id}`,
|
|
353
357
|
};
|
|
354
358
|
await this.ws.sendMessagePromise(args);
|
|
355
359
|
return args.url_path;
|
|
@@ -372,7 +376,7 @@ class HomeAssistant {
|
|
|
372
376
|
async Dashboard(config, options) {
|
|
373
377
|
if (!this.options.browser)
|
|
374
378
|
throw new Error('Cannot launch a dashboard without a browser integration. Make sure to specify options.integration');
|
|
375
|
-
const dashboard = await this.createDashboard();
|
|
379
|
+
const dashboard = await this.createDashboard({ title: options?.title });
|
|
376
380
|
await this.setDashboardView(dashboard, config);
|
|
377
381
|
const code = await this.fetchLoginCode();
|
|
378
382
|
const page = await this.options.browser.open(this.customDashboard(dashboard, code), options || {});
|
|
@@ -394,10 +398,12 @@ class HomeAssistant {
|
|
|
394
398
|
HassDashboard = class {
|
|
395
399
|
parent;
|
|
396
400
|
path;
|
|
401
|
+
page;
|
|
397
402
|
cards = [];
|
|
398
403
|
constructor(parent, path, config, page) {
|
|
399
404
|
this.parent = parent;
|
|
400
405
|
this.path = path;
|
|
406
|
+
this.page = page;
|
|
401
407
|
for (let i = 0; i < config.length; i++) {
|
|
402
408
|
this.cards.push(new HassCard(i, page));
|
|
403
409
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { ElementHandle, Page, LaunchOptions } from 'playwright';
|
|
2
|
+
import { Browser, ElementHandle, Page, LaunchOptions, BrowserContext } from 'playwright';
|
|
3
3
|
import { BrowserIntegration, BrowserPage, DashboardOptions, DiffOptions } from '../types';
|
|
4
|
-
export
|
|
4
|
+
export type PlaywrightElement = ElementHandle<Node>;
|
|
5
5
|
export declare class PlaywrightBrowser implements BrowserIntegration<PlaywrightElement> {
|
|
6
6
|
private static browsers;
|
|
7
7
|
private browserName;
|
|
8
8
|
private browserPromise;
|
|
9
9
|
constructor(browserName: string, options?: LaunchOptions);
|
|
10
|
+
newPage(browser: Browser | BrowserContext): Promise<Page>;
|
|
10
11
|
open(url: string, options: DashboardOptions): Promise<PlaywrightPage>;
|
|
11
12
|
openInHeaded(url: string): Promise<void>;
|
|
12
13
|
close(): Promise<void>;
|
|
@@ -19,4 +20,5 @@ export declare class PlaywrightPage implements BrowserPage<PlaywrightElement> {
|
|
|
19
20
|
screenshot(element: PlaywrightElement): Promise<Buffer>;
|
|
20
21
|
find(element: PlaywrightElement, selector: string): Promise<ElementHandle<SVGElement | HTMLElement> | null>;
|
|
21
22
|
textContent(element: PlaywrightElement): Promise<string>;
|
|
23
|
+
get playwright(): Page;
|
|
22
24
|
}
|
|
@@ -14,6 +14,9 @@ class PlaywrightBrowser {
|
|
|
14
14
|
this.browserName = browserName;
|
|
15
15
|
this.browserPromise = PlaywrightBrowser.browsers[browserName].launch(options);
|
|
16
16
|
}
|
|
17
|
+
async newPage(browser) {
|
|
18
|
+
return await browser.newPage();
|
|
19
|
+
}
|
|
17
20
|
async open(url, options) {
|
|
18
21
|
let browser = await this.browserPromise;
|
|
19
22
|
if (options) {
|
|
@@ -21,7 +24,7 @@ class PlaywrightBrowser {
|
|
|
21
24
|
colorScheme: options.colorScheme,
|
|
22
25
|
});
|
|
23
26
|
}
|
|
24
|
-
const page = await
|
|
27
|
+
const page = await this.newPage(browser);
|
|
25
28
|
await page.goto(url);
|
|
26
29
|
return new PlaywrightPage(page);
|
|
27
30
|
}
|
|
@@ -29,7 +32,7 @@ class PlaywrightBrowser {
|
|
|
29
32
|
const browser = await PlaywrightBrowser.browsers[this.browserName].launch({
|
|
30
33
|
headless: false,
|
|
31
34
|
});
|
|
32
|
-
const page = await
|
|
35
|
+
const page = await this.newPage(browser);
|
|
33
36
|
await page.goto(url);
|
|
34
37
|
await page.waitForEvent('close', { timeout: 0 });
|
|
35
38
|
}
|
|
@@ -65,5 +68,8 @@ class PlaywrightPage {
|
|
|
65
68
|
throw new Error('Element has no textcontent');
|
|
66
69
|
return content;
|
|
67
70
|
}
|
|
71
|
+
get playwright() {
|
|
72
|
+
return this.page;
|
|
73
|
+
}
|
|
68
74
|
}
|
|
69
75
|
exports.PlaywrightPage = PlaywrightPage;
|
package/lib/types.d.ts
CHANGED
|
@@ -21,8 +21,9 @@ export interface DiffOptions {
|
|
|
21
21
|
/** whether to strip attributes from Lit & Polymer with undefined values */
|
|
22
22
|
stripUndefinedAttributes: boolean;
|
|
23
23
|
}
|
|
24
|
-
export
|
|
24
|
+
export type DashboardOptions = Partial<{
|
|
25
25
|
colorScheme: 'light' | 'dark' | 'no-preference';
|
|
26
|
+
title: string;
|
|
26
27
|
}>;
|
|
27
28
|
export interface BrowserIntegration<E> {
|
|
28
29
|
open(url: string, options: DashboardOptions): Promise<BrowserPage<E>>;
|
|
@@ -36,7 +37,7 @@ export interface BrowserPage<E> {
|
|
|
36
37
|
screenshot(element: E): Promise<Buffer>;
|
|
37
38
|
find(element: E, selector: string): Promise<E | null | undefined>;
|
|
38
39
|
}
|
|
39
|
-
export
|
|
40
|
+
export type LovelaceResourceType = 'css' | 'js' | 'module' | 'html';
|
|
40
41
|
export interface LovelaceDashboardMutableParams {
|
|
41
42
|
require_admin: boolean;
|
|
42
43
|
show_in_sidebar: boolean;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hass-taste-test",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Integration testing for Home Assistant cards",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "jest && ava",
|
|
8
8
|
"prepare": "husky install",
|
|
9
|
-
"
|
|
9
|
+
"prepublishOnly": "tsc"
|
|
10
10
|
},
|
|
11
11
|
"bin": {
|
|
12
12
|
"hass-taste-test": "lib/bin.js"
|
|
@@ -15,26 +15,27 @@
|
|
|
15
15
|
"homepage": "https://github.com/rianadon/hass-taste-test#readme",
|
|
16
16
|
"license": "AGPL-3.0-or-later",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"home-assistant-js-websocket": "^
|
|
18
|
+
"home-assistant-js-websocket": "^8.0.1",
|
|
19
19
|
"node-fetch": "^2.6.1",
|
|
20
|
-
"proper-lockfile": "^4.1.2"
|
|
20
|
+
"proper-lockfile": "^4.1.2",
|
|
21
|
+
"ws": "^8.11.0"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
|
-
"@types/jest": "^
|
|
24
|
-
"@types/jest-image-snapshot": "^
|
|
25
|
-
"@types/node-fetch": "^2.
|
|
24
|
+
"@types/jest": "^29.2.4",
|
|
25
|
+
"@types/jest-image-snapshot": "^6.1.0",
|
|
26
|
+
"@types/node-fetch": "^2.6.2",
|
|
26
27
|
"@types/proper-lockfile": "^4.1.2",
|
|
27
|
-
"@types/ws": "^8.
|
|
28
|
-
"ava": "^
|
|
29
|
-
"husky": "^
|
|
30
|
-
"jest": "^
|
|
31
|
-
"jest-image-snapshot": "^
|
|
32
|
-
"lint-staged": "^
|
|
33
|
-
"playwright": "^1.
|
|
34
|
-
"prettier": "^2.
|
|
35
|
-
"ts-jest": "^
|
|
36
|
-
"ts-node": "^10.
|
|
37
|
-
"typescript": "^4.4
|
|
28
|
+
"@types/ws": "^8.5.3",
|
|
29
|
+
"ava": "^5.1.0",
|
|
30
|
+
"husky": "^8.0.2",
|
|
31
|
+
"jest": "^29.3.1",
|
|
32
|
+
"jest-image-snapshot": "^6.1.0",
|
|
33
|
+
"lint-staged": "^13.1.0",
|
|
34
|
+
"playwright": "^1.29.0",
|
|
35
|
+
"prettier": "^2.8.1",
|
|
36
|
+
"ts-jest": "^29.0.3",
|
|
37
|
+
"ts-node": "^10.9.1",
|
|
38
|
+
"typescript": "^4.9.4"
|
|
38
39
|
},
|
|
39
40
|
"prettier": {
|
|
40
41
|
"printWidth": 100,
|